How do I set the font and color for a group box caption using Win32

前端 未结 3 587
醉话见心
醉话见心 2021-01-21 22:17

I am stuck with WIN32 ( no .NET or anything managed )

3条回答
  •  臣服心动
    2021-01-21 22:31

    Well you set the font using the normal way of setting control fonts. Send a WM_SETFONT message in your window initialisation using a HFONT you created with CreateFont. e.g.

    SendDlgItemMessage(hDlg, IDC_STATIC, WM_SETFONT, (WPARAM)hFont, TRUE);

    Then as pointed out you need to use the WM_CTLCOLORSTATIC notification to set the actual color.

    case WM_CTLCOLORSTATIC:
    if(GetDlgItem(hDlg, IDC_STATIC) == (HWND)lParam)
    {
        HDC hDC = (HDC)wParam;
    SetBkColor(hDC, GetSysColor(COLOR_BTNFACE)); SetTextColor(hDC, RGB(0, 0xFF, 0)); SetBkMode(hDC, TRANSPARENT);
    return (INT_PTR)CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
    } break;

    Although you really should only create the solid brush once and delete it when the dialog goes away because you will end up with a leak.

提交回复
热议问题