-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClipSave.dpr
More file actions
106 lines (96 loc) · 3.04 KB
/
ClipSave.dpr
File metadata and controls
106 lines (96 loc) · 3.04 KB
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
102
103
104
105
106
program ClipSave;
// $define debug}
uses
Forms,
Windows,
Messages,
SysUtils,
ClipSaveMain in 'ClipSaveMain.pas' {ClipSaveMainForm},
ClipSaveVersion in 'ClipSaveVersion.pas' {VersionDlg},
ClipSaveConfig in 'ClipSaveConfig.pas' {ClipSaveConfigForm},
ClipSaveCreateUDef in 'ClipSaveCreateUDef.pas' {CreateUDefForm},
LIB_ClipSave_UDef in 'LIB_ClipSave_UDef.pas',
Form_Memo in 'Form_Memo.pas' {F_Memo};
{$R *.RES}
var
bufWT : array[0..255] of char; //ウィンドウタイトル用のバッファ
bufCN : array[0..255] of char; //クラス名用のバッファ
bufTMP: array[0..255] of char; //作業用ディレクトリ用のバッファ
FTemp_Path: String;
FCShwnd_File: TextFile;
CShwnd: hwnd;
p:pointer;
const
Mutex_Name = 'ClipSaveMutex';
CRLF = #13#10;
begin
GetTempPath(SizeOf(bufTMP),bufTMP);
FTemp_Path := StrPas(bufTMP);
//clipsave.pidが存在するか確認する
if FileExists(FTemp_Path + '\clipsave.pid') then
begin
//ファイルが存在したらCShwndを取得する
AssignFile(FCShwnd_File,FTemp_Path + '\clipsave.pid');
Reset(FCShwnd_File);
try
Readln(FCShwnd_File,CShwnd);
finally
CloseFile(FCShwnd_File);
end;
//CShwndの情報を取得する
if ((GetWindowText(CShwnd, BufWT, 255) > 0) and //ウィンドウタイトルがあれば
(GetClassName(CShwnd, BufCN, 255) > 0) and //クラス名も取得して
(BufWT = 'ClipSave') and
(BufCN = 'TApplication')) then
Exit
else
begin
//pidファイルが存在するが、不正である場合削除
try
DeleteFile(FTemp_Path + '\clipsave.pid');
except
raise Exception.Create(
'二重起動防止ファイルを削除できません:' +
CRLF +
FTemp_Path + '\clipsave.pid'
);
end;
end;
end;
//二重起動防止のファイルを作成する
AssignFile(FCShwnd_File,FTemp_Path + '\clipsave.pid');
ReWrite(FCShwnd_File);
try
Writeln(FCShwnd_File,Application.Handle);
finally
CloseFile(FCShwnd_File);
end;
try
{ 以下は通常通りの処理を行う }
Application.Initialize;
Application.ShowMainForm := False; // ← 追加
SetWindowLong(Application.Handle,
GWL_EXSTYLE,
GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW
); //←追加
Application.Title := 'ClipSave';
Application.HelpFile := '';
Application.CreateForm(TClipSaveMainForm, ClipSaveMainForm);
Application.CreateForm(TCreateUDefForm, CreateUDefForm);
Application.CreateForm(TF_Memo, F_Memo);
ShowWindow(Application.Handle, SW_HIDE); // ← 追加
Application.Run;
finally
//終了時に二重起動防止ファイルを削除
if (FileExists(FTemp_Path + '\clipsave.pid') = True) then
try
DeleteFile(FTemp_Path + '\clipsave.pid');
except
raise Exception.Create(
'二重起動防止ファイルを削除できません:' +
CRLF +
FTemp_Path + '\clipsave.pid'
);
end;
end;
end.