[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. Git 经常使用命令

    Git经常使用命令备忘: Git配置 git config --global user.name "storm" git config --global user.email &q ...

  2. Altium Designer如何对齐原件

    右边那个图标是排列菜单

  3. 微服务实战(四):服务发现的可行方案以及实践案例 - DockOne.io

    原文:微服务实战(四):服务发现的可行方案以及实践案例 - DockOne.io 这是关于使用微服务架构创建应用系列的第四篇文章.第一篇介绍了微服务架构的模式,讨论了使用微服务架构的优缺点.第二和第三 ...

  4. [React Intl] Format Date and Time Using react-intl FormattedDate and FormattedTime

    Using the react-intl FormattedDate and FormattedTime components, we’ll render a JavaScript Date into ...

  5. Altium Designer的pcb上添加文字说明

  6. 配置IP地址及HOSTNAME脚本

    #!/bin/bash #修改IP及HOSTNAME ETHCONF=/etc/sysconfig/network-scripts/ifcfg-eth0 HOSTS=/etc/hosts NETWOR ...

  7. Win10系统如何设置所有程序默认以管理员身份运行?

    原文:Win10系统如何设置所有程序默认以管理员身份运行? 在win10系统中有些用户发现一些程序只有使用管理员身份运行能才打开,这样的话就感觉会麻烦很多,那么有没有办法设置所有程序都默认以管理员身份 ...

  8. centos中的配置文件 分类: B3_LINUX 2015-04-03 22:21 184人阅读 评论(0) 收藏

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一个 ...

  9. stm32的复用与映射

    摘自:https://blog.csdn.net/lincheng15/article/details/51789093 摘自:http://www.51hei.com/bbs/dpj-36242-1 ...

  10. 28、应用调试之strace命令来跟踪系统调用

    strace是个工具,在使用时需要先按照,见韦东山书籍: 1.tar xjf starce-4.5.15.tar.bz2 2.cd strace-4.5.15/ 3.patch -p1 < .. ...