Creating multiple MFC dialogs via COM, strange behavior

Updated: See this other thread , all of these COM stuff are not part of the issue.


One of our applications has a COM interface that will launch a dialog, for example:

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

      

For some reason, when a COM method is called by multiple servers at once, we get odd behavior:

  • We get multiple dialogs, but only one entry in the taskbar
  • Dialog Z-order is based on the created order and cannot be changed ... the first dialog created is always displayed under the second, the second under the third, etc., even when you drag them around
  • if N dialogs were created, closing one of them closes it and all the others created later. for example, if 5 dialog boxes are created and you close the third one, # 3, # 4, # 5 all are closed.

It's kind of like dialogue - brothers and sisters, but I don't see anything strange. Could it be COM related, or is it a weird MFC / Win32 issue?

EDIT: If the interface method is called multiple times separately, it works as expected. Only when the server component is sending multiple instances at once does it seem like a mess. Could threads / timings be to blame?

EDIT2: I entered this login:

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

      

He gave:

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

So the problem is that the dialogues are created by each other's children. But the question is, WHY ?! Windows seems to do this automatically ...

This question seems to be a bit off the main parenting issue, so I tried to isolate the main issue into a new question .

0


a source to share


1 answer


It looks like the first dialog was set as the owner of the second, and the second as the owner of the third. Can you change the initialization of the dialog to explicitly specify the owner window? Is there a window that makes sense to assign? Perhaps the desktop window if they are all meant to be top-level?



If you want to have access to all three (or more), then they must be modeless. Try using Create(CSomeClass::IDD, CWnd::GetDesktopWindow())

it and you should see sister dialogs, all of which are displayed in the taskbar.

0


a source







All Articles