CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Subclassing?

  1. #1
    Join Date
    Apr 1999
    Location
    southern cali
    Posts
    7

    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


  2. #2
    Guest

    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




  3. #3
    Join Date
    Apr 1999
    Location
    southern cali
    Posts
    7

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured