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 Add Taskbar-Button's for SubForms and manage them correctly 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
07-Jul-03
Category
VCL-Forms
Language
Delphi 2.x
Views
177
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Marc Hoffmann

I would like to add some Windows' Taskbar-Buttons for dynamic created forms w/o 
loosing the ability to 're-focus' the MainForm by clicking it's own button.

Answer:

The following example uses a Button (Button1)to dynamic create forms at runtime. 
Each form will be accessable via a corresponding Button placed on the Taskbar. You 
had to include the WMSysCommand method to enable the real "look&feel" of minimizing 
the MainForm. Otherwise, the MainForm will be minimized to the lower left side of 
the Screen or will be hidden in the background, so it's not possible to restore it 
correctly.

If you want to minimize (or hide) all subforms when minimizing the MainForm, you 
had to iterate through all registered subforms and hide them manualy. I don't know 
a better way right now, but if you've found any solution...:-) 

MainForm Unit

1   unit MainForm;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7     StdCtrls;
8   
9   type
10    TMainForm = class(TForm)
11      Button1: TButton;
12      procedure FormCreate(Sender: TObject);
13      procedure Button1Click(Sender: TObject);
14    private
15      { Private declarations }
16      procedure WMSysCommand(var Msg: TMessage); message WM_SYSCOMMAND;
17    public
18      { Public declarations }
19      procedure CreateParams(var Params:
20        TCreateParams); override;
21    end;
22  
23  var
24    MainForm: TMainForm;
25  
26  implementation
27  
28  {$R *.DFM}
29  
30  uses
31    SubForm;
32  
33  var
34    SubForm: TSubForm;
35  
36  procedure TMainForm.FormCreate(Sender: TObject);
37  begin
38    SetWindowLong(Application.Handle, GWL_EXSTYLE,
39      GetWindowLong(Application.Handle, GWL_EXSTYLE) or
40      WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
41  end;
42  
43  procedure TMainForm.CreateParams(var Params: TCreateParams);
44  begin
45    inherited CreateParams(Params);
46    Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW and not WS_EX_TOOLWINDOW;
47  end;
48  
49  procedure TMainForm.WMSysCommand(var Msg: TMessage);
50  begin
51    DefaultHandler(Msg);
52  end;
53  
54  procedure TMainForm.Button1Click(Sender: TObject);
55  begin
56    SubForm := TSubForm.Create(Application);
57    SubForm.Show;
58  end;
59  
60  end.
61  
62  //SubForm Unit
63  
64  unit SubForm;
65  
66  interface
67  
68  uses
69    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
70  
71  type
72    TSubForm = class(TForm)
73      procedure FormClose(Sender: TObject; var Action: TCloseAction);
74    private
75      { Private declarations }
76    public
77      { Public declarations }
78      procedure CreateParams(var Params: TCreateParams); override;
79    end;
80  
81  implementation
82  
83  {$R *.DFM}
84  
85  procedure TSubForm.CreateParams(var Params: TCreateParams);
86  begin
87    inherited CreateParams(Params);
88    Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
89  end;
90  
91  procedure TSubForm.FormClose(Sender: TObject; var Action: TCloseAction);
92  begin
93    Action := caFree;
94  end;
95  
96  end.



			
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