views:

219

answers:

1

Hi! I am writing a GUI wrapper for windows api right now ( i can't use qt or mfc ). The library itself is extremely basic. After subclassing windows common controls ( and wrapping them into the classes ) i have faced a problem. As far as i know (and i hope i am wrong), only parent control can handle a message like WM_CTLCOLOREDIT and the same. But i want to be able to write something like this:

myedit->SetBkColor ( RGB ( 0, 0, 0 ) );

Is it possible to implement at all ( like in windows forms, for example ), or i should write a new controll from scratch, and write the painting by myself?

Thank you, #535.

+3  A: 

You can do it, but it is a fair amount of work. The basic idea is that you create another window to act as the parent to the control you're subclassing. In that, you keep track of whether a notification message (e.g. WM_CTLCOLOREDIT) is being handled by the parent or the sub-classed control itself. If it's being handled by the parent, it just passes the message through, but if it's supposed to be handled by the subclassed control itself, it reflects it back to the control.

Jerry Coffin
To be honest, sounds like some kind of a trick))) Considering, that win forms are just wrappers over win api, i was wondering, how did they implement that. Maybe their edit is just a completely different control... Nevertheless, thank you very mush!
n535
I suspect they use the usual Windows controls, but with a wrapper like this around them (at least for most controls -- there might be a few exceptions). If you really wanted to know how WinForms does it, a bit of time with Spy++ should make it clear.
Jerry Coffin