c++ 求助:有关MFC中的消息映射的问题,下列程序为什么调用父类的消息处理函数 就能触发WM_LBUTTONDOWN消
调用自己的缺省处理函数却不能处理#include<afxwin.h>#include<afxext.h>classCMFCWnd:publicCFrameWnd{DECL...
调用自己的缺省处理函数却不能处理
#include <afxwin.h>
#include <afxext.h>
class CMFCWnd : public CFrameWnd
{
DECLARE_MESSAGE_MAP() //思考该宏的作用
public:
BOOL PreCreateWindow( CREATESTRUCT& cs)
{
cs.x=400;
cs.y=400;
cs.cx=400;
cs.cy=400;
return TRUE;
}
LRESULT WindowProc( UINT message, WPARAM wParam, LPARAM lParam )
{
CDC *dc;
PAINTSTRUCT ps;
CWinApp *app;
app=AfxGetApp();
switch(message)
{
case WM_PAINT:
dc=BeginPaint(&ps);
//app->LoadCursor(??);
dc->MoveTo(CPoint(100,100));
dc->LineTo(CPoint(400,400));
EndPaint(&ps);
return TRUE;
case WM_CLOSE:
if(MessageBox("是否关闭","提示",MB_YESNO)==IDYES)
{
//DestroyWindow();
return DefWindowProc(message,wParam,lParam);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return CFrameWnd::WindowProc(message,wParam,lParam);//上面的语句若换成return DefWindowProc(message,wParam,lParam;//不能触发消息WM_LBUTTONDOWN
}
//#define afx_msg
afx_msg LRESULT myLLL(WPARAM wparam, LPARAM lparam)
{
MessageBox("鼠标","提示",MB_OK);
return 0;
}
};
//开始消息映射
BEGIN_MESSAGE_MAP(CMFCWnd,CFrameWnd)
ON_MESSAGE(WM_LBUTTONDOWN,myLLL)
END_MESSAGE_MAP()
class CMFCApp : public CWinApp
{
public:
BOOL InitInstance()
{
CMFCWnd *w=new CMFCWnd();
w->Create(AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW),"我的窗体");
m_pMainWnd=w;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
CMFCApp app; 展开
#include <afxwin.h>
#include <afxext.h>
class CMFCWnd : public CFrameWnd
{
DECLARE_MESSAGE_MAP() //思考该宏的作用
public:
BOOL PreCreateWindow( CREATESTRUCT& cs)
{
cs.x=400;
cs.y=400;
cs.cx=400;
cs.cy=400;
return TRUE;
}
LRESULT WindowProc( UINT message, WPARAM wParam, LPARAM lParam )
{
CDC *dc;
PAINTSTRUCT ps;
CWinApp *app;
app=AfxGetApp();
switch(message)
{
case WM_PAINT:
dc=BeginPaint(&ps);
//app->LoadCursor(??);
dc->MoveTo(CPoint(100,100));
dc->LineTo(CPoint(400,400));
EndPaint(&ps);
return TRUE;
case WM_CLOSE:
if(MessageBox("是否关闭","提示",MB_YESNO)==IDYES)
{
//DestroyWindow();
return DefWindowProc(message,wParam,lParam);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return CFrameWnd::WindowProc(message,wParam,lParam);//上面的语句若换成return DefWindowProc(message,wParam,lParam;//不能触发消息WM_LBUTTONDOWN
}
//#define afx_msg
afx_msg LRESULT myLLL(WPARAM wparam, LPARAM lparam)
{
MessageBox("鼠标","提示",MB_OK);
return 0;
}
};
//开始消息映射
BEGIN_MESSAGE_MAP(CMFCWnd,CFrameWnd)
ON_MESSAGE(WM_LBUTTONDOWN,myLLL)
END_MESSAGE_MAP()
class CMFCApp : public CWinApp
{
public:
BOOL InitInstance()
{
CMFCWnd *w=new CMFCWnd();
w->Create(AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW),"我的窗体");
m_pMainWnd=w;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
CMFCApp app; 展开
展开全部
DefWindowProc和WindowProc都是回调处理消息API函数,DefWindowProc处理WindowProc没处理的消息。但是在你程序的场景中,CMFCWnd是CFrameWnd的子类,仅仅调用DefWindowProc不能实现全部CFrameWnd特色消息,必须调用父类的消息处理函数才行。
追问
可是我用了消息映射,WM_LBUTTONDOWN 消息应给由与之对应的函数来处理
而不是CFramWnd::DefWindowProc,我想问的是为什么换成CFrameWnd::DefWindowProc(message,wParam,lParam);函数afx_msg LRESULT myLLL(WPARAM wparam, LPARAM lparam)就能处理WM_LBUTTONDOWN 消息,而换成DefWindowProc,函数afx_msg LRESULT myLLL不处理WM_LBUTTONDOWN消息
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询