这是代码:

//h file
class MyClass: public CView
{
public:
    afx_msg LRESULT OnMyMess(WPARAM, LPARAM);
}

//cpp file
BEGIN_MESSAGE_MAP(MyClass, CView)
    ON_MESSAGE(WM_USER+100, OnMyMess)
END_MESSAGE_MAP()

LRESULT OnMyMess(WPARAM, LPARAM)
{return 0};


//Somewhere in the programm
SendMessage(WM_USER+100, 0 ,0);

程序为什么不调用处理程序?

更新:WinXP,MS VS 2003

最佳答案

第一,

LRESULT OnMyMess(WPARAM, LPARAM)
{return 0;}

应该
LRESULT MyClass::OnMyMess(WPARAM, LPARAM)
{return 0;}

但我想这只是一个错字。

其次,SendMessage仅在您正在调用的MyClass中才应按预期工作;否则,您应指定要将消息发送到的窗口。

关于c++ - 用户定义的消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6859317/

10-10 17:37