How to print bold string in C++?

為{幸葍}努か 提交于 2020-01-14 14:32:06

问题


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


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/4022001/how-to-print-bold-string-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!