Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Owner-drawn buttons and WM_DRAWITEM messages

426 views
Skip to first unread message

John Smith

unread,
Apr 13, 2009, 6:25:43 AM4/13/09
to
I've created an owner-drawn button and subclassed it to have its own WndProc:
but_wndproc.

The but_wndproc should handle all the messages and repainting. Unfortunately some
messages such as WM_DRAWITEM and WM_COMMAND go to *parent* window WndProc and not
but the subclassed but_wndproc. I don't want that. The messages should go
straight to but_wndproc.

Now I am just doing a PostMessage from WndProc to but_wndproc for WM_DRAWITEM and
WM_COMMAND. But my main WndProc is getting messy when I have all sorts of owner
drawn controls and I have to determine what shoult get posted and to which
subclassed WndProc.

I there any way to make for example WM_DRAWITEM go directly to the the subclassed
WndProc?

Timo Kunze

unread,
Apr 13, 2009, 8:09:38 AM4/13/09
to
John Smith schrieb:

> I there any way to make for example WM_DRAWITEM go directly to the the subclassed
> WndProc?
Some kind of. It is called message reflection and more or less exactly
what you're already doing. The default message handler provided by
Windows does message reflection, so it should be enough to remove your
own reflection stuff from your parent window and in but_wndproc watch
for OCM_COMMAND and OCM_DRAWITEM instead of WM_COMMAND and WM_DRAWITEM.

Timo
--
www.TimoSoft-Software.de - Unicode controls for VB6
"Those who sacrifice freedom for safety deserve neither."
"Demokratie ist per Definition unsicher. Ihr Schutz entsteht aus der
Überzeugung, dass die demokratischen Kräfte überwiegen und sich – auf
demokratischem Wege – durchsetzen."

Norman Bullen

unread,
Apr 13, 2009, 9:37:34 AM4/13/09
to

The whole intent of BS_OWNERDRAW (and the other owner-draw styles) is so
that you _don't_ have to subclass the control's window procedure. They
save the effort of writing a subclassing procedure because they allow
you to do the drawing in the parent window procedure or dialog procedure
with you have write in any case.

If, for any reason, you prefer to use subclassing, don't use the owner
draw styles. Just handle the WM_PAINT (and possibly WM_NCPAINT) messages
in the subclassing procedure and do the painting there.

--
Norm

To reply, change domain to an adult feline.

0 new messages