通过COM创建多个MFC对话框,奇怪的行为 [英] Creating multiple MFC dialogs through COM, strange behaviour

查看:307
本文介绍了通过COM创建多个MFC对话框,奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:请参阅此其他主题,而不是全部COM工具不是问题的一部分。






我们的一个应用程序有一个COM接口, :

  STDMETHODIMP CSomeClass :: LaunchDialog(BSTR TextToDisplay)
{
CDialog * pDlg = new CSomeDialog TextToDisplay);
pDlg-> BringWindowToTop();
}

由于某种原因,当服务器一次调用COM方法多次时,我们得到奇怪的行为:




  • 我们得到多个对话框,但任务栏中只有一个条目

  • 对话框Z顺序是基于创建的订单,不能更改...第一个创建的对话框总是显示在第二个对话框下,第二个位于第三个对话框下,即使您将它们拖动也是如此。

  • 如果创建了N个对话框,关闭其中一个会关闭它,之后创建所有其他对话框。



这是不知何故,如果你创建了5个对话框,并且你关闭了第三个,#3,#4,像对话框是兄弟姐妹,但我没有看到任何奇怪的事情。这可能是由于COM,还是这是一个奇怪的MFC / Win32问题?



编辑:如果接口方法被分别调用几次,它的工作原理。只有当服务器组件立即发送几个通过,它似乎混乱。



EDIT2:
我将此日志记录在:

  std :: stringstream ss; 
HWND self = dlg-> m_hWnd;
HWND parent = dlg-> GetParent()? dlg-> GetParent() - > m_hWnd:0;
ss<<<<<<<< std :: endl;
OutputDebugString(ss.str()。c_str());

它提供:



  • 创建Dlg。 HWND = 0013014A,Parent = 00000000

  • 已创建Dlg。 HWND = 001B0390,Parent = 0013014A

  • 创建Dlg。 HWND = 000B03B0,Parent = 001B0390


很清楚,对话是彼此的孩子。但 问题是,为什么?它似乎Windows自动这样做...



这个问题似乎是略微偏离了育儿的主要问题,所以我试图分离出来主要问题是新问题

解决方案

听起来第一个对话框已设置为第二个对话框的所有者,第二个对话框设置为第三个对象的所有者。你可以更改对话框初始化以明确指定所有者窗口吗?是否有一个有意义的窗口分配?也许桌面窗口,如果他们都打算是顶级?



如果你想能够访问所有三个(或更多),那么他们会需要是无模式的。尝试使用 Create(CSomeClass :: IDD,CWnd :: GetDesktopWindow()),你应该看到兄弟对话框,所有这些都显示在任务栏上。 >

Updated: please see this other thread instead, all this COM stuff is not part of the problem.


One of our apps has a COM interface which will launch a dialog, e.g:

STDMETHODIMP CSomeClass::LaunchDialog(BSTR TextToDisplay)
{
  CDialog *pDlg = new CSomeDialog(TextToDisplay);
  pDlg->BringWindowToTop();
}

For some reason when the COM method is called several times at once by the server, we get odd behaviour:

  • We get multiple dialogs, but only one entry in the taskbar
  • Dialog Z-order is based on order created and can't be changed... the first dialog created is always shown under the 2nd one, 2nd under 3rd, etc, even when you drag them around
  • if N dialogs were created, closing one of them closes it and all the others created afterwards. e.g if 5 dialogsa re created and you close the 3rd one, #3,#4,#5 all get closed.

It's somehow like the dialogs are siblings but I don't see anything weird going on. Is it perhaps due to COM, or is this a weird MFC/Win32 issue?

EDIT: If the interface method is called several times separately, it works as expected. Only when the server component sends several through at once does it seem to mess up. Could threading/timings be to blame?

EDIT2: I put this logging in:

std::stringstream ss;
HWND self = dlg->m_hWnd;
HWND parent = dlg->GetParent() ? dlg->GetParent()->m_hWnd : 0;
ss<<"Dlg created'. HWND = "<<self<<", Parent = "<<parent<<std::endl;
OutputDebugString(ss.str().c_str());

It gave:

  • Dlg created. HWND = 0013014A, Parent = 00000000
  • Dlg created. HWND = 001B0390, Parent = 0013014A
  • Dlg created. HWND = 000B03B0, Parent = 001B0390

So clearly the problem is the dialogs are being made children of each other. But the question is, WHY?! It seems Windows is doing this automatically...

This question seems to be slightly away from the main issue of parenting, so I have tried to separate out the main issue into a new question.

解决方案

It sounds like the first dialog has been set as the owner of the second, and the second as the owner of the third. Can you change the dialog initialization to explicitly specify the owner window? Is there a window that makes sense to assign? Perhaps the Desktop window, if they're all intended to be top-level?

If you want to be able to access all three (or more), then they would need to be modeless. Try using Create(CSomeClass::IDD, CWnd::GetDesktopWindow()), and you ought to see sibling dialogs, all of which show up on the taskbar.

这篇关于通过COM创建多个MFC对话框,奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆