-
Subclassing?
I am looking for information on subclasing a window in an application not written by me. I can get the HWND of the window, but any attempts to manipulate the window in any way fail. I can SetWindowText and send messages such as WM_CLOSE easily, they work fine. But when I try to use SetWindowLong with GWL_WNDPROC to replace the window proc with my own, it fails.
I have tried creating a CWnd and calling SubclassWindow, it returns true, and yet no calls are made top PreTranslateMessage or DefWindowProc. Any help? Thanks.
JL
-
Re: Subclassing?
If SetWindowLong() fails, you can call GetLastError() to get the error. If
something else is failing, it could be a number of things. Subclassing should
*always* works, unless you did something wrong. How about posting the part of
the code that fails.
Personally, I've always subclassed a window using good old Windows API and have
never used CWnd::SubclassWindow(). I wanted to know exactly where my old
handler was and knew when/where to call it, and when to restore the old
handler. The CWnd::SubclassWindow() was too convoluted (my opinion).
Regards,
Paul
-
Re: Subclassing?
I prefer to use the Win32 route rather than the MFC route also. At first I tried using SetWindowLong with the HWND of the window and passed my WNDPROC. Only it returns a NULL HWND as the previous one, and GetLastError() just returns 0 (no error), when I pass an HWND returned by GetSafeHwnd(), for my app. It works fine.
Thanks,
JL