Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to keep other forms visible while minimizing the main form Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
28-Oct-02
Category
VCL-Forms
Language
Delphi 2.x
Views
83
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to keep other forms visible while minimizing the main form

Answer:

Solve 1:

You need to disable Delphi's default minimization behaviour and take over yourself.

In the main forms FormCreate do this:


1   { ... }
2   ShowWindow(Application.handle, SW_HIDE);
3   SetWindowLong(Application.handle, GWL_EXSTYLE, GetWindowLong(application.handle,
4     GWL_EXSTYLE) and not WS_EX_APPWINDOW or WS_EX_TOOLWINDOW);
5   ShowWindow(Application.handle, SW_SHOW);
6   { ... }


That removes the application button from the taskbar.

The main form gets a handler for the WM_SYSCOMMAND message:

7   { ... }
8   private {form declaration}
9   
10  procedure WMSyscommand(var msg: TWmSysCommand); message WM_SYSCOMMAND;
11  
12  procedure TForm1.WMSyscommand(var msg: TWmSysCommand);
13  begin
14    case (msg.cmdtype and $FFF0) of
15      SC_MINIMIZE:
16        begin
17          ShowWindow(handle, SW_MINIMIZE);
18          msg.result := 0;
19        end;
20      SC_RESTORE:
21        begin
22          ShowWindow(handle, SW_RESTORE)
23            msg.result := 0;
24        end;
25    else
26      inherited;
27    end;
28  end;


This disables the default minimization behaviour.

To get a taskbar button for the form and have it minimize to the taskbar instead of 
to the desktop, override the CreateParams method of the main form and also of all 
the secondary forms:

29  { in form declaration }
30  
31  procedure CreateParams(var params: TCreateParams); override;
32  
33  procedure TForm1.CreateParams(var params: TCreateParams);
34  begin
35    inherited CreateParams(params);
36    params.ExStyle := params.ExStyle or WS_EX_APPWINDOW;
37  end;



Solve 2:

You must override the CreateParams() method and add the following code:
38  
39  procedure TForm2.CreateParams(var params: TCreateParams);
40  begin
41    inherited CreateParams(Params);
42    Params.ExStyle := params.ExStyle or WS_EX_APPWINDOW
43  end;


Something to keep in mind is that when you restore a minimized form, the entire 
application will be brought to the front If you don't want that to happen, do this:
44  
45  procedure TForm3.CreateParams(var params: TCreateParams);
46  begin
47    inherited CreateParams(Params);
48    Params.ExStyle := params.ExStyle or WS_EX_APPWINDOW;
49    Params.WndParent := GetDesktopWindow; {add this line}
50  end;


Now the forms will brought to the front independently. If you're launching forms from other form, you'll have to handle the paranting issues accordingly so that modal forms don't appear behind your other forms.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC