문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top