C++ Windows Programming Question

Started by
4 comments, last by Shadowflare 21 years, 8 months ago
I have created a Button on my window, using CreateWindowEx(), and I need to change the WndProc that the Button uses. Is there any way to reset the WndProc? Or to remotely access and change the setting in the "Button" class? Any help is greatly appreciated.
Advertisement
Shadowflare,

Check out SetWindowLong() with the nIndex parameter as GWL_WNDPROC.

Hope this helps...
Thanks, this seems to be what I''m looking for, but how do I declare the pointer to my new WndProc to pass as dwNewLong?
Do you mean you want to change the window''s (=button) wndproc, after you''ve created it? Beats me why you want to do that, but anyhoo. What do you mean by how to declare the pointer? If you mean how you should cast it when calling SetWindowLong(), give it what it wants, probably (void *) or (ULONG). Perhaps you could explain better what you''re up to, and provide some code.
...Just found something I did once:

oldhandler = (WNDPROC)SetWindowLong( GetDlgItem( hwnd, IDC_PREVIEW ), GWL_WNDPROC, (LONG)thumbnail_2 );

oldhandler was a WNDPROC variable to store the address of the old handler subroutine, and the new handler was thumbnail_2().

In case you''re wondering, I was working with a control in a dialog box to generate a thumbnail preview for a graphics editor (hence the GetDlgItem() call)...

To answer your question more directly, all you''ve gotta do is typecast the function name to LONG.

Hope this helps...
quote:Original post by CWizard
Beats me why you want to do that...

It''s called control subclassing and is standard practice to customize control behavior. VGASteve provides the solution.

This topic is closed to new replies.

Advertisement