views:

18

answers:

1

Hello,

I'm writing an application for a Pocket PC 2003 device. In it there is a dialog where various text information is shown. The information is separated so that each piece resides inside its own label, defined as LTEXT in the resource file.

Now my problem is that, at the moment, all text lables have the same font and style (normal or simple, i.e. not bold or italic); I want want one to be set in bold. I know that I can set the font to bold in the resource file, but that sets the style of all labels.

How does one achieve this? I've seen it be used in the Windows 'About' screen so I know it's possible. I've written the program in C++ using the Win32 API directly (except for certain dialogs where I've used the resource file) so I would appreciate if the answer was given in the same language and approach.

Thanks.

+1  A: 

In the resource editor, edit the static text item, and change its control ID to something unique: IDC_BOLD for example.

In the DialogProc for the dialog boxes that is hosting the control, add a WM_CTLCOLORSTATIC handler:

case WM_CTLCOLORSTATIC:
  HDC hdc;
  HWND hwndCtl;
  hwndCtl = (HWND) lParam;
  hdc = (HDC) wParam;

  if( GetWindowLong(hwndClt, GWL_ID ) == IDC_BOLD )
  {
    SetBkMode(hdc,TRANSPARENT);
    SetTextColor(hdc,RGB(0xff,0,0)); // turn the text red for fun :)
    SelectObject(hdc,hBoldFont);     // but you want this...
    return (INT_PTR)GetSysColorBrush(COLOR_BTNFACE); 
    //return 0L; // if visual themes are enabled (common controls 6) then 0 is better.
  }
  // default processing
  return 0;

You are developing for Pocket PC 2003, I don't know what buttons styles are available. This Page refers of course to desktop XP. But, if the buttons in the dialogs are not flat grey 95esq buttons, then it might be more appropriate to return 0 as that will paint the text background correctly if the dialogs background is not plain grey.

Pre-visual styles a return of 0 causes the system to reset the DC so its important to know which return is appropriate.

Chris Becke
Ah yes, of course. Didn't think about the catching-a-message approach. But this is my first Windows app so I guess I can be excused. ^^ I'm guessing you're talking about buttons in order to determine the correct return value, yes? Could you also please include the code for creating a font handle to the system font which has been modified or set as bold? I'm not familiar with the font API...
gablin
I managed to figure out how to make a bold system font through this tutorial: http://windows-programming.suite101.com/article.cfm/win32_easy_font_handling_tutorial Thank you for your help, Chris Becke!
gablin