Class wizard

Hello all,

How do I go about adding a message handler i.e ON_MESSAGE(...etc) without the class wizard as in VC++6 Thanks in advance.



Answer this question

Class wizard

  • SanthaMind

    I still get the following errors in my Begin Message Map for the parent Dialog.

    : error C2440: 'static_cast' : cannot convert from 'void (__thiscall CPDUTSDlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'

    None of the functions with this name in scope match the target type

    ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

    Please let me know if more information is needed.


  • Izhido_

    Thanks,

    I don't think I would have ever got this one.


  • sl0140

    You'd have to type the macro and the corresponding function declaration/definition into the cpp/h files in manually. You could look at existing class wizard generated code or MSDN documentation to figure out the function prototypes for each type of ON_ macro.

  • El Pato

    That's due to a breaking change in VC++ 2005. See my blog entry on this, which also gives a workaround/

    http://blog.voidnish.com/ p=91



  • Troy Lundin

    Beside that Nishant already said.

    ON_MESSAGE macro is generally used to map user-defined message handlers.
    The handler function prototype is
    afx_msg LRESULT memberFxn(WPARAM, LPARAM);

    Here is an example:

    #define WM_APP_MYMESSAGE (WM_APP+1)
    // ...
    // MainFrm.h
    class CMainFrame : public CFrameWnd
    {
    // ...
      afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);
      DECLARE_MESSAGE_MAP()
    };
    
    // MainFrm.cpp
    // ...
      //}}AFX_MSG_MAP
      ON_MESSAGE(WM_APP_MYMESSAGE, OnMyMessage)
    END_MESSAGE_MAP()
    // ...
    LRESULT CMainFrame::OnMyMessage(WPARAM wParam, LPARAM lParam)
    {
      // ...
      return (LRESULT)0;
    }


  • Class wizard