VC + + Settings control displays the foreground color, background color, and font of text

Source: Internet
Author: User

Before each control starts drawing, a WM_CTLCOLOR advertisement message is sent to its parent window, in which you can set the foreground color, background color, and font for the control's display text. The message handler also requires that the handle of a brush be returned to erase its client area before the control's specific drawing.

Hbrush Ctestdlg::onctlcolor (cdc* PDC, cwnd* pWnd, UINT nCtlColor)

{

Hbrush HBR = Cdialog::onctlcolor (PDC, PWnd, nCtlColor);

  Todo:return a different brush if the default is not desired

  return HBR;

}

1. PDC: The context object of the control.

2, PWnd: Control object pointer, you can specify the properties of a specific control.

3, Nctlcolor:color Types.

Color Types:

#define Ctlcolor_msgbox 0
#define CTLCOLOR_EDIT 1
#define Ctlcolor_listbox 2
#define CTLCOLOR_BTN 3
#define CTLCOLOR_DLG 4
#define Ctlcolor_scrollbar 5
#define Ctlcolor_static 6
#define CTLCOLOR_MAX 7

#define COLOR_SCROLLBAR 0
#define COLOR_BACKGROUND 1
#define Color_activecaption 2
#define Color_inactivecaption 3
#define COLOR_MENU 4
#define Color_window 5
#define COLOR_WINDOWFRAME 6
#define COLOR_MENUTEXT 7
#define COLOR_WINDOWTEXT 8
#define COLOR_CAPTIONTEXT 9
#define Color_activeborder 10
#define Color_inactiveborder 11
#define COLOR_APPWORKSPACE 12
#define Color_highlight 13
#define COLOR_HIGHLIGHTTEXT 14
#define COLOR_BTNFACE 15
#define Color_btnshadow 16
#define COLOR_GRAYTEXT 17
#define COLOR_BTNTEXT 18
#define COLOR_INACTIVECAPTIONTEXT 19
#define Color_btnhighlight 20

#define Color_3ddkshadow 21
#define Color_3dlight 22
#define COLOR_INFOTEXT 23
#define COLOR_INFOBK 24

#define Color_hotlight 26
#define Color_gradientactivecaption 27
#define Color_gradientinactivecaption 28

#define Color_menuhilight 29
#define Color_menubar 30

#define COLOR_DESKTOP Color_background
#define Color_3dface Color_btnface
#define Color_3dshadow Color_btnshadow
#define Color_3dhighlight Color_btnhighlight
#define Color_3dhilight Color_btnhighlight
#define Color_btnhilight Color_btnhighlight

Depending on the color types, you can specify properties for different types of controls, and the common properties are set

Pdc->settextcolor (RGB (255, 0, 0)); //Set text foreground color

Pdc->setbkcolor (RGB (255, 255, 255)); //Set text background color

Pdc->setbkmode (TRANSPARENT); //transparent or opaque

Finally, to return to the custom Hbrush

Example:

Hbrush Cshowvideodlg::onctlcolor (cdc* PDC, cwnd* pWnd, UINT nCtlColor)
{
Hbrush HBR = Cdialog::onctlcolor (PDC, PWnd, nCtlColor);

Todo:change any attributes of the DC
Hbrush b;
if (nCtlColor = = ctlcolor_static)
{
Switch (Pwnd->getdlgctrlid ())
{
Case Idc_node_name:
{
Pdc->settextcolor (0X228B22);
Pdc->setbkcolor (RGB (0x8d, 0xb6, 0XCD));

b = CreateSolidBrush (RGB (0x8d, 0xb6, 0XCD));
}
Break
Case Idc_static_display:
{
Pdc->setbkcolor (RGB (0, 0, 0));

b = CreateSolidBrush (RGB (0, 0, 0));
}
Break
}
}
else if (nCtlColor = = Color_menu)
{
if (pwnd->getdlgctrlid () = = Idr_play_menu)
{
Pdc->settextcolor (0X228B22);
Pdc->setbkcolor (RGB (0x8d, 0xb6, 0XCD));

b = CreateSolidBrush (RGB (0x8d, 0xb6, 0XCD));
}
}

return b;
Todo:return a different brush if the default is not desired
return HBR;
}

VC + + Settings control displays the foreground color, background color, and font of text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.