<p>I have developed a COM component (dll) that implements an Edit() method displaying a WTL modal dialog.</p>

<p>The complete interface to this COM component corresponds to a software standard used in the chemical process industry (CAPE-OPEN) and as a result this COM component is supposed to be usable by a range of 3rd party executables that are out of my control.</p>

<p>My component works as expected in many of these EXEs, but for one in particular the Edit() method just hangs without the dialog appearing.</p>

<p>However, if I make a call to <code>::MessageBox()</code> immediately before <code>DoModal()</code> the dialog displays and behaves correctly after first showing the MessageBox.</p>

<p>I have a suspicion that the problem may be something to do with this particular EXE running as a 'hidden window application'.</p>

<p>I have tried using both NULL and the return value from <code>::GetConsoleWindow()</code> as the dialog's parent, neither have worked.</p>

<p>The dialog itself is an ATL/WTL CPropertySheetImpl.</p>

<p>The parent application (EXE) in question is out of my control as it is developed by a (mildly hostile) 3rd party.</p>

<p>I do know that I can successfully call <code>::MessageBox()</code> or display the standard Windows File Dialog from my COM component, and that after doing so I am then able to display my custom dialog. I'm just unable to display my custom dialog without first displaying a 'standard' dialog.</p>

<p>Can anyone suggest how I might get it to display the dialog without first showing an unnecessary MessageBox? I know it is possible because I've seen this EXE display the dialogs from other COM components corresponding to the same interface.</p>

[{'answer_id': 37943, 'author': 'Mark Ingram', 'author_id': 986, 'author_profile': 'https://Stackoverflow.com/users/986', 'pm_score': 1, 'selected': False, 'text': '<p>Are you using a parent for the Dialog? e.g.</p>\n\n<pre><code>MyDialog dialog(pParent);\ndialog.DoModal();\n</code></pre>\n\n<p>If you are, try removing the parent. Especially if the parent is the desktop window.</p>\n'}, {'answer_id': 37954, 'author': 'dguaraglia', 'author_id': 2384, 'author_profile': 'https://Stackoverflow.com/users/2384', 'pm_score': 1, 'selected': False, 'text': '<p>Depending on how the "hidden window" application works, it might not be able to display a window. For example, services don\'t have a "main message loop", and thus are not able to process messages sent to windows in the process. i.e, the application displaying the window should have something like this:</p>\n\n<pre><code>    while(GetMessage(&amp;msg, NULL, 0, 0))\n    {\n        if(!TranslateAccelerator(msg.hwnd, hAccelTable, &amp;msg)) \n        {\n            TranslateMessage(&amp;msg);\n            DispatchMessage(&amp;msg);\n        }\n    }\n</code></pre>\n\n<p>in WinMain.</p>\n'}, {'answer_id': 37984, 'author': 'Mark Ingram', 'author_id': 986, 'author_profile': 'https://Stackoverflow.com/users/986', 'pm_score': 1, 'selected': False, 'text': "<p>This isn't supposed to be reliable - but try ::GetDesktopWindow() as the parent (it returns a HWND).</p>\n\n<p>Be warned - if your app crashes, it will bring down the desktop with it. But i'd be interested to see if it works.</p>\n"}, {'answer_id': 37989, 'author': 'Tom Williams', 'author_id': 3229, 'author_profile': 'https://Stackoverflow.com/users/3229', 'pm_score': 1, 'selected': False, 'text': '<p>It turns out I was mistaken:</p>\n\n<ul>\n<li>If I create my dialog with a NULL parent then it is not displayed, and hangs the parent application</li>\n<li>However if I create my dialog with ::GetConsoleWindow() as the parent then the dialog is displayed; it just fooled me because it was displayed behind the window of the application that launched the parent application</li>\n</ul>\n\n<p>So now I just have to find out how to bring my dialog to the front.</p>\n\n<p>Thanks for the answers ;-)</p>\n'}, {'answer_id': 5243578, 'author': 'Adam Woś', 'author_id': 89005, 'author_profile': 'https://Stackoverflow.com/users/89005', 'pm_score': 0, 'selected': False, 'text': '<p>Whatever you do, <strong>do not</strong> use the desktop window as the parent for your modal dialog box.</p>\n\n<p>See here for explanation: <a href="http://blogs.msdn.com/b/oldnewthing/archive/2004/02/24/79212.aspx" rel="nofollow">http://blogs.msdn.com/b/oldnewthing/archive/2004/02/24/79212.aspx</a></p>\n\n<p>To quote the rationale:</p>\n\n<blockquote>\n  <p>Put this together: If the owner of a\n  modal dialog is the desktop, then the\n  desktop becomes disabled, which\n  disables all of its descendants. In\n  other words, it disables every window\n  in the system. Even the one you\'re\n  trying to display!</p>\n</blockquote>\n'}]
['https://Stackoverflow.com/questions/37920', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3229/']