Background color of CButton
How can I change the background color of a CButton?
I have set the ownerdraw property to true.
Then I tried with SetBkColor in DrawItem function, but how can I get the hwnd argument?
thx
[213 byte] By [
laitinen] at [2007-11-20 1:28:27]

# 1 Re: Background color of CButton
here is Something through which you can get the handle of your button..
CButton *pButton;
pButton= (CButton *) GetDlgItem(IDC_BUTTON);
and for changing Button color n no of examples are present on Code guru just Search for them
Thanx
# 2 Re: Background color of CButton
Then I tried with SetBkColor in DrawItem function, but how can I get the hwnd argument?What hwnd do you mean and why do you need it by using SetBkColor ?
BTW, there is m_hWnd member variable to store the window handle in any CWnd derived class. :rolleyes:
# 3 Re: Background color of CButton
sorry I didnt mean hwnd, I meant HDC.
The setBkColor is defined like this;
COLORREF SetBkColor(HDC hdc, COLORREF color)
I try to invoke this method in DrawItem method in my CButton. Is this right?
thx.
# 4 Re: Background color of CButton
Check this article, http://www.dev-archive.com/cpp/controls/buttonctrl/advancedbuttons/article.php/c8395/.
cilu at 2007-11-10 23:21:21 >

# 5 Re: Background color of CButton
In addition to cilu's link...
You should also look at MSDN to see the example of CButton::DrawItem method: CButton::DrawItem (http://msdn2.microsoft.com/en-us/library/y0k9f0a4.aspx)
and DRAWITEMSTRUCT description: DRAWITEMSTRUCT Structure (http://msdn2.microsoft.com/en-us/library/92fhtw0f.aspx)