Don't have to change the font color OnCtlColor MFC
Time:10-10
Due to change the color of the Static is more, if you use OnCtlColor, will write a lot if judgment, plan to write a generic function to change the color, such as Void setcolor (ID, color) {} this way, when I click a button to call the function, so as to change the color of the specified ID, but use SetTextColor from OnCtlColor complains, there are other ways to solve?
CodePudding user response:
Try
HBRUSH CMyStatic: : CtlColor (CDC * pDC, UINT nCtlColor) { //TODO: Change any attributes of the DC here The static CBrush Brush (RGB (255255128));
//CRect rc; //GetClientRect (& amp; Rc); //pDC - & gt; FillSolidRect (rc, RGB (0255255));//blue //Set the background mode for the text to transparent //so the background will show thru. COLORREF color; PDC - & gt; SetBkMode (TRANSPARENT); //Set the text color to white UINT id=GetDlgCtrlID (); The switch (id) { Case IDC_STATIC1: color=RGB (0128128); break; Case IDC_STATIC2: color=RGB (129128, 0); break; Case IDC_STATIC3: color=RGB (128,0,128); break; } PDC - & gt; SetTextColor (color); Return the Brush; //TODO: the Return of a non - NULL brush if the parent 's handler should not be called //return NULL; }