深入浅出MFC:对话框消息路由
[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:对话框消息路由的更多相关文章
- MFC的消息机制
MFC的消息循环(::GetMessage,::PeekMessage)消息泵(CWinThread::PumpMessage)和MFC的消息在窗口之间的路由是两件不同的事情 分两个步骤完成: 1 “ ...
- MFC编程入门之十六(对话框:消息对话框)
前面几节讲了属性页对话框,我们可以根据所讲内容方便的建立自己的属性页对话框.本节讲解Windows系统中最常用最简单的一类对话框--消息对话框. 我们在使用Windows系统的过程中经常会见到消息对话 ...
- mfc对话框不能响应键盘消息
这东西真是奇怪,找了半天原因,最终的发现却是让人抓狂,呵呵 现象:对话框按ESC或回车都不能关闭窗口(我没有处理PreTransplanteMessage),用spy++看,对话框完全收不到键盘消息 ...
- 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 ...
- MFC消息路由
1.Command Routing(命令传递):当消息进来时,会有一个泵推动它前进.消息如何进来,以有泵函数如何推动,都是属于windows程序设计的范畴, 消息如果是从子类流向父类(纵向流动),那么 ...
- MFC命令消息的路由
下面,我们以Menu这个程序为例,来看看 菜单命令消息路由的具体过程:当单击某个菜单项时,最先接收到这个菜单命令消息的是框架类.框架类将把接收到的这个消息交给它的子窗口.即视类,由视类首先进行处理.视 ...
- 深入浅出MFC学习笔记 消息
本章将会对MFC的消息映射和 命令传递机制做深入探讨. MFC规定了消息传递的路线,消息会按照这个路线传递下去,找不到归宿的话就交给DefWindowProc. 在产生窗口之前,如果我们在创建窗口时指 ...
- 深入浅出MFC——MFC六大关键技术仿真(二)
1. 仿真MFC目的:以MFC为例,学习application framework的内部运行.MFC六大关键技术: (1)MFC程序的初始化过程 (2)RTTI(Runtime Type Inform ...
- 《深入浅出MFC》下载
百度云及其他网盘下载地址:点我 编辑推荐 <深入浅出MFC>内含光盘一片,书中所有原始码与可执行文件尽在其中. 作者简介 侯俊杰,先生不知何许人也,闲静少言,不慕荣利.好读书,求甚解:每有 ...
随机推荐
- 微软重生:4年市值U型大逆转,超越谷歌重返巅峰!
划重点: 智东西(公众号:zhidxcom)文 | 寓扬 在最近的两个星期里,微软和谷歌正在进行一场市值大比拼,双方在7700亿美元上下厮杀正紧,抢夺着全球市值第三大公司的宝座(前两位为市值超过900 ...
- Anaconda的安装
Windows下Anaconda的安装和简单使用 Anaconda is a completely free Python distribution (including for commercial ...
- POJ 3041 Asteroids 最小覆盖数
http://poj.org/problem?id=3041 题目大意: 一辆宇宙飞船在一个小行星带中,你知道,这很危险.他有一种武器,可以清除掉一行或一列的小行星.问把小行星全部清除最少的武器使用次 ...
- python输出杨辉三角
使用python列表,展示杨辉三角 # !/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan yanghui = [] fo ...
- LoadRunner--录制手机APP脚本
通过LR录制手机脚本的方式有三种: 1)通过安卓模拟器录制: 2)通过抓包录制: 3)通过代理方式录制: 本文使用第二种方式进行录制,首先需要先安装LoadRunner11测试工具,然后安装lr录制A ...
- UVA 11178 - Morley's Theorem 向量
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- [TypeScript] Define a function type
type DigitValidator = (char) => boolean; -]{}/.test(char); export const digitValidators: {[key: s ...
- Win7下多线程中OpenFileDialog和SaveFileDialog失效的解决办法(转载)
在程序中,通常会使用独立线程来操作OpenFileDialog或者SaveFileDialog控件,但是在某些情况下(Win7系统下)调用 ShowDialog方法并不显示选择路径对话框.此时需要对启 ...
- 23种设计模式——Prototype模式
Prototype模式是提供自我复制的功能.包括浅拷贝和深拷贝. 一.Prototype模式的用途 场景1:游戏场景中有很多类似的敌人,它们的技能都一样,但是随着敌人出现的位置和不同,它们的能力也不太 ...
- Linux 系统 杀Oracle 进程
Linux 系统 杀Oracle 进程 杀掉进程用此方法比较好,能保证杀得干净,而不是用SQL alter system kill kill -9 `ps -ef|grep "oracle ...