Solved

non-modal forms and window controls

Posted on 2002-06-24
3
363 Views
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:

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
Comment
Question by:msessions
3 Comments
 
LVL 7

Accepted Solution

by:
Cynna earned 200 total points
ID: 7110120
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
 

Expert Comment

by:CleanupPing
ID: 9343166
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
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9453606
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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