Thread: subclassing a wndproc from within a class

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Bummer. Wrote two pages, wrong password. Gone.
    You can retrieve your this directly from your static wndproc via GetWindowLong because the control has not been subclassed until after wnd creation.
    Consider, within your static wndproc:
    Code:
    //beware: pseudocode!!!
    MyClass *pWnd=(MyClass*)GetWindowLong(...);
    if (!pWnd)
       {
       /*must be a diy registered and created wnd class
       so get and set this from WM_NCCREATE*/
       }
    //this is good so do stuff
    pWnd->MyMsgHandler(...);
    When you register a diy wnd class and create windows of that class, ALL the msgs go to your wndproc because that's the way it's set up. When you create a control, the initial creation messages go to the system defined wndproc; your diy wndproc does not kick in until you subclass the control after you have created the control using CreateWindowEx.

    When you superclass a control what you are doing is copying the details - including the default wndproc - for a control and then registering those details with a different class name,instance and diy wndproc; in effect you are creating a 'normal' window but based on the original control. Now, just like your normal window, ALL messages go to YOUR wndproc, because that's how that particular class of window was registered with the system. When you want default 'control' behaviour for it just ensure you use CallWindowProc using the original, system wndproc returned in the WNDCLASSEX when you initially called GetClassInfoEx.

    edit: just about everything.
    Last edited by Ken Fitlike; 01-04-2003 at 07:00 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM