non-modal forms and window controls

Posted on 2002-06-24
Last Modified: 2010-04-04
i have a non-modal form that is generated from my main form. these non-modal forms when minimized need to go to the taskbar. to do this i've used the following code in my non-modal forms:

    procedure CreateParams(var params: TCreateParams); override;
//disassociates form from application so that it minimizes to the windows toolbar.
procedure TForm2.CreateParams(var params: TCreateParams);
 inherited CreateParams(params);
 params.ExStyle := params.ExStyle or WS_EX_APPWINDOW;
 params.WndParent := GetDesktopwindow;

however, all is well except that when another window control has focus from within these non-modal forms, the non-modal form loses its place in the z-order and doesn't appear behind the window control(messagedlg,popup-grid from dblookupedit control, etc.) and appears to the user to disappear. i've narrowed it down to the last line of code above:

params.WndParent := GetDesktopwindow;

if i comment this out, i get what i need but when i minimize the mainform, all non-modal windows are minimized within the mainform and unaccessable. placing the params.WndParent := GetDesktopwindow; code back in fixes this problem but i get the window z-order problem that i mention above. i want to be able to:

1. minimize non-modal forms generated from mainform to taskbar.

2. when mainform is minimized, all non-modals forms generated from mainform to not minimize unless user minimizes these forms.

3. all window controls on non-modal forms appear above (in the z-order) the "calling" non-modal form and not appear to the user to disappear.

Question by:msessions
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

Cynna earned 200 total points
ID: 7110120

> ...if i comment this out, i get what i need but when i minimize the mainform, all non-modal windows are minimized within the mainform ...

When you minimize the main form, default behaviour is to
hide and minimize application window. You should prevent
this by making main form minimize normally.

If Form1 is your main form, Copy/Paste this:

In Form1 declaration add:

    procedure WMSyscommand(Var msg: TWmSysCommand);   message WM_SYSCOMMAND;

...and in implemetation part:
procedure TForm1.WMSyscommand(var msg: TWmSysCommand);
    case (msg.cmdtype and $FFF0) of
      SC_MINIMIZE: begin
                     ShowWindow( handle, SW_MINIMIZE );
                     msg.result := 0;
      SC_RESTORE: begin
                    ShowWindow( handle, SW_RESTORE );
                    msg.result := 0;
      else inherited;

This code will handle minimization/restoration of the
main form instead of (for your scenario problematic)
default behaviour.

So, to recap:

1. Keep your b) scenario, ie:

procedure TForm2.CreateParams(var params: TCreateParams);
  inherited CreateParams(params);
  params.ExStyle := params.ExStyle or WS_EX_APPWINDOW;
  // params.WndParent := GetDesktopwindow;

2. Add my example to your main form.


Expert Comment

ID: 9343166
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Expert Comment

by:Lukasz Lach
ID: 9453606
No comment has been added lately (17 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to Cynna http:#7110120

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --


EE Cleanup Volunteer

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month4 days, 21 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question