由于经常要用到窗体全屏功能 所以把他封装成了一个组件 这是主要代码
1 {*******************************************************}
2 { }
3 { TFullScreen }
4 { Ver 0.1.1 }
5 { Copyright(C) 2006-2007 Unruly Wolf Soft }
6 { }
7 {*******************************************************}
8
9 unit FullScreen;
10
11 interface
12
13 uses
14 SysUtils, Classes,Forms,Windows;
15
16 type
17 TFullScreen = class(TComponent)
18 private
19 { Private declarations }
20 FFullScreenMode : Boolean;
21 FForm : TCustomForm;
22 OldState,OldHeight,OldWidth,OldX,OldY:Longint;
23 FOldState:TWindowState;
24 FBeforeFullScreen:TNotifyEvent ;
25 FAfterModeChanged:TNotifyEvent ;
26 FAfterFullScreen:TNotifyEvent ;
27 FExitFullScreen:TNotifyEvent ;
28 Procedure SetFullScreenMode(aVal:Boolean);
29 protected
30 { Protected declarations }
31 public
32 { Public declarations }
33 property FullScreen : Boolean read FFullScreenMode write SetFullScreenMode;
34 property FormMain : TCustomForm read FForm write FForm;
35 procedure SaveOldWinState;
36 published
37 { Published declarations }
38 property BeforeFullScreen : TNotifyEvent read FBeforeFullScreen write FBeforeFullScreen;
39 property AfterModeChanged : TNotifyEvent read FAfterModeChanged write FAfterModeChanged;
40 property AfterFullScreen : TNotifyEvent read FAfterFullScreen write FAfterFullScreen;
41 property ExitFullScreen : TNotifyEvent read FExitFullScreen write FExitFullScreen;
42 end;
43
44 procedure Register;
45
46 implementation
47
48
49 //Save form state
50 procedure TFullScreen.SaveOldWinState ;
51 begin
52 if FForm<>nil then
53 FOldState:=FForm.WindowState ;
54 end;
55
56 procedure TFullScreen.SetFullScreenMode(aVal:Boolean);
57 begin
58 if aVal<>FFullScreenMode then
59 begin
60 FFullScreenMode:=aVal;
61 if FFullScreenMode then
62 //enter fullscreen
63 begin
64 OldState:=GetWindowLong(FForm.Handle, GWL_STYLE);
65 OldHeight:=FForm.Height;
66 OldWidth:=FForm.Width;
67 OldX:=FForm.Left ;
68 OldY:=FForm.Top;
69 SaveOldWinState;
70 if Assigned(FBeforeFullScreen) then FBeforeFullScreen(Self);
71 FForm.Left:=0;
72 FForm.Top:=0;
73 FForm.windowstate:=wsmaximized;
74 SetWindowLong(FForm.Handle, GWL_STYLE,
75 GetWindowLong(FForm.Handle, GWL_STYLE) AND NOT WS_CAPTION);
76 //FForm.windowstate:=wsmaximized;
77 FForm.clientHeight:=screen.Height;
78 FForm.Refresh;
79 if Assigned(FAfterFullScreen) then FAfterFullScreen(Self);
80 end
81 else
82 // Exit full screen
83 begin
84 SetWindowLong(FForm.Handle, GWL_STYLE, OldState);
85 FForm.Height:=OldHeight;
86 FForm.Width:=OldWidth;
87 FForm.Left:=OldX;
88 FForm.Top:=OldY;
89 FForm.Windowstate:=FOldState;
90 FForm.Refresh;
91 if Assigned(FExitFullScreen) then FExitFullScreen(Self);
92 end;
93 end;
94 if Assigned(FAfterModeChanged) then FAfterModeChanged(Self);
95 end;
96
97 procedure Register;
98 begin
99 RegisterComponents('UWS Used', [TFullScreen]);
100 end;
101
102 end.
103