扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:李万林 来源:yesky 2007年11月16日
关键字:
//通过对话框按钮发送消息的函数 void TestDialog::OnDialogTest() { CMDIFrameWnd *pFrame; CMDIChildWnd *pChild; CView *pView; //获取主窗口指针 pFrame =(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; // 获取子窗口指针 pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); //获取视类指针 pView = pChild->GetActiveView(); if(active != NULL) active->PostMessage(WM_MY_MESSAGE,0,0);//发送消息 } |
static UINT WM_MY_MESSAGE=RegisterWindowMessage("Message"); |
protected: //{{AFX_MSG(CMessageView) //}}AFX_MSG afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam); //此行为添加代码 DECLARE_MESSAGE_MAP() 在视类文件MessageView.cpp中的消息映射中添加自定义消息映射 BEGIN_MESSAGE_MAP(CMessageView, CView) //{{AFX_MSG_MAP(CMessageView) //}}AFX_MSG_MAP // Standard printing commands ON_REGISTERED_MESSAGE(WM_MY_MESSAGE,OnMyMessage) //此行添加代码定义唯一消息 END_MESSAGE_MAP() |
LRESULT CMessageView::OnMyMessage(WPARAM wParam, LPARAM lParam) { CRect rect; GetClientRect(&rect); InvalidateRect(&rect); test=!test; return 0; } |
void CMessageView::OnDraw(CDC* pDC) { CMessageDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // 以下程序显示消息响应效果 if(test) pDC->TextOut(0,0,"消息响应!"); } |
#include "TestDialog.h"; OnTest()函数中添加代码 void CMainFrame::OnTest() { TestDialog dialog; dialog.DoModal(); } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。