none
ON_MESSAGE(MY_MESSAGE,CTESTDlg::WindowProc) error!!!!! RRS feed

  • 问题

  • 我用MFC做一个播放器时,基于对话框,添加了一个自定义的消息,结果报错,我用的是vs2010

    这是在对话框类里面的消息传来函数
    virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);

    这是定义
    LRESULT CTESTDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
    // TODO: Add your specialized code here and/or call the base class
    switch (message)
    {
    case MY_MESSAGE:
    if (lParam==WM_RBUTTONUP||lParam==WM_LBUTTONUP)
    {
    ShowWindow(SW_SHOW);
    Tdehide();
    }
    break;
    }

    return CDialogEx::WindowProc(message, wParam, lParam);
    }


    这是自定义消息

    #define MY_MESSAGE (WM_USER + 1)

    BEGIN_MESSAGE_MAP(CTESTDlg, CDialogEx)

    ON_MESSAGE(MY_MESSAGE,CTESTDlg::WindowProc)//消息/////////////////////////此处报错

    END_MESSAGE_MAP()

    错误原因:
    Error 1 error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CTESTDlg::* )(UINT,WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' d:\users\lenovo\documents\visual studio 2010\projects\c++课程设计\test\testdlg.cpp 88


    已尝试几种方法,因为不理解机制,搞不清楚,也搜了好久,也没找到答案
    帮帮忙
    2011年1月8日 12:40

答案

  • 错误信息写得很清楚了,你的函数多了一个UINT参数,和消息宏期待的函数类型不匹配。

    你不是用消息映射分发消息么?怎么还想自己重载wndproc?



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2011年1月9日 4:59
    版主
  • afx_msg LRESULT OnMessage(WPARAM wParam, LPARAM lParam);
    BEGIN_MESSAGE_MAP(...,...)
    ON_MESSAGE(MY_MESSAGE, &CTESTDlg::OnMessage)
    END_MESSAGE_MAP()
    LRESULT CTESTDlg::OnMessage(WPARAM wParam, LPARAM lParam)
    { 
     // ...
     return 0;
    }
    

    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE platform embedded development.
    2011年1月10日 4:01
    版主

全部回复

  • 错误信息写得很清楚了,你的函数多了一个UINT参数,和消息宏期待的函数类型不匹配。

    你不是用消息映射分发消息么?怎么还想自己重载wndproc?



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2011年1月9日 4:59
    版主
  • afx_msg LRESULT OnMessage(WPARAM wParam, LPARAM lParam);
    BEGIN_MESSAGE_MAP(...,...)
    ON_MESSAGE(MY_MESSAGE, &CTESTDlg::OnMessage)
    END_MESSAGE_MAP()
    LRESULT CTESTDlg::OnMessage(WPARAM wParam, LPARAM lParam)
    { 
     // ...
     return 0;
    }
    

    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE platform embedded development.
    2011年1月10日 4:01
    版主