自定义消息

http://msdn.microsoft.com/en-us/library/k35k2bfs(v=VS.90).aspx

 

 

/************************************************************************/
/* mywnd.h */
/************************************************************************/
#ifndef MYWND_H
#define MYWND_H

#include
<afxwin.h>

class MyWnd : public CFrameWnd
{
public:
MyWnd();
const static unsigned short WM_MYMSG;
DECLARE_MESSAGE_MAP()

afx_msg LRESULT showMsg(WPARAM, LPARAM);
afx_msg
void OnLButtonDown(UINT nFlags, CPoint point);
};

#endif

 

/************************************************************************/
/* myapp.h */
/************************************************************************/
#ifndef MYAPP_H
#define MYAPP_H

#include
<afxwin.h>

class MyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};
#endif

 

/************************************************************************/
/* mywnd.cpp */
/************************************************************************/
#include
"mywnd.h"

BEGIN_MESSAGE_MAP(MyWnd, CFrameWnd)
ON_MESSAGE(MyWnd::WM_MYMSG,
&MyWnd::showMsg)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

const unsigned short MyWnd::WM_MYMSG = WM_USER + 1;

MyWnd::MyWnd()
{
Create(NULL, _T(
"MyWnd"));
}

LRESULT MyWnd::showMsg(WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(wParam);
UNREFERENCED_PARAMETER(lParam);
MessageBox(_T(
"Hello, My Message!!!"));
return (LRESULT)0;
}
void MyWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
::PostMessage(m_hWnd, WM_MYMSG, 0, 0);
CFrameWnd::OnLButtonDown(nFlags, point);
}

 

/************************************************************************/
/* myapp.cpp */
/************************************************************************/
#include
"myapp.h"
#include
"mywnd.h"

BEGIN_MESSAGE_MAP(MyApp, CWinApp)
END_MESSAGE_MAP()

MyApp theApp;

BOOL MyApp::InitInstance()
{
m_pMainWnd
= new MyWnd();
m_pMainWnd
->ShowWindow(m_nCmdShow);
m_pMainWnd
->UpdateWindow();
return TRUE;
}

 

posted @ 2010-07-12 17:33  penink  阅读(153)  评论(0)    收藏  举报