MFC-消息映射机制
#include <afxwin.h>
class MyFrameWnd :public CFrameWnd {
public:
virtual LRESULT WindowProc(UINT msgID,WPARAM wParam,LPARAM IParam);
};
LRESULT MyFrameWnd::WindowProc(UINT msgID, WPARAM wParam, LPARAM IParam) {
switch (msgID)
{
case WM_CREATE:
AfxMessageBox("Hi Major");
break;
}
return CFrameWnd::WindowProc(msgID,wParam,IParam);
}
class MyWinApp :public CWinApp {
public:
MyWinApp() {
}
virtual BOOL InitInstance() {
MyFrameWnd* pFrame = new MyFrameWnd;
pFrame->Create(NULL,"Test");
m_pMainWnd = pFrame;
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}
};
MyWinApp mainApp;
#include <afxwin.h>
class MyFrameWnd :public CFrameWnd {
DECLARE_MESSAGE_MAP()
public:
LRESULT OnCreate(WPARAM wParam,LPARAM IParam);
};
BEGIN_MESSAGE_MAP(MyFrameWnd,CFrameWnd)
ON_MESSAGE(WM_CREATE,OnCreate)
END_MESSAGE_MAP()
LRESULT MyFrameWnd::OnCreate(WPARAM wParam, LPARAM IParam) {
AfxMessageBox("Hi Major!");
return 0;
}
class MyWinApp :public CWinApp {
public:
MyWinApp() {
}
virtual BOOL InitInstance() {
MyFrameWnd* pFrame = new MyFrameWnd;
pFrame->Create(NULL,"Test");
m_pMainWnd = pFrame;
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}
};
MyWinApp mainApp;
#include <afxwin.h>
class MyFrameWnd :public CFrameWnd {
DECLARE_MESSAGE_MAP()
public:
int OnCreate(LPCREATESTRUCT pcs);
};
BEGIN_MESSAGE_MAP(MyFrameWnd,CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
int MyFrameWnd::OnCreate(LPCREATESTRUCT pcs) {
AfxMessageBox("Hi Major!");
return CFrameWnd::OnCreate(pcs);
}
class MyWinApp :public CWinApp {
public:
MyWinApp() {
}
virtual BOOL InitInstance() {
MyFrameWnd* pFrame = new MyFrameWnd;
pFrame->Create(NULL,"Test");
m_pMainWnd = pFrame;
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}
};
MyWinApp mainApp;
#include <afxwin.h>
class MyFrameWnd :public CFrameWnd {
DECLARE_MESSAGE_MAP()
public:
int OnCreate(LPCREATESTRUCT pcs);
void OnPaint();
};
BEGIN_MESSAGE_MAP(MyFrameWnd,CFrameWnd)
ON_WM_CREATE()
ON_WM_PAINT()
END_MESSAGE_MAP()
int MyFrameWnd::OnCreate(LPCREATESTRUCT pcs) {
AfxMessageBox("Hi Major!");
return CFrameWnd::OnCreate(pcs);
}
void MyFrameWnd::OnPaint() {
PAINTSTRUCT ps = { 0 };
HDC hdc = ::BeginPaint(this->m_hWnd,&ps);
::TextOutA(hdc,100,100,"Hi Major!",9);
::EndPaint(m_hWnd,&ps);
}
class MyWinApp :public CWinApp {
public:
MyWinApp() {
}
virtual BOOL InitInstance() {
MyFrameWnd* pFrame = new MyFrameWnd;
pFrame->Create(NULL,"Test");
m_pMainWnd = pFrame;
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}
};
MyWinApp mainApp;
#include <afxwin.h>
class MyFrameWnd :public CFrameWnd {
DECLARE_MESSAGE_MAP()
public:
int OnCreate(LPCREATESTRUCT pcs);
void OnPaint();
void OnMouseMove(UINT nKey,CPoint pt);
int m_x;
int m_y;
};
BEGIN_MESSAGE_MAP(MyFrameWnd,CFrameWnd)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
int MyFrameWnd::OnCreate(LPCREATESTRUCT pcs) {
AfxMessageBox("Hi Major!");
return CFrameWnd::OnCreate(pcs);
}
void MyFrameWnd::OnPaint() {
PAINTSTRUCT ps = { 0 };
HDC hdc = ::BeginPaint(this->m_hWnd,&ps);
::TextOutA(hdc, m_x, m_y,"Hi Major!",9);
::EndPaint(m_hWnd,&ps);
}
void MyFrameWnd::OnMouseMove(UINT nKey, CPoint pt) {
m_x = pt.x;
m_y = pt.y;
::InvalidateRect(this->m_hWnd,NULL,TRUE);
}
class MyWinApp :public CWinApp {
public:
MyWinApp() {
}
virtual BOOL InitInstance() {
MyFrameWnd* pFrame = new MyFrameWnd;
pFrame->Create(NULL,"Test");
m_pMainWnd = pFrame;
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}
};
MyWinApp mainApp;
#include <afxwin.h>
#define WM_MYMESSAGE WM_USER+001
class MyFrameWnd :public CFrameWnd {
DECLARE_MESSAGE_MAP()
public:
int OnCreate(LPCREATESTRUCT pcs);
void OnPaint();
void OnMouseMove(UINT nKey,CPoint pt);
LRESULT OnMyMessage(WPARAM wParam,LPARAM IParam);
int m_x;
int m_y;
};
BEGIN_MESSAGE_MAP(MyFrameWnd,CFrameWnd)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_MOUSEMOVE()
ON_MESSAGE(WM_MYMESSAGE,OnMyMessage)
END_MESSAGE_MAP()
int MyFrameWnd::OnCreate(LPCREATESTRUCT pcs) {
AfxMessageBox("Hi Major!");
::PostMessage(this->m_hWnd, WM_MYMESSAGE,1,2);
return CFrameWnd::OnCreate(pcs);
}
LRESULT MyFrameWnd::OnMyMessage(WPARAM wParam, LPARAM IParam) {
CString str;
str.Format("wParam=%d,IParam=%d",wParam,IParam);
AfxMessageBox(str);
return 0;
}
void MyFrameWnd::OnPaint() {
PAINTSTRUCT ps = { 0 };
HDC hdc = ::BeginPaint(this->m_hWnd,&ps);
::TextOutA(hdc, m_x, m_y,"Hi Major!",9);
::EndPaint(m_hWnd,&ps);
}
void MyFrameWnd::OnMouseMove(UINT nKey, CPoint pt) {
m_x = pt.x;
m_y = pt.y;
::InvalidateRect(this->m_hWnd,NULL,TRUE);
}
class MyWinApp :public CWinApp {
public:
MyWinApp() {
}
virtual BOOL InitInstance() {
MyFrameWnd* pFrame = new MyFrameWnd;
pFrame->Create(NULL,"Test");
m_pMainWnd = pFrame;
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}
};
MyWinApp mainApp;