Home > Software engineering >  Under win32 with window, how to implement multiple static text box set different background and font
Under win32 with window, how to implement multiple static text box set different background and font

Time:11-14

As title, set up three static text box in a win32 window
At the time of the response message has been added to the following code, the result is the color of the three static text box has changed
 
Case WM_CTLCOLORSTATIC:
//create a brush
HBrush1=CreateSolidBrush (RGB (245, 246, 250));
WParam hdcStatic=(HDC);//static text box text and background Settings
SetTextColor (hdcStatic, RGB (83, 92, 104));
SetBkMode (hdcStatic, TRANSPARENT);//SetBkMode (hdcStatic, RGB (206, 214, 224)); SetBkColor (hdcStatic, RGB (255, 107, 129));//green
Return (INT_PTR) hBrush1;


How to separate set each static text box background and text color?

CodePudding user response:


HBRUSH CTestDlg: : OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor)
{
//TODO: any features in this change DC
Enum {br4Edit1 br4Static1};
The static CBrush br [br4Static1 + 1];
If ((HBRUSH) br [br4Edit1]==nullptr)
{
VERIFY (br) [r]. Br4Edit1 CreateSolidBrush (RGB (0126255)));
VERIFY (br) [r]. Br4Static1 CreateSolidBrush (RGB (122, 23, 255)));
}

//TODO: if the default brush is not required, it returns another brush
The switch (pWnd - & gt; GetDlgCtrlID ())
{
Case IDC_EDIT1:
{
Return br [br4Edit1];
}
Case IDC_STATIC1:
Return br [br4Static1];

Default:
HBRUSH gets=CDialogEx: : OnCtlColor (pDC, pWnd, nCtlColor);
Return gets;
}
}
  • Related