-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunitwindowobject.pas
More file actions
189 lines (153 loc) · 5.02 KB
/
unitwindowobject.pas
File metadata and controls
189 lines (153 loc) · 5.02 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
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
{ Copyright (C) 2005 Bas Steendijk and Peter Green
For conditions of distribution and use, see copyright notice in zlib_license.txt
which is included in the package
----------------------------------------------------------------------------- }
unit unitwindowobject;
interface
uses
classes,
{$ifdef mswindows}
windows,messages,wmessages,
{$else}
lmessages,
{$macro on}
{$define windows := lmessages}
{$endif}
sysutils,
pgtypes;
type
twindowobjectbase=class(tobject)
hwndmain:hwnd;
onmsg:function(msg,wparam,lparam:taddrint):boolean of object;
exitloopflag:boolean;
exstyle,style:integer;
docreatewindow:boolean;
function windowprocaddr:pointer; virtual;
procedure init_window(dwexstyle,dwstyle:cardinal);
procedure init; virtual;
procedure initinvisible;
function settimer(id,timeout:taddrint):integer;
function killtimer(id:taddrint):boolean;
procedure postmessage(msg,wparam,lparam:taddrint);
procedure messageloop;
{$ifdef mswindows}
procedure processmessages; virtual;
function processmessage:boolean;
{$endif}
constructor create; virtual;
destructor destroy; override;
end;
{this type exists for compatibility with the original one in bewarehttpd,
therefore it inits on create}
twindowobject=class(twindowobjectbase)
constructor create; override;
end;
function WindowProc_windowobjectbase(ahWnd:HWND; auMsg:Integer; awParam:WPARAM; alParam:LPARAM):Integer; stdcall;
var
twindowobject_Class : TWndClass = (style:0; lpfnWndProc:nil;
cbClsExtra:0; cbWndExtra:sizeof(pointer); hInstance:thinstance(0); hIcon:hicon(0); hCursor:hcursor(0);
hbrBackground:hbrush(0);lpszMenuName:nil; lpszClassName:'twindowobject_class');
implementation
//uses safewriteln;
{------------------------------------------------------------------------------}
function WindowProc_windowobjectbase(ahWnd:HWND; auMsg:Integer; awParam:WPARAM; alParam:LPARAM):Integer; stdcall;
var
i:taddrint;
begin
////swriteln('in unitwindowobject.windowproc');
Result := 0; // This means we handled the message
if ahwnd <> hwnd(0) then i := getwindowlongptr(ahwnd,0) else i := 0;
if i <> 0 then begin
if assigned(twindowobjectbase(i).onmsg) then begin
if not twindowobjectbase(i).onmsg(aumsg,awparam,alparam) then i := 0;
end else i := 0
end;
if i = 0 then Result := DefWindowProc(ahWnd, auMsg, awParam, alParam)
end;
function twindowobjectbase.windowprocaddr;
begin
result := @WindowProc_windowobjectbase;
end;
procedure twindowobjectbase.initinvisible;
begin
init_window(WS_EX_TOOLWINDOW,WS_POPUP);
end;
procedure twindowobjectbase.init;
begin
//
end;
function twindowobjectbase.settimer;
begin
result := windows.settimer(hwndmain,id,timeout,nil);
end;
function twindowobjectbase.killtimer;
begin
result := windows.killtimer(hwndmain,id);
end;
procedure twindowobjectbase.init_window;
begin
//swriteln('in twindowobject.create, about to call registerclass');
twindowobject_Class.lpfnWndProc := windowprocaddr;
Windows.RegisterClass(twindowobject_Class);
//swriteln('about to call createwindowex');
style := dwstyle;
exstyle := dwexstyle;
hWndMain := CreateWindowEx(dwexstyle, twindowobject_Class.lpszClassName,
'', dwstyle, CW_USEDEFAULT, CW_USEDEFAULT,100, 100, hwnd(0), 0, HInstance, nil);
//swriteln('about to check result of createwindowex');
if hWndMain = hwnd(0) then raise exception.create('CreateWindowEx failed');
//swriteln('about to store reference to self in extra window memory');
setwindowlongptr(hwndmain,0,taddrint(self));
//swriteln('finished twindowobject.create , hwndmain='+inttohex(taddrint(hwndmain),16));
end;
constructor twindowobjectbase.create;
begin
inherited;
end;
destructor twindowobjectbase.destroy;
begin
if hWndMain <> hwnd(0) then DestroyWindow(hwndmain);
inherited;
end;
procedure twindowobjectbase.postmessage;
begin
windows.postmessage(hwndmain,msg,wparam,lparam);
end;
{$ifdef mswindows}
function twindowobjectbase.ProcessMessage : Boolean;
var
MsgRec : TMsg;
begin
Result := FALSE;
if PeekMessage(MsgRec, 0, 0, 0, PM_REMOVE) then begin
Result := TRUE;
TranslateMessage(MsgRec);
DispatchMessage(MsgRec);
end;
end;
procedure twindowobjectbase.processmessages;
begin
while processmessage do;
end;
{$endif}
procedure twindowobjectbase.messageloop;
var
MsgRec : TMsg;
begin
while GetMessage(MsgRec, hwnd(0), 0, 0) do begin
{$ifdef mswindows}
TranslateMessage(MsgRec);
{$endif}
DispatchMessage(MsgRec);
if exitloopflag then exit;
{if not peekmessage(msgrec,0,0,0,PM_NOREMOVE) then onidle}
end;
end;
{------------------------------------------------------------------------------}
constructor twindowobject.create;
begin
inherited;
initinvisible;
end;
{------------------------------------------------------------------------------}
end.