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
|
{
Proof of concept test app for multi-handle GUI widgets.
Graeme Geldenhuys
}
program test;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
,gui2Base
,gfxbase
,fpgfx
;
type
{ TMainWindow }
TMainWindow = class(TForm)
procedure btnCancelClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure btnPopupClick(Sender: TObject);
private
btnClose: TButton;
btnCancel: TButton;
btnPopup: TButton;
lblWelcome: TLabel;
edEdit: TEdit;
public
constructor Create; override;
destructor Destroy; override;
end;
TMyPopup = class(TPopupWindow)
public
constructor Create; override;
end;
const
clBlue: TGfxColor = (Red: $0000; Green: $0000; Blue: $FF00; Alpha: 0);
clLightSteelBlue: TGfxColor = (Red: $B000; Green: $C400; Blue: $DE00; Alpha: 0);
{ TMyPopup }
constructor TMyPopup.Create;
begin
inherited Create;
Title := 'My Popup';
SetClientSize(Size(180, 320));
end;
{ TMainWindow }
procedure TMainWindow.btnCancelClick(Sender: TObject);
begin
Writeln('You click Cancel');
end;
procedure TMainWindow.btnCloseClick(Sender: TObject);
begin
Writeln('You click Close');
GFApplication.Quit;
end;
procedure TMainWindow.btnPopupClick(Sender: TObject);
var
frm: TMyPopup;
begin
frm := TMyPopup.Create;
GFApplication.AddWindow(frm);
// frm.SetPosition(Point(0, btnPopup.Height));
frm.Show;
end;
constructor TMainWindow.Create;
begin
inherited Create;
Title := 'fpGUI multi-handle example';
SetClientSize(Size(320, 200));
Color := clLightSteelBlue;
btnClose := TButton.Create(self, Point(20, 150));
btnClose.Caption := 'Close';
btnClose.OnClick := @btnCloseClick;
btnCancel := TButton.Create(self, Point(150, 150));
btnCancel.Caption := 'Cancel';
btnCancel.OnClick := @btnCancelClick;
btnPopup := TButton.Create(self, Point(80, 80));
btnPopup.Caption := 'Popup';
btnPopup.OnClick := @btnPopupClick;
lblWelcome := TLabel.Create(self, Point(10, 10));
lblWelcome.Caption := 'So what do you think?';
edEdit := TEdit.Create(self, Point(65, 110));
edEdit.Text := 'Multi-Handle widgets';
end;
destructor TMainWindow.Destroy;
begin
btnClose.Free;
btnCancel.Free;
btnPopup.Free;
lblWelcome.Free;
inherited Destroy;
end;
var
MainWindow: TMainWindow;
begin
GFApplication.Initialize;
MainWindow := TMainWindow.Create;
GFApplication.AddWindow(MainWindow);
MainWindow.Show;
GFApplication.Run;
MainWindow.Free;
end.
|