非模态对话框不运行PreTranslateMessage??????????????

candeabc123 2012-08-07 06:42:31
如题,求解~~~~~~~谢谢!
网上查查,都没看到解决的方法。

对话框创建代码如下,

BOOL ret = m_Dlg.Create(IDD_DIALOG_MESS ,CWnd::FromHandle(::GetDesktopWindow()));// CWnd::FromHandle(m_hParent)
if(ret==0)
{
return NULL;
}
::ShowWindow(m_Dlg.m_hWnd,SW_SHOW);
...全文
891 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunsongshan0711 2013-01-23
  • 打赏
  • 举报
回复
回调函数一般都作为全局函数不作为成员函数,GetMessageProc应作为全局函数,不过这种方法也确实也解决了非模态对话框中消息的拦截。
candeabc123 2012-08-08
  • 打赏
  • 举报
回复
http://wenku.baidu.com/view/5c873a1d6bd97f192279e990.html
看到有人是使用Hook方法来做的,真是难找啊,分享给大家

LRESULT CALLBACK CMessMangerApp::GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
LPMSG lpMsg = (LPMSG) lParam;

if(AfxGetApp()->PreTranslateMessage(lpMsg))
{
lpMsg->message = WM_NULL;
lpMsg->lParam = 0L;
lpMsg->wParam = 0;
}

// Passes the hook information to the next hook procedure in
// the current hook chain.
return ::CallNextHookEx(hHook, nCode, wParam, lParam);
}

BOOL CMessMangerApp::InitInstance()
{
hHook = ::SetWindowsHookEx(
WH_GETMESSAGE,
GetMessageProc,
AfxGetInstanceHandle(),
GetCurrentThreadId());

ASSERT (hHook);
return CWinApp::InitInstance();
}

int CMyApp::ExitInstance()
{
UnhookWindowsHookEx((HHOOK)hHook);
return CWinApp::ExitInstance();
}
candeabc123 2012-08-08
  • 打赏
  • 举报
回复
schlafenhamster 2012-08-08
  • 打赏
  • 举报
回复
初始化:
m_pDlg2=new CChildDlg2;
m_pDlg2->Create(IDD_DIALOG2,this);
m_pDlg2->ShowWindow(SW_SHOW);
rc1.left=rc.Width()/2;
rc1.right=rc.right;
rc1.top=0;
rc1.bottom=rc.bottom;
m_pDlg2->MoveWindow(&rc1);
schlafenhamster 2012-08-08
  • 打赏
  • 举报
回复
// CChildDlg2 message handlers

BOOL CChildDlg2::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
afxDump << "ChildDlg2::PreTranslateMessage\n" ; return CDialog::PreTranslateMessage(pMsg);
}
//
ChildDlg2child风格。
candeabc123 2012-08-08
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

Child风格就在 CChildDlg中响应。
[/Quote]
PreTranslateMessage函数不执行到
schlafenhamster 2012-08-08
  • 打赏
  • 举报
回复
Child风格就在 CChildDlg中响应。
candeabc123 2012-08-08
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

非模态响应的PreTranslateMessage
是在你后面的那个窗口句柄
楼主的是:CWnd::FromHandle(::GetDesktopWindow())
[/Quote]

怎么让非模态对话框自己响应PreTranslateMessage()呢???
candeabc123 2012-08-08
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

非模态响应的PreTranslateMessage
是在你后面的那个窗口句柄
楼主的是:CWnd::FromHandle(::GetDesktopWindow())
[/Quote]

怎么让非模态对话框自己响应PreTranslateMessage()呢???
看不见的裂痕 2012-08-07
  • 打赏
  • 举报
回复
非模态响应的PreTranslateMessage
是在你后面的那个窗口句柄
楼主的是:CWnd::FromHandle(::GetDesktopWindow())
  • 打赏
  • 举报
回复
可以啊
贪玩的老鼠 2012-08-07
  • 打赏
  • 举报
回复
非模态框不响应PreTranslateMessage,
与父窗口共享消息,可在父窗口处理

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧