• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

non-modal forms and window controls

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:

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

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.

thanks.
0
msessions
Asked:
msessions
1 Solution
 
CynnaCommented:
msessions,

> ...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:

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

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


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);
begin
  inherited CreateParams(params);
  params.ExStyle := params.ExStyle or WS_EX_APPWINDOW;
  // params.WndParent := GetDesktopwindow;
end;

2. Add my example to your main form.

0
 
CleanupPingCommented:
msessions:
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 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
Lukasz LachCommented:
msessions,
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 ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now