source: OniWindowMover/Unit1.pas @ 257

Last change on this file since 257 was 257, checked in by alloc, 12 years ago
File size: 3.3 KB
Line 
1UNIT Unit1;
2INTERFACE
3USES
4  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5  Dialogs, StdCtrls, CrossEdit, Math, ExtCtrls;
6
7TYPE
8  TForm1 = Class(TForm)
9    grp_center: TGroupBox;
10    group_setxy: TGroupBox;
11    btn_center: TButton;
12    edit_x: TCrossEdit;
13    edit_y: TCrossEdit;
14    btn_setxy: TButton;
15    group_black: TGroupBox;
16    btn_black: TButton;
17    timer_check: TTimer;
18    PROCEDURE timer_checkTimer(Sender: TObject);
19    PROCEDURE btn_blackClick(Sender: TObject);
20    PROCEDURE btn_setxyClick(Sender: TObject);
21    PROCEDURE FormCreate(Sender: TObject);
22    PROCEDURE btn_centerClick(Sender: TObject);
23    PROCEDURE Button1Click(Sender: TObject);
24  PRIVATE
25  PUBLIC
26  END;
27
28VAR
29  Form1: TForm1;
30
31IMPLEMENTATION
32USES Unit2;
33{$R *.dfm}
34VAR
35  ONIHandle:LongWord;
36
37PROCEDURE TForm1.Button1Click(Sender: TObject);
38  BEGIN
39    ONIHandle:=FindWindow(PChar('ONI '),PChar('ONI '));
40    Form1.Caption:=IntToStr(ONIHandle);
41  END;
42
43PROCEDURE TForm1.btn_centerClick(Sender: TObject);
44  VAR
45    Handle,NewX,NewY:LongWord;
46    Screen,Cur:TRect;
47    ScreenWidth,ScreenHeight,Width,Height:LongWord;
48  BEGIN
49    Handle:=FindWindow(PChar('ONI '),PChar('ONI '));
50    IF Handle>0 THEN BEGIN
51      GetWindowRect(Handle,Cur);
52      GetWindowRect(GetDesktopWindow,Screen);
53      ScreenWidth:=Screen.Right-Screen.Left;
54      ScreenHeight:=Screen.Bottom-Screen.Top;
55      Width:=Cur.Right-Cur.Left;
56      Height:=Cur.Bottom-Cur.Top;
57      IF (Width<ScreenWidth) AND (Height<ScreenHeight) THEN BEGIN
58        NewX:=(ScreenWidth DIV 2)-(Width DIV 2);
59        NewY:=(ScreenHeight DIV 2)-(Height DIV 2);
60        IF NOT SetWindowPos(Handle,0,NewX,NewY,0,0,SWP_NOSIZE OR SWP_NOACTIVATE OR SWP_NOZORDER) THEN
61          ShowMessage('Couldn''t set the position of ONIs window!');
62      END ELSE ShowMessage('ONIs window is at fullscreen!');
63    END ELSE ShowMessage('Couldn''t find ONIs window!');
64  END;
65
66PROCEDURE TForm1.FormCreate(Sender: TObject);
67  VAR
68    Screen:TRect;
69  BEGIN
70    GetWindowRect(GetDesktopWindow,Screen);
71    edit_x.Max:=Screen.Right;
72    edit_y.Max:=Screen.Bottom;
73    edit_x.BorderStyle:=bsSingle;
74    edit_y.BorderStyle:=bsSingle;
75  END;
76
77PROCEDURE TForm1.btn_setxyClick(Sender: TObject);
78  VAR
79    Handle:LongWord;
80  BEGIN
81    IF edit_x.CheckError THEN BEGIN
82      ShowMessage('x-value has to be between 0 and '+IntToStr(Floor(edit_x.Max))+'!');
83      Exit;
84    END;
85    IF edit_y.CheckError THEN BEGIN
86      ShowMessage('y-value has to be between 0 and '+IntToStr(Floor(edit_y.Max))+'!');
87      Exit;
88    END;
89    Handle:=FindWindow(PChar('ONI '),PChar('ONI '));
90    IF Handle>0 THEN BEGIN
91      IF NOT SetWindowPos(Handle,0,edit_x.GetInteger,edit_y.GetInteger,0,0,SWP_NOSIZE OR SWP_NOACTIVATE OR SWP_NOZORDER) THEN
92        ShowMessage('Couldn''t set the position of ONIs window!');
93    END ELSE ShowMessage('Couldn''t find ONIs window!');
94  END;
95
96PROCEDURE TForm1.btn_blackClick(Sender: TObject);
97  BEGIN
98    IF FindWindow(PChar('ONI '),PChar('ONI '))>0 THEN BEGIN
99      Form2.Visible:=NOT Form2.Visible;
100      SetForeGroundWindow(FindWindow(PChar('ONI '),PChar('ONI ')));
101    END;
102  END;
103
104PROCEDURE TForm1.timer_checkTimer(Sender: TObject);
105  BEGIN
106    IF Form2.Visible THEN BEGIN
107      IF FindWindow(PChar('ONI '),PChar('ONI '))=0 THEN Form2.Visible:=False;
108    END;
109  END;
110
111END.
Note: See TracBrowser for help on using the repository browser.