DLL 内部的非模态对话框的 PreTranslateMessage 函数不执行
2015-08-19 16:12
375 查看
虽然MFC Regular DLL派生了CWinApp类,并有一个theApp全局对象。但它不包含CWinApp::Run机制,主消息由 exe 负责接收、分发。如果DLL 生成了无模式对话框或有自己的主框架窗口,则它应该导出函数来调用PreTranslateMessage。
exe程序需要调用这个导出函数。示例代码如下:
如果不这么做,则dll内部的非模态对话框PreTranslateMessage函数不会被执行,对话框内按Tab键也无法切换焦点。如果exe不是MFC程序,而是VB6.0、VC#程序,该如何处理PreTranslateMessage?这个问题需要再进行深入研究。此时,非模态对话框内按Tab键无法切换焦点,该如何处理?估计得使用键盘钩子了……
exe程序需要调用这个导出函数。示例代码如下:
//DLL端需要导出函数,调用AfxGetApp()->PreTranslateMessage __declspec(dllexport) BOOL DllPreTranslateMessage(MSG* pMsg) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); //切换模块状态 return AfxGetApp()->PreTranslateMessage(pMsg); } //exe端需要调用DLL的导出函数 class CTestApp : public CWinApp { public: BOOL PreTranslateMessage(MSG* pMsg) { if(DllPreTranslateMessage(pMsg)) { return TRUE; } return CWinApp::PreTranslateMessage(pMsg); } ...
//对话框 cpp 中处理回车事件 BOOL CTestDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN) { AfxMessage(_T("按下了回车键")); return TRUE; } return CDialog::PreTranslateMessage(pMsg); }
如果不这么做,则dll内部的非模态对话框PreTranslateMessage函数不会被执行,对话框内按Tab键也无法切换焦点。如果exe不是MFC程序,而是VB6.0、VC#程序,该如何处理PreTranslateMessage?这个问题需要再进行深入研究。此时,非模态对话框内按Tab键无法切换焦点,该如何处理?估计得使用键盘钩子了……
相关文章推荐
- tokudb
- Test Design Techniques - STATE BASED TESTING
- 汉字字符串排序,如人名排序
- 桌面支持--将excel打印到一个页面
- 打印2的n次方数字三角形
- JS时间特效最常用的三款
- 静态类
- [LeetCode] Insert Interval
- git 使用过程遇到的问题集合
- POJ 2585 Window Pains(拓扑排序·窗口覆盖)
- 模板
- XIB技巧
- POJ 1416 Shredding Company
- codeforces #267 C George and Job(DP)
- nginx安装
- 写文章与写程序
- 写文章与写程序
- Strategy Pattern
- sql 将‘1,2,3,4’转成相应的表,字段分隔表值函数,一行变多行,
- 如何用消息系统避免分布式事务?