-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCSWinFn.dpr
60 lines (53 loc) · 1.36 KB
/
CSWinFn.dpr
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
program CSWinFn;
uses
Vcl.Forms,
MainU in 'MainU.pas' {FormMain},
Winapi.Windows;
{$R *.res}
(*
* Written from scratch by :
* Arachmadi Putra (github.com/cimo95)
* https://cimosoft.com
*)
function Singleton(const sInstance: string): Boolean;
var
hMutex: THandle;
begin
hMutex := CreateMutex(nil, False, PChar(sInstance));
if (hMutex <> 0) then
begin
if GetLastError = ERROR_ALREADY_EXISTS then
begin
Result := False;
CloseHandle(hMutex);
end
else
Result := True;
end
else
Result := False;
end;
var
i: integer;
begin
Application.Initialize;
{Making sure only one instance can run, if there's another instance that already run
simulate press CTRL+ALT+SHIFT+F12 to bring up the existed instance and terminate current
new instance. Simulating the key also hide the existed instance if its already shown.}
if Singleton('CobaWinFn') then
begin
Application.MainFormOnTaskbar := True;
Application.CreateForm(TFormMain, FormMain);
Application.HintPause := 0;
Application.HintHidePause := 30000;
Application.Run;
end
else
begin
for i in [VK_CONTROL, VK_MENU, VK_SHIFT, VK_F12] do
keybd_event(i, 0, 0, 0);
for i in [VK_CONTROL, VK_MENU, VK_SHIFT, VK_F12] do
keybd_event(i, 0, 2, 0);
application.Terminate;
end;
end.