-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainFormU.pas
102 lines (83 loc) · 2.5 KB
/
MainFormU.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
unit MainFormU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, SettingsR, StdCtrls;
type
TForm1 = class(TForm)
btnEnter: TBitBtn;
btnExit: TBitBtn;
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnEnterClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnExitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
SelectU;
var
OldWindowProc : Pointer; {Variable for the old windows proc}
MyMsg : DWord; {custom systemwide message}
function NewWindowProc(WindowHandle : hWnd;
TheMessage : LongInt;
ParamW : LongInt;
ParamL : LongInt) : LongInt stdcall;
begin
if TheMessage = MyMsg then begin
{Tell the application to restore, let it restore the form}
SendMessage(Application.handle, WM_SYSCOMMAND, SC_RESTORE, 0);
SetForegroundWindow(Application.Handle);
{We handled the message - we are done}
Result := 0;
exit;
end;
{Call the original winproc}
Result := CallWindowProc(OldWindowProc,
WindowHandle,
TheMessage,
ParamW,
ParamL);
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
SelectForm.ShowSelectTabs := [stDatabase, stInsertFiles];
SelectForm.InitializeForm;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{Register a custom windows message}
MyMsg := RegisterWindowMessage('S19Database');
{Set form1's windows proc to ours and remember the old window proc}
OldWindowProc := Pointer(SetWindowLong(Form1.Handle,
GWL_WNDPROC,
LongInt(@NewWindowProc)));
LoadSettings;
end;
procedure TForm1.btnEnterClick(Sender: TObject);
begin
SelectForm.ShowModal;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{Set form1's window proc back to it's original procedure}
SetWindowLong(Form1.Handle,
GWL_WNDPROC,
LongInt(OldWindowProc));
end;
procedure TForm1.btnExitClick(Sender: TObject);
begin
Application.Terminate;
end;
begin
{Tell Delphi to hide it's hidden application window for now to avoid}
{a "flash" on the taskbar if we halt due to another instance}
ShowWindow(Application.Handle, SW_HIDE);
end.