dll非模态窗口不响应按钮消息

整理自网络,但未验证。

 

解决方法:

 

1.dll导出一条函数 DllPreTranslateMessage

 

BOOL PASCAL DllPreTranslateMessage(MSG *pMsg)

{

    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    return theApp.PreTranslateMessage(pMsg);

}

 

2.在主程序的CWinApp的PreTranslateMessage中直接调用DLL的DllPreTranslateMessage函数。但记住要先调用DLL中的函数。

 

BOOL CMyApp::PreTranslateMessage(MSG* pMsg)

{

    // TODO: Add your specialized code here and/or call the base class

 

    if(DllPreTranslateMessage(pMsg))

        return TRUE;

 

    return CWinApp::PreTranslateMessage(pMsg);

}

 

经过以上两步,DLL中的窗口就可以响应PreTranslateMessage了。

 

虽然未验证该方法是否解决"dll非模态窗口不响应按钮消息",但该方法提供了一个很好的思路,通过App中的PreTranslateMessage可以进入到dll的PreTranslateMessage,或许还可以解决其它问题!

原文地址:https://www.cnblogs.com/ant-wjf/p/3238403.html