Author: Lou Adler
I'd like to resize a form and have it fill up the screen. But I don't want it to
display over the Win95/WinNT taskbar. Is there a way to do this?
Answer:
I put the code in a component wrapper so all you have to do is drop the component
onto any form, call the component's execute procedure in FormCreate, and voila! an
instantly sized form that fits nicely within your screen, above the Taskbar.
For Non-Windows 95 users, your form will be sized to maximized, but will be still
be FormStyle := wsNormal. Select the text below, put it in a file, save the file as
SizeTask.pas, add into your component library, drop it into a form, and watch it go!
1 unit Sizetask;
2
3 interface
4
5 uses
6 SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
7 Forms, Dialogs;
8
9 type
10 TSizer = class(TComponent)
11 private
12 { Private declarations }
13 protected
14 { Protected declarations }
15 procedure SetSize(MyForm: TForm);
16 public
17 { Public declarations }
18 procedure Execute;
19 end;
20
21 procedure register;
22
23 implementation
24
25 procedure TSizer.Execute;
26 begin
27 SetSize(TForm(Owner));
28 end;
29
30 procedure TSizer.SetSize(MyForm: TForm);
31 var
32 TaskBarHandle: HWnd; { Handle to the Win95 Taskbar }
33 TaskBarCoord: TRect; { Coordinates of the Win95 Taskbar }
34 CxScreen, { Width of screen in pixels }
35 CyScreen, { Height of screen in pixels }
36 CxFullScreen, { Width of client area in pixels }
37 CyFullScreen, { Height of client area in pixels }
38 CyCaption: Integer; { Height of a window's title bar in pixels }
39 begin
40 TaskBarHandle := FindWindow('Shell_TrayWnd', nil); { Get Win95 Taskbar handle }
41 if TaskBarHandle = 0 then { We're running Win 3.x or WinNT w/o Win95
42 shell, so just maximize }
43 MyForm.WindowState := wsMaximized
44 else { We're running Win95 or WinNT w/Win95 shell }
45 begin
46 MyForm.WindowState := wsNormal;
47 GetWindowRect(TaskBarHandle, TaskBarCoord); { Get coordinates of Win95 Taskbar }
48 CxScreen := GetSystemMetrics(SM_CXSCREEN);
49 { Get various screen dimensions and set form's width/height }
50 CyScreen := GetSystemMetrics(SM_CYSCREEN);
51 CxFullScreen := GetSystemMetrics(SM_CXFULLSCREEN);
52 CyFullScreen := GetSystemMetrics(SM_CYFULLSCREEN);
53 CyCaption := GetSystemMetrics(SM_CYCAPTION);
54 MyForm.Width := CxScreen - (CxScreen - CxFullScreen) + 1;
55 MyForm.Height := CyScreen - (CyScreen - CyFullScreen) + CyCaption + 1;
56 MyForm.Top := 0;
57 MyForm.Left := 0;
58 if (TaskBarCoord.Top = -2) and (TaskBarCoord.Left = -2) then
59 {Taskbar on either top or left }
60 if TaskBarCoord.Right > TaskBarCoord.Bottom then { Taskbar on top }
61 MyForm.Top := TaskBarCoord.Bottom
62 else { Taskbar on left }
63 MyForm.Left := TaskBarCoord.Right;
64 end;
65 end;
66
67 procedure register;
68 begin
69 RegisterComponents('Samples', [TSizer]);
70 end;
71
72 end.
|