我这样做的:
CWnd MyWnd;
MyWin.CreateEx(WS_EX_ACCEPTFILES,"My_Test","My first program1",WS_OVERLAPPEDWINDOW,0,0,300,300,NULL,NULL,NULL);
MyWin.ShowWindow(SW_MAXIMIZE);
窗口显示没问题,怎样实现其消息映射?我想Cwnd是CCmdTarget的子类,应该有消息映射,怎样在vc中找到修改其消息映射的地方啊难道只有从CWnd派生自己的类,才可以?
CWnd MyWnd;
MyWin.CreateEx(WS_EX_ACCEPTFILES,"My_Test","My first program1",WS_OVERLAPPEDWINDOW,0,0,300,300,NULL,NULL,NULL);
MyWin.ShowWindow(SW_MAXIMIZE);
窗口显示没问题,怎样实现其消息映射?我想Cwnd是CCmdTarget的子类,应该有消息映射,怎样在vc中找到修改其消息映射的地方啊难道只有从CWnd派生自己的类,才可以?
#include<afxwin.h>
class CMinApp:public CWinApp//定义应用程序类
{
public :
virtual BOOL InitInstance();//重载初始化函数
};
class CMainWnd:public CFrameWnd//定义主窗口类
{
protected:
afx_msg void OnLButtonDown(UINT nFlags,CPoint point);//定义鼠标左单击的消息处理函数
afx_msg void OnRButtonDown(UINT nFlags,CPoint point);
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP();//声明拥有消息映射
};
BEGIN_MESSAGE_MAP(CMainWnd,CFrameWnd)//声明主窗口的消息映射
ON_WM_LBUTTONDOWN()//鼠标左键按下消息映射
ON_WM_RBUTTONDOWN()
ON_WM_PAINT()
END_MESSAGE_MAP()//结束消息映射声明
void CMainWnd::OnLButtonDown(UINT nFlags,CPoint point){
CString szAboutLeft="This is a minimal Windows MFC program.\n"
"You've pressed the left mouse button!";
::MessageBeep(MB_ICONINFORMATION);//叫一声
::MessageBox(GetSafeHwnd(),szAboutLeft,"About",MB_OK|MB_ICONINFORMATION);//显示一个消息框
CFrameWnd::OnLButtonDown(nFlags,point);//执行鼠标按下的一般处理
}
void CMainWnd::OnRButtonDown(UINT nFlags,CPoint point){
CString szAboutRight="This is a minimal Windows MFC Program\n"
"You've pressed the right mouse button!";
::MessageBeep(MB_ICONINFORMATION);
::MessageBox(GetSafeHwnd(),szAboutRight,"About",MB_OK|MB_ICONINFORMATION);
CFrameWnd::OnRButtonDown(nFlags,point);
}
void CMainWnd::OnPaint(){
CPaintDC dc(this);
CRect rc;
GetClientRect(&rc);
dc.Ellipse(rc);
}
BOOL CMinApp::InitInstance(){//应用程序初始化函数
CMainWnd *pFrame=new CMainWnd;
pFrame->Create(0,_T("Another Minimal MFC Program"));
pFrame->ShowWindow(SW_SHOWMAXIMIZED);
pFrame->UpdateWindow();
this->m_pMainWnd=pFrame;
return TRUE;
}
CMinApp MyApp;//生成应用程序并执行应用程序
学习MFC吧,