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);
}