CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Posts
    12

    window procedure

    Hi,

    Is it possible to have a window procedure,that will be a member function of a class.

    thanks,

    Shai


  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: window procedure

    A static member function, yes it can be done. A non-static member function, no.

    The prototype for a window procedure is not compatible with the prototype for a non-static class member function because of the hidden "this" argument for non-static member functions.

    Regards,

    Paul McKenzie


  3. #3
    Join Date
    May 1999
    Posts
    12

    Re: window procedure

    How does the message map macros map a message to
    a class memeber function in MFC (for instance ON_MESSAGE(...) )?

    Shai


  4. #4
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: window procedure

    ON_MESSAGE(UM_MYMESSAGE, OnMyMessage)

    maps to:

    LRESULT CSomeWindowClass::OnMyMessage(WPARAM wParam, LPARAM lParam)
    {
    }

    (the routine name OnMyMessage() can be whatever you want).

    This mirrors the standard API window procedure where you have the parameters passed with the message and you return a long value.

    Don't forget to stick afx_msg in front of the prototype in the header file.



    --
    Jason Teagle
    [email protected]

  5. #5
    Join Date
    Apr 1999
    Posts
    37

    Re: window procedure

    Hi,
    In MFC there is a super window proc which is called for all the windows created using MFC .This is not a member of any class.its called AfxWndProcBase(file afxstate.cpp).This function in turn calls AfxWndProc which gets the CWnd pointer from the window handle which comes with the message and calls the member function of CWnd called WindowProc which in turn calls CWnd::OnWndMsg which finally calls the handler for that particular message which will be a member function of ur CWnd derived class.
    The point is ur non-static member function is not a direct callback function.Its just been invoked by a real callback function(which is not a member of any class) which has the pointer to ur object.
    Just put a breakpoint in a message handler and study the function call stack when it breaks at that point.



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