Home > Software engineering >  VS2010 Combo - the color of the text box control under the Unicode cannot change
VS2010 Combo - the color of the text box control under the Unicode cannot change

Time:10-11



Just to change from the original project multibyte to Unicode, found above controls, is VS2010 Combo box control, such as I want to change the control to the green, before I am OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor) function,
PDC - & gt; SetBkColor (bkColor);
PDC - & gt; SetTextColor (textColor);
It should be possible, but after to Unicode, haven't success, try many ways to change only the color of the part, when selecting the drop-down box will be displayed after the selected color does not change, can someone encountered similar problems, how do I operation can change the color?

CodePudding user response:

This OnPaint create a brush
 HPEN HPEN, hOldPen;//brush 
HPen=CreatePen (PS_SOLID, 2, RGB (0, 255));//generated red color brush brush width 5 pixels
HOldPen=(HPEN) SelectObject (HDC, HPEN);//into the brush device field condition

SelectObject (HDC, hOldPen);
DeleteObject (hPen);



: OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor)
If (pWnd - & gt; GetDlgCtrlID ()==IDC_ controls)//change the color button
{
PDC - & gt; SetBkMode (TRANSPARENT);
PDC - & gt; SetBkColor (RGB (0, 0, 0));
PDC - & gt; SetTextColor (RGB (255, 255, 255));
Return m_brush;//create a brush
}

CodePudding user response:

reference 1st floor SWWLLX response:
create a brush inside the OnPaint
HPEN HPEN, hOldPen;//brush
HPen=CreatePen (PS_SOLID, 2, RGB (0, 255));//generated red color brush brush width 5 pixels
HOldPen=(HPEN) SelectObject (HDC, HPEN);//into the brush device field condition

SelectObject (HDC, hOldPen);
DeleteObject (hPen);



: OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor)
If (pWnd - & gt; GetDlgCtrlID ()==IDC_ controls)//change the color button
{
PDC - & gt; SetBkMode (TRANSPARENT);
PDC - & gt; SetBkColor (RGB (0, 0, 0));
PDC - & gt; SetTextColor (RGB (255, 255, 255));
Return m_brush;//create a brush
}

"OnPaint inside to create a brush" refers to the combobox control redraw a child, then the control below add OnPaint function add your code?

CodePudding user response:

refer to the second floor lgq60122 response:
Quote: refer to 1st floor SWWLLX response:

This OnPaint create a brush
HPEN HPEN, hOldPen;//brush
HPen=CreatePen (PS_SOLID, 2, RGB (0, 255));//generated red color brush brush width 5 pixels
HOldPen=(HPEN) SelectObject (HDC, HPEN);//into the brush device field condition

SelectObject (HDC, hOldPen);
DeleteObject (hPen);



: OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor)
If (pWnd - & gt; GetDlgCtrlID ()==IDC_ controls)//change the color button
{
PDC - & gt; SetBkMode (TRANSPARENT);
PDC - & gt; SetBkColor (RGB (0, 0, 0));
PDC - & gt; SetTextColor (RGB (255, 255, 255));
Return m_brush;//create a brush
}

"OnPaint inside to create a brush" refers to the combobox control redraw a child, then the control below add OnPaint function add your code?
without success

CodePudding user response:

Estimation is enabled the MANIFEST so lead to system resources over the standard control style, custom painting

CodePudding user response:

Subclass, and then their redraw

 HBRUSH CMyComboBox: : OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor) 
{
If (nCtlColor==CTLCOLOR_LISTBOX)
PDC - & gt; SetBkColor (RGB (255, 0, 0));

Return CComboBox: : OnCtlColor (pDC, pWnd, nCtlColor);
}

CodePudding user response:

Create a brush of resources this thing, don't repeatedly create and release in the onpaint, should be put in
Create the Oncreate function,
  • Related