JBode
JBode

Reputation: 23

MFC Custom Control Background/Text Color

So I have used MFC for a few years and made various interfaces which include custom controls. I was recently asked to start making an interface which can have dynamically set background and text colors. I started working on this and have been running into an issue getting some of my custom controls to behave. All the controls which generate WM_CTLCOLOR messages work really nicely using that interface to allow the parent to set the colors of the child controls, but not all the controls I have customized generate these messages. Specifically a class I built off of CTabCrtl and a few based on CWnd. These classes don't seem to generate WM_CTLCOLOR messages before they call a paint. I was wondering if anyone had any ideas on how to either get the background and text color of a controls parent CWnd or how to manually create a WM_CTLCOLOR message. I have tried to get the current DC of the controls parent so I can call GetBkColor() and GetTextColor() but doing this always seems to return default values. I have also tried to create WM_CTLCOLOR messages but don't know where I should create them or the exact syntax.. Any help would be great.

Upvotes: 1

Views: 2219

Answers (1)

xMRi
xMRi

Reputation: 15355

The idea of WM_CTLCOLOR is that is has to be called from within the WM_PAINT and WM_ERASEBKGND. In such cases you have a DC. You send the message to the parent and you get a brush and the text and background Color gets set.

I see only a major problem that WM_CTLCOLOR isn't a real window message... it is just syntesized from the various WM_CTLCOLOR... messages described in the SDK.

So the syntax is documented in the MSDN. Cast the DC handle to WPARAM and hast the window handle to LPARAM...

Upvotes: 1

Related Questions