为modaldialogbox 实现pretranslatemessage

来源:互联网 发布:手机淘宝一排三个图片 编辑:程序博客网 时间:2024/04/30 08:31

atl 中modaldialogbox实现的CDialogImpl 是没有PreTranslateMessage的,就算增加对应实现也是没有作用的

原因:PreTranslateMessage是框架部分的代码并非系统部分modaldialogbox的独立消息循环并不能调用PreTranslateMessage


解决方法:设置系统钩子捕获消息


static HHOOK g_hHook_GetMessage = 0;static DWORD g_hHook_GetMessage_TargetThreadId = 0;BOOL g_PreTranslateMessage(MSG* pMsg){if (g_pMessageLoop){return g_pMessageLoop->PreTranslateMessage(pMsg);}return FALSE;}static LRESULT CALLBACK s_MessageProc(int nCode, WPARAM wParam, LPARAM lParam){if (nCode < 0){return CallNextHookEx(g_hHook_GetMessage, nCode, wParam, lParam);}if(MSGF_DIALOGBOX == nCode ||MSGF_MENU == nCode ||MSGF_SCROLLBAR == nCode){MSG* pMsg = (MSG*)lParam;if (pMsg){if (g_PreTranslateMessage(pMsg)){return TRUE;}}}return CallNextHookEx(g_hHook_GetMessage, nCode, wParam, lParam);}void InstallPreTranslateMessage(HINSTANCE hInstance,DWORD dwThreadId){//HHOOK SetWindowsHookEx(int idHook,//HOOKPROC lpfn,//HINSTANCE hMod,//DWORD dwThreadId//);g_hHook_GetMessage = ::SetWindowsHookEx(WH_MSGFILTER, s_MessageProc, hInstance, dwThreadId);}


0 0