如何在 C++ 中打印粗体字符串?

发布于 2024-09-28 21:47:49 字数 1249 浏览 2 评论 0原文

我有一个用 C++ 编写的旧应用程序。我对此没有任何经验,但我应该在应用程序中进行一些更改。其中之一是更改一些文本。问题是更新文本的一部分需要加粗,但我不知道该怎么做。我用谷歌搜索但没有取得太大成功。我现在只是想用 \n 转到新行,并用 \t 转到新选项卡。

有什么聪明的建议吗?

编辑:
代码示例:

BEGIN
    STRING1                              "First Example"
    STRING2                              "Second Example"

使用 STRING1 的地方:

// WelcomeTip ---------------------------------------------//
    LPSTR idsWelcomeTip = (LPSTR)GlobalAlloc(GPTR, sizeof(CHAR) * 4098 );
    LoadString( waveInDlg->hInstance, STRING1, idsWelcomeTip, 4098 );
    waveInDlg->hwndWelcomeTip = CreateWindow(
        "STATIC",
        idsWelcomeTip,
        WS_CHILD | WS_VISIBLE | SS_LEFT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        waveInDlg->hwnd,
        NULL,
        waveInDlg->hInstance,
        NULL
    );
    SetWindowLongPtr(waveInDlg->hwndWelcomeTip, GWLP_USERDATA ,(LONG)waveInDlg );
    SendMessage(waveInDlg->hwndWelcomeTip, WM_SETFONT , (WPARAM)waveInDlg->hFontDefault , TRUE );
    ShowWindow(waveInDlg->hwndWelcomeTip, SW_HIDE);
    GlobalFree( (HGLOBAL)idsWelcomeTip );

谢谢,

I got an old application which was written in a C++. I have 0 experience with it but I am suppose to make some changes in app. One of them is to change some text. Problem is that part of updated text needs to be bold, but i have no idea how to do that. I googled but with no much success. Only think I now is to go to new line with \nand new tab with \t.

Any clever advise?

EDIT:
Example of code:

BEGIN
    STRING1                              "First Example"
    STRING2                              "Second Example"

And place where STRING1 is used:

// WelcomeTip ---------------------------------------------//
    LPSTR idsWelcomeTip = (LPSTR)GlobalAlloc(GPTR, sizeof(CHAR) * 4098 );
    LoadString( waveInDlg->hInstance, STRING1, idsWelcomeTip, 4098 );
    waveInDlg->hwndWelcomeTip = CreateWindow(
        "STATIC",
        idsWelcomeTip,
        WS_CHILD | WS_VISIBLE | SS_LEFT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        waveInDlg->hwnd,
        NULL,
        waveInDlg->hInstance,
        NULL
    );
    SetWindowLongPtr(waveInDlg->hwndWelcomeTip, GWLP_USERDATA ,(LONG)waveInDlg );
    SendMessage(waveInDlg->hwndWelcomeTip, WM_SETFONT , (WPARAM)waveInDlg->hFontDefault , TRUE );
    ShowWindow(waveInDlg->hwndWelcomeTip, SW_HIDE);
    GlobalFree( (HGLOBAL)idsWelcomeTip );

Thanks,

Ile

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

妄司 2024-10-05 21:47:49

C++ 中没有粗体文​​本的概念,可能在显示字符文本的特定设备中存在,例如富文本格式或 HTML 标记或终端屏幕。后者通常涉及发送一些与该特定终端相关的“转义序列”。

There is no concept of bold text in C++, there may be in a particular device that displays character text, for example rich-text-format or HTML tagging or a terminal screen. The latter usually involves sending some "escape sequence" relevant to that particular terminal.

与酒说心事 2024-10-05 21:47:49

好的,我已经敲出了一些代码,应该可以概述您所追求的内容,我还没有成功编译它,因为我需要编写更多内容来测试,但它应该指出您的正确方向方向:

// Create the font you need
LOGFONT lf;
zeromemory(&lf, sizeof(LOGFONT))
lf.lfHeight = 20; // 20 pixel high font
lf.lfWeight = FW_BOLD;
strcpy(lf.lfFaceName, "Arial");
HFONT hFont = ::CreateFondIndirect(&lf);

// Set the control to use this font
SendMessage(waveInDlg->hwndWelcomeTip, WM_SETFONT, (WPARAM)hFont, NULL);

我希望这会有所帮助。

OK, I've knocked up some code that should give an overview of what you're after, I've not managed to compile it as I'd need to write a lot more to test, but it should point you in the right direction:

// Create the font you need
LOGFONT lf;
zeromemory(&lf, sizeof(LOGFONT))
lf.lfHeight = 20; // 20 pixel high font
lf.lfWeight = FW_BOLD;
strcpy(lf.lfFaceName, "Arial");
HFONT hFont = ::CreateFondIndirect(&lf);

// Set the control to use this font
SendMessage(waveInDlg->hwndWelcomeTip, WM_SETFONT, (WPARAM)hFont, NULL);

I hope this helps.

贪了杯 2024-10-05 21:47:49

请通过以下链接寻求帮助
http://msdn.microsoft.com/en-us/ library/dd162499(VS.85).aspx

是的,您必须在对话框类中重写 WM_PAINT 并调用 drawtext 函数。

Please go through the below link for help
http://msdn.microsoft.com/en-us/library/dd162499(VS.85).aspx

Yes, you have to override WM_PAINT in your dialog class and call drawtext function.

风轻花落早 2024-10-05 21:47:49

在 WM_PAINT 消息处理程序中使用 DrwaText API。dc.DrawText (_T ("Hello, MFC"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);

使用 DrawTextEx 方法。
有关更多信息,请访问以下链接

ms-help://MS.MSDNQTR.v90.en/gdi/fontext_4pbs.htm

Use DrwaText API in WM_PAINT message handler.dc.DrawText (_T ("Hello, MFC"), -1, &rect,
DT_SINGLELINE ¦ DT_CENTER ¦ DT_VCENTER);

use DrawTextEx method.
For more inforamtion go through the follwoing link

ms-help://MS.MSDNQTR.v90.en/gdi/fontext_4pbs.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文