-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfrmMain.pas
243 lines (212 loc) · 5.45 KB
/
frmMain.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
unit frmMain;
{$MODE Delphi}
interface
uses
Windows, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Spin, ComCtrls, Buttons;
type
{ TMainForm }
TMainForm = class(TForm)
DelayTime: TSpinEdit;
lblDelayTime: TLabel;
Label1: TLabel;
SaveDialog1: TSaveDialog;
PageControl1: TPageControl;
InformationSheet: TTabSheet;
DelphiFormSheet: TTabSheet;
Information: TButton;
WndValue: TEdit;
Label3: TLabel;
PasFileName: TEdit;
BrowsePas: TButton;
Label4: TLabel;
FormName: TEdit;
SavePas: TButton;
lblWndValue: TLabel;
optAutomatic: TRadioButton;
optManual: TRadioButton;
RCSheet: TTabSheet;
Label2: TLabel;
RCFileName: TEdit;
BrowseRC: TButton;
SaveRC: TButton;
btnAbout: TBitBtn;
procedure InformationClick(Sender: TObject);
procedure BrowsePasClick(Sender: TObject);
procedure BrowseRCClick(Sender: TObject);
procedure SavePasClick(Sender: TObject);
procedure PasEditChange(Sender: TObject);
procedure optManualClick(Sender: TObject);
procedure optAutomaticClick(Sender: TObject);
procedure RCFileNameChange(Sender: TObject);
procedure btnAboutClick(Sender: TObject);
procedure SaveRCClick(Sender: TObject);
private
procedure GenerateDfmFile(const filename, frmname: String; wnd: HWND;
PasList: TStrings);
procedure GeneratePasFile(const filename, frmname: String; PasList: TStrings);
procedure EnableSavePas;
procedure EnableWndInput;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
uses frmResults, Writers, DfmEngine, about1;
{$R *.lfm}
procedure TMainForm.InformationClick(Sender: TObject);
var
wnd: HWND;
begin
if optAutomatic.Checked then
begin
Application.Minimize;
Sleep(DelayTime.Value);
wnd := GetForegroundWindow;
Application.Restore;
end
else
wnd := StrToInt(WndValue.Text);
Results.Show;
Results.TreeView1.Items.Clear;
Results.GetWinInfo(wnd, nil);
end;
procedure TMainForm.BrowsePasClick(Sender: TObject);
var
s: String;
begin
with SaveDialog1 do
begin
FileName := '';
DefaultExt := 'pas';
Filter := 'Delphi Units|*.pas';
if Execute then
begin
PasFileName.Text := FileName;
s := ChangeFileExt(ExtractFileName(FileName), '');
if LowerCase(Copy(s, 1, 3)) = 'frm' then
s := Copy(s, 4, Length(s) - 3) + 'Form'
else
s := s + 'Form';
FormName.Text := s;
end;
end;
end;
procedure TMainForm.BrowseRCClick(Sender: TObject);
begin
with SaveDialog1 do
begin
FileName := '';
DefaultExt := 'rc';
Filter := 'Resource scripts|*.rc';
// if Execute then RCFileName.Text := FileName;
end;
end;
procedure TMainForm.GenerateDfmFile(const filename, frmName: String;
wnd: HWND; PasList: TStrings);
var
OutStream: TFileStream;
b1: TDfmBuilder;
begin
b1 := TDfmBuilder.Create(PasList);
OutStream := TFileStream.Create(filename, fmCreate);
b1.Build(OutStream, frmName, wnd);
OutStream.Free;
b1.Free;
end;
procedure TMainForm.GeneratePasFile(const filename, frmname: String; PasList: TStrings);
var
title: String;
fpas: TTextWriter;
i: Integer;
begin
fpas := TTextWriter.CreateFile(filename);
try
title := ChangeFileExt(ExtractFileName(filename), '');
with fpas do
begin
WriteLn('unit ' + title + ';');
WriteLn('');
WriteLn('interface');
WriteLn('');
WriteLn('uses');
WriteLn(' Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,');
WriteLn(' StdCtrls;');
WriteLn('');
WriteLn('type');
WriteLn(' T' + frmname + ' = class(TForm)');
for i := 0 to PasList.Count - 1 do
WriteLn(' ' + PasList[i]);
WriteLn(' private');
WriteLn(' { Private declarations }');
WriteLn(' public');
WriteLn(' { Public declarations }');
WriteLn(' end;');
WriteLn('');
WriteLn('var');
WriteLn(' ' + frmname + ': T' + frmname + ';');
WriteLn('');
WriteLn('implementation');
WriteLn('');
WriteLn('{$R *.DFM}');
WriteLn('');
WriteLn('end.');
end;
finally
fpas.Free;
end;
end;
procedure TMainForm.SavePasClick(Sender: TObject);
var
dfmName: String;
wnd: HWND;
s: TStringList;
begin
Application.Minimize;
Sleep(DelayTime.Value);
wnd := GetForegroundWindow;
Application.Restore;
dfmName := ChangeFileExt(PasFileName.Text, '.dfm');
s := TStringList.Create;
GenerateDfmFile(dfmName, FormName.Text, wnd, s);
GeneratePasFile(PasFileName.Text, FormName.Text, s);
s.Free;
end;
procedure TMainForm.EnableSavePas;
var
UnitName: String;
begin
UnitName := ChangeFileExt(ExtractFileName(PasFileName.Text), '');
SavePas.Enabled := IsValidIdent(FormName.Text) and IsValidIdent(UnitName) and
(CompareText(UnitName, FormName.Text) <> 0);
end;
procedure TMainForm.PasEditChange(Sender: TObject);
begin
EnableSavePas;
end;
procedure TMainForm.EnableWndInput;
begin
WndValue.Enabled := optManual.Checked;
lblWndValue.Enabled := optManual.Checked;
end;
procedure TMainForm.optManualClick(Sender: TObject);
begin
EnableWndInput;
end;
procedure TMainForm.optAutomaticClick(Sender: TObject);
begin
EnableWndInput;
end;
procedure TMainForm.RCFileNameChange(Sender: TObject);
begin
SaveRC.Enabled := False;
end;
procedure TMainForm.btnAboutClick(Sender: TObject);
begin
AboutBox.ShowModal;
end;
procedure TMainForm.SaveRCClick(Sender: TObject);
begin
end;
end.