c++ - 用户定义的消息

标签 c++ mfc sendmessage

代码如下:

//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

最佳答案

例如,也许您不是从 MyClass 而是从 MyMainFrame 的方法调用 SendMessage(),因此您将消息发送到错误的窗口。 如果是这样,只需添加成员变量:

m_myView.SendMessage(WM_USER+100,0,0);

此外,您确实忘记了 MyClass:: 来自:

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

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

相关文章:

c++ - 寻求 DDX 的替代品

c++ - 用于解析资源 (.rc) 文件的正则表达式

multiplayer - 如何使用 firebase 向特殊在线用户发送警报消息

c++ - 从 HGDIOBJ 到 HBRUSH 的转换

java - 在 C++/JNI 中将 vector 转换为作业?

c++ - 无法将参数 1 从 'ATL::CStringT<wchar_t,ATL::StrTraitATL<wchar_t,ATL::ChTraitsCRT<wchar_t>>>' 转换为 'const char *'

C++ WINAPI : Client area parent dragging with obscuring child tab windows

c++ - win32api SendMessage 不能在 WM_CREATE 之外工作

c++ - 遍历 txt 文件中的对象数组

c++ - 使用特殊字符对字符串数组进行排序