[appmodul.cpp]

extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

[winmain.cpp]

int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
int nReturnCode = -1;
CWinThread* pThread = AfxGetThread();
CWinApp* pApp = AfxGetApp(); pApp->InitApplication(); if (!pThread->InitInstance())
{
return nReturnCode;
} nReturnCode = pApp->Run(); return nReturnCode;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

CWinApp::InitApplication 
CWinThread::InitInstance 
CWinThread::Run 
均是virtual函数


[ProjName.cpp]

BOOL CProjNameApp::InitInstance()
{
CWinAppEx::InitInstance(); CTestWYDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
} return FALSE;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

由于该函数返回FALSE,所以在AfxWinMain中函数结束后直接退出, 
不会运行pApp->Run()


[dlgcore.cpp]

INT_PTR CDialog::DoModal()
{
AfxHookWindowCreate(this);
CreateDlgIndirect();
RunModalLoop(); //消息循环 DestroyWindow(); //销毁了窗口 return;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

[wincore.cpp]

int CWnd::RunModalLoop(DWORD dwFlags)
{
for (;;)
{
if (!AfxPumpMessage())
{
AfxPostQuitMessage(0);
return -1;
}
} return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

[thrdcore.cpp]

BOOL AFXAPI AfxPumpMessage()
{
CWinThread *pThread = AfxGetThread();
return pThread->PumpMessage();
}
  • 1
  • 2
  • 3
  • 4
  • 5

[thrdcore.cpp]

BOOL CWinThread::PumpMessage()
{
return AfxInternalPumpMessage();
}
  • 1
  • 2
  • 3
  • 4

[thrdcore.cpp]

BOOL AFXAPI AfxInternalPumpMessage()
{
MSG msg;
::GetMessage(&msg);
if (!AfxPreTranslateMessage(&msg))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return TRUE;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

[thrdcore.cpp]

BOOL AfxPreTranslateMessage(MSG* pMsg)
{
CWinThread *pThread = AfxGetThread();
return pThread->PreTranslateMessage(pMsg);
}
  • 1
  • 2
  • 3
  • 4
  • 5

[thrdcore.cpp]

BOOL CWinThread::PreTranslateMessage(MSG* pMsg)
{
return AfxInternalPreTranslateMessage(pMsg);
}
  • 1
  • 2
  • 3
  • 4

[thrdcore.cpp]

BOOL AfxInternalPreTranslateMessage(MSG* pMsg)
{
CWnd* pMainWnd = AfxGetMainWnd();
if (CWnd::WalkPreTranslateTree(pMainWnd->GetSafeHwnd(), pMsg))
return TRUE;
return FALSE;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

[wincore.cpp]

//
// 返回TRUE or FALSE
// 由以上流程得:该函数返回TRUE,则pMsg指向的消息将会被忽略而不处理
// 返回FALSE,则会DispatchMessage到对应的窗口过程函数处理
//
BOOL PASCAL CWnd::WalkPreTranslateTree(HWND hWndStop, MSG* pMsg)
{
//
// 先调用本窗口对应CWnd类的PreTranslateMessage
// 再往父窗口层层上溯调用对应CWnd类的PreTranslateMessage直到上溯到hWndStop对应的窗口
// 若其中的某个PreTranslateMessage返回TRUE, 则函数退出返回TRUE
// 否则上溯完成返回FALSE
//
for (HWND hWnd = pMsg->hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd))
{
CWnd* pWnd = CWnd::FromHandlePermanent(hWnd);
if (pWnd != NULL)
{
if (pWnd->PreTranslateMessage(pMsg))
return TRUE;
}
if (hWnd == hWndStop)
break;
}
return FALSE;
}

http://blog.csdn.net/hisinwang/article/details/45786757

深入浅出MFC:对话框消息路由的更多相关文章

  1. MFC的消息机制

    MFC的消息循环(::GetMessage,::PeekMessage)消息泵(CWinThread::PumpMessage)和MFC的消息在窗口之间的路由是两件不同的事情 分两个步骤完成: 1 “ ...

  2. MFC编程入门之十六(对话框:消息对话框)

    前面几节讲了属性页对话框,我们可以根据所讲内容方便的建立自己的属性页对话框.本节讲解Windows系统中最常用最简单的一类对话框--消息对话框. 我们在使用Windows系统的过程中经常会见到消息对话 ...

  3. mfc对话框不能响应键盘消息

    这东西真是奇怪,找了半天原因,最终的发现却是让人抓狂,呵呵 现象:对话框按ESC或回车都不能关闭窗口(我没有处理PreTransplanteMessage),用spy++看,对话框完全收不到键盘消息 ...

  4. Meandering Through the Maze of MFC Message and Command Routing MFC消息路由机制分析

    Meandering Through the Maze of MFC Message and Command Routing Paul DiLascia Paul DiLascia is a free ...

  5. MFC消息路由

    1.Command Routing(命令传递):当消息进来时,会有一个泵推动它前进.消息如何进来,以有泵函数如何推动,都是属于windows程序设计的范畴, 消息如果是从子类流向父类(纵向流动),那么 ...

  6. MFC命令消息的路由

    下面,我们以Menu这个程序为例,来看看 菜单命令消息路由的具体过程:当单击某个菜单项时,最先接收到这个菜单命令消息的是框架类.框架类将把接收到的这个消息交给它的子窗口.即视类,由视类首先进行处理.视 ...

  7. 深入浅出MFC学习笔记 消息

    本章将会对MFC的消息映射和 命令传递机制做深入探讨. MFC规定了消息传递的路线,消息会按照这个路线传递下去,找不到归宿的话就交给DefWindowProc. 在产生窗口之前,如果我们在创建窗口时指 ...

  8. 深入浅出MFC——MFC六大关键技术仿真(二)

    1. 仿真MFC目的:以MFC为例,学习application framework的内部运行.MFC六大关键技术: (1)MFC程序的初始化过程 (2)RTTI(Runtime Type Inform ...

  9. 《深入浅出MFC》下载

    百度云及其他网盘下载地址:点我 编辑推荐 <深入浅出MFC>内含光盘一片,书中所有原始码与可执行文件尽在其中. 作者简介 侯俊杰,先生不知何许人也,闲静少言,不慕荣利.好读书,求甚解:每有 ...

随机推荐

  1. [D3] Add image to the node

    We can create node with 'g' container, then append 'image' to the nodes. // Create container for the ...

  2. usr/bin/mysqladmin: refresh failed; error: &#39;Unknown error&#39;

    debian wheezy 升级后, 由于授权错误, 导致password给改动, 在debian的mysql safe下也无法进入.   我在/etc/mysql/my.cnf 里面已经改动了bin ...

  3. Windows Forms 布局篇

    1,锚定功能(Anchor属性) 默认为“Top,Left”,不管窗体大小如果改变,保持相对于窗体左上角的位置. 如果设置为”Top,Bottom,Left,Right”这样,控件的大小将随窗体的大小 ...

  4. Socket 长连接与短连接,心跳

    长连接与短连接 所谓长连接,指在一个TCP连接上可以连续发送多个数据包,在TCP连接保持期间,如果没有数据包发送,需要双方发检测包以维持此连接,一般需要自己做在线维持. 短连接是指通信双方有数据交互时 ...

  5. amazeui页面分析3

    amazeui页面分析3 一.总结 1. 本质是list列表,是ul套li的形式,只不过li里面是图片 <li class="am-g am-list-item-desced am-l ...

  6. jQuery笔记---选择器(二)

    1.选择器练习: 1)查找UL中的元素的内容 格式:$(“ul li:XX”).text() XX:代表方法 比如:获取到第一元素,然后获取当中的值 $(“ul li:first”).text() 获 ...

  7. LA 3026 - Period KMP

    看题传送门:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  8. mongodb查询部分满足条件的列

    db.tblorders.createIndex( { orderid : -1 },{background:true, name:"index_orderid"} ); db.o ...

  9. IDC报告:从IaaS到PaaS,阿里云主导云计算市场

    11月7日,著名国际研究机构IDC发布了2017年上半年中国公共云PaaS市场调研结果,阿里云以27%的份额保持压倒性领先,是第二名的近三倍.结合IDC上一份IaaS市场的报告(阿里云第一,占比47. ...

  10. 正确使用pthread_create,防止内存泄漏

    近日,听说pthread_create会造成内存泄漏,觉得不可思议,因此对posix(nptl)的线程创建和销毁进行了分析.   分析结果:如果使用不当,确实会造成内存泄漏. 产生根源:pthread ...