3

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

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
ilija veselica
  • 9,414
  • 39
  • 93
  • 147
  • Add details: what is the user interface? MFC? Windows Forms? A web application? C++ has no notion of typefaces -- that's a UI thing. – Pontus Gagge Oct 26 '10 at 08:47
  • Is this text written into console or is it displayed somewhere? You will be unable to make text bold if it is written to console/stdout – Sergii Pozharov Oct 26 '10 at 08:48
  • It's windows application. The text is displayed in a dialog window – ilija veselica Oct 26 '10 at 08:49
  • Can you post a code sample of where this text is being set, maybe then we can help with setting the font to bold. – John Warlow Oct 26 '10 at 08:52
  • JLWarlow, I edited my question, there is small piece of code if it helps. If not, I could post more code – ilija veselica Oct 26 '10 at 08:54
  • @ile: You can always edit your question to add such information. – Björn Pollex Oct 26 '10 at 08:55
  • @ile - Could you also include the code from the cpp file where STRING1 is used, thanks. – John Warlow Oct 26 '10 at 08:59
  • @ZloiAdun : you can make text be bold in a console. but only a few consoles supports it. On most of them, the 'bold' attribute is replaced by 'Bright' so they change the color of the text to a brighter one. It's quite the same effect if you ask me. – BatchyX Oct 26 '10 at 09:21
  • Within a dialog the simplest is to have a static control inside that dialog that displays the text and set the font for that static to be a bold font. – CashCow Oct 26 '10 at 11:11

4 Answers4

11

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.

CashCow
  • 30,981
  • 5
  • 61
  • 92
3

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.

John Warlow
  • 2,922
  • 1
  • 34
  • 49
  • 1
    The thing is I need only part of string to be bold. For example: First Example (this is how it would look like in HTML). Thank you! – ilija veselica Oct 26 '10 at 09:21
  • 2
    Ah ok, not sure how or if you can do that with a static control. You could do something like that with a read-only rich text control, maybe. – John Warlow Oct 26 '10 at 09:24
  • 2
    +1, rich text is the correct solution then. A normal static label is intended for simple cases. – MSalters Oct 26 '10 at 11:08
0

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.

-1

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