在文档视图程序里面,如何向Doc发送消息
在单文档视图程序中,在Doc类中添加了消息:
.h:
#define WM_CONTRALLINEWORK WM_USER+1
public:
//WM_CONTRALLINEWORK消息处里函数原型
LRESULT OnContralLineWork(WPARAM wParam,LPARAM lParam);
.cpp中:
//消息响应函数
BEGIN_MESSAGE_MAP(CHowTestDoc, CDocument)
//{{AFX_MSG_MAP(CHowTestDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
ON_MESSAGE(WM_CONTRALLINEWORK,OnContralLineWork)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
LRESULT CHowTestDoc::OnContralLineWork(WPARAM wParam,LPARAM lParam)
{
CString show;
show.Format("收到消息,参数为:%d,%d",wParam,lParam);
AfxMessageBox(show);
return 0;
}
这样,在View里面或别的地方怎么向它发送这个消息呢?试了几个函数都不行,多谢各位指点!!
在单文档视图程序中,在Doc类中添加了消息:
.h:
#define WM_CONTRALLINEWORK WM_USER+1
public:
//WM_CONTRALLINEWORK消息处里函数原型
LRESULT OnContralLineWork(WPARAM wParam,LPARAM lParam);
.cpp中:
//消息响应函数
BEGIN_MESSAGE_MAP(CHowTestDoc, CDocument)
//{{AFX_MSG_MAP(CHowTestDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
ON_MESSAGE(WM_CONTRALLINEWORK,OnContralLineWork)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
LRESULT CHowTestDoc::OnContralLineWork(WPARAM wParam,LPARAM lParam)
{
CString show;
show.Format("收到消息,参数为:%d,%d",wParam,lParam);
AfxMessageBox(show);
return 0;
}
这样,在View里面或别的地方怎么向它发送这个消息呢?试了几个函数都不行,多谢各位指点!!
解决方案 »
- 半桶水都没有啊。。怎么办。。求帮忙~~
- 三维模型的坐标转换
- 请问如何设置控件的属性?
- 现在的杀毒软件一点都不管用,想自己编,高手给点思路!
- 编译ACCESS数据库警告求助!!!
- 为何每次打开一个新的document,ChtmlEditview构造函数要调用两次??
- 那里有AutoCAD中用ObjectARX的二次开发的资料下载
- 内存泄露问题(高手请进)
- 关于edit控件的问题
- 客户端应用如何从组件获取大块数据(几K)?
- 关于U盘,控制代码IOCTL_GET_USB_DESCRIPTOR问题,顶者有分!
- link dll error:unresolved external symbol __imp__dr_GetFrame@8
SendMessage(NULL, WM_CONTRALLINEWORK,....)2、以WM开头的消息一般是窗口消息,可你该消息的响应又不在窗口类中,所以你的设计是否合适?
//{{AFX_MSG_MAP(CHowTestDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
ON_COMMAND(WM_CONTRALLINEWORK,OnContralLineWork)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
在视图里:
this->SendMessage(WM_COMMAND, WM_CONTRALLINEWORK, 0);文档不是窗口,不能接收消息,但是它能接收WM_COMMAND,原因是:
BOOL CView::OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo)
{
// first pump through pane
if (CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE; // then pump through document
if (m_pDocument != NULL)
{
// 注意这里!
CPushRoutingView push(this);
return m_pDocument->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
} return FALSE;
}
所以,你把你的自定义消息命名成自定义命令更好!
//{{AFX_MSG_MAP(CHowTestDoc)
// 这里改成:
ON_COMMAND(WM_CONTRALLINEWORK,OnContralLineWork)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
在视图里:
this->SendMessage(WM_COMMAND, WM_CONTRALLINEWORK, 0);文档不是窗口,不能接收消息,但是它能接收WM_COMMAND,原因是:
BOOL CView::OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo)
{
// first pump through pane
if (CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE; // then pump through document
if (m_pDocument != NULL)
{
// 注意这里!
CPushRoutingView push(this);
return m_pDocument->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
} return FALSE;
}
所以,你把你的自定义消息命名成自定义命令更好!