<p>I have a Delphi 7 application that has two views of a document (e.g. a WYSIWYG HTML edit might have a WYSIWYG view and a source view - not my real application). They can be opened in separate windows, or docked into tabs in the main window.</p>

<p>If I open a modal dialog from one of the separate forms, the main form is brought to the front, and is shown as the selected window in the windows taskbar. Say the main form is the WYSIWYG view, and the source view is poped out. You go to a particular point in the source view and insert an image tag. A dialog appears to allow you to select and enter the properties you want for the image. If the WYSIWYG view and the source view overlap, the WYSIWYG view will be brought to the front and the source view is hidden. Once the dialog is dismissed, the source view comes back into sight.</p>

<p>I've tried setting the owner and the ParentWindow properties to the form it is related to:</p>

<blockquote><code>dialog := TDialogForm.Create( parentForm );<br>
  dialog.ParentWindow := parentForm.Handle;
</code></blockquote>

<p>How can I fix this problem? What else should I be trying?</p>

<p>Given that people seem to be stumbling on my example, perhaps I can try with a better example: a text editor that allows you to have more than one file open at the same time. The files you have open are either in tabs (like in the Delphi IDE) or in its own window. Suppose the user brings up the spell check dialog or the find dialog. What happens, is that if the file is being editing in its own window, that window is sent to below the main form in the z-order when the modal dialog is shown; once the dialog is closed, it is returned to its original z-order.</p>

<p><b>Note</b>: If you are using Delphi 7 and looking for a solution to this problem, see my answer lower down on the page to see what I ended up doing.</p>

[{'answer_id': 21809, 'author': 'Ryan Farley', 'author_id': 1627, 'author_profile': 'https://Stackoverflow.com/users/1627', 'pm_score': 0, 'selected': False, 'text': '<p>First of all, I am not completely sure I follow, you might need to provide some additional details to help us understand what is happening and what the problem is. I guess I am not sure I understand exactly what you\'re trying to accomplish and what the problem is.</p>\n\n<p>Second, you shouldn\'t need to set the dialog\'s parent since that is essentially what is happening with the call to Create (passing the parent). The dialogs you\'re describing sound like they could use some "re-thinking" a bit to be honest. Is this dialog to enter the properties of the image a child of the source window, or the WYSIWYG window?</p>\n'}, {'answer_id': 21915, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 1, 'selected': False, 'text': '<p>Is the dialog shown using ShowModal or just Show? You should probably set the PopupMode property correct of the your dialog. pmAuto would probably your best choice. Also see if you need to set the PopupParent property.</p>\n'}, {'answer_id': 21978, 'author': 'Marius', 'author_id': 1008, 'author_profile': 'https://Stackoverflow.com/users/1008', 'pm_score': 4, 'selected': True, 'text': "<p>I'd use this code... (Basically what Lars said)</p>\n\n<pre><code>dialog := TDialogForm.Create( parentForm );\ndialog.PopupParent := parentForm;\ndialog.PopupMode   := pmExplicit; \ndialog.ShowModal();\n</code></pre>\n"}, {'answer_id': 22105, 'author': 'Andrew', 'author_id': 1389, 'author_profile': 'https://Stackoverflow.com/users/1389', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m not sure I quite understand what you are getting at, but here\'s a few things I can suggest you can try...</p>\n\n<ol>\n<li>This behaviour changes between different versions of Delphi. I\'d suggest that this is due to the hoops they jumped through to support Windows Vista in Delphi 2007.</li>\n<li>If you are using Delphi 2007, try removing the line from the project source file that sets the Application.MainFormOnTaskBar boolean variable.</li>\n<li>With this removed, you should be able to use the various Form\'s BringToFront / SendToBack methods to achieve the Z-ordering that you are after.</li>\n</ol>\n\n<p>I suspect that what you\'ve discovered has been discussed on <a href="http://www.stevetrefethen.com/blog/TheNewVCLPropertyTApplicationMainFormOnTaskbarInDelphi2007.aspx" rel="nofollow noreferrer">this link</a>\nOf course, I may have just missed your point entirely, so apologies in advance!  </p>\n'}, {'answer_id': 29257, 'author': 'garethm', 'author_id': 2219, 'author_profile': 'https://Stackoverflow.com/users/2219', 'pm_score': 2, 'selected': False, 'text': '<p>I ultimately ended up finding the <a href="http://groups.google.com/group/borland.public.delphi.winapi/browse_frm/thread/36b3d5a199be91f4/7de8dab437f6aa1e?lnk=st&amp;q=delphi+main+form+modal+dialog+z-order#7de8dab437f6aa1e" rel="nofollow noreferrer">answer</a> using Google Groups. In a nutshell, all the modal dialogs need to have the following added to them:</p>\n\n<blockquote><pre><code>\nprocedure TDialogForm.CreateParams(var Params: TCreateParams);\nbegin\n  inherited;\n  Params.Style := Params.Style or WS_POPUP;\n  Params.WndParent := (Owner as TWinControl).Handle;\nend;\n</code></pre></blockquote>\n\n<p>I\'m guessing this does the equivalent of Lars\' and Marius\' answers in Delphi 7.</p>\n'}]
['https://Stackoverflow.com/questions/21749', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2219/']