简体   繁体   中英

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM