troubleshooting Question

CStatic color and OnCtrlColor question

Avatar of StixGP
StixGP asked on
System ProgrammingMicrosoft DevelopmentEditors IDEs
3 Comments1 Solution1618 ViewsLast Modified:

I am attempting to change the text and background colors of a CStatic and simmilar MFC controls.  After looking into this problem, I've come accross  afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);

but when I try to add this function to the message map is Visual Studio 2005, I get errors complaining about the wrong function definition.  The only way I seem to be able to compile is by using

LRESULT OnCtlColor(WPARAM wParam, LPARAM lParam); instead of the above.

However, when I debug this code, the wParam provided is 0 and the lparam contains a large value.  I can't find any documentation on this function, or what the parameters mean, and I'd like to know why I can't use the HBRUSH function definition in my program since its clearly documented all over the place.

My most recent attempt at this look like

LRESULT CGeoFlowDlg::OnCtlColor(WPARAM wParam, LPARAM lParam)

MyCDC = GetDC();
MyHDC = MyCDC->GetSafeHdc();

SetTextColor(MyHDC, RGB(0, 128, 0));
SetBkColor(MyHDC, RGB(0, 0, 255));

return (LRESULT)m_hDialogBrush; //brush was created at start of application and is set to dark grey

I put the above  together from various examples in hopes of getting something to work, but no joy.  

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros