function GlobalWndProc(id: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;
var
winCtrl: TWinControl;
begin
if msg = WM_NCCREATE then
begin
winCtrl := TWinControl(GetWindowLongPtrA(id, GWLP_USERDATA));
SetWindowLongPtrA(id, GWLP_USERDATA, NativeInt(winCtrl));
winCtrl.FHandle := id;
end else
winCtrl := TWinControl(GetWindowLongPtrA(id, GWLP_USERDATA));
if Assigned(winCtrl) then
Result := winCtrl.HandleMessage (id, Msg, wParam, lParam) else
Result := DefWindowProcA (id, Msg, wParam, lParam) ;
end;
function TWinControl_Create(p: TWinControl): TWinControl; stdcall; export;
var
_msg: TMsg;
cls : TWndClassEx;
wrd : WordBool;
hin : HINSTANCE;
begin
{$ifdef DLLDEBUG}
writeln('TWinControl: Create');
{$endif DLLDEBUG}
if p = nil then
begin
ShowError(sError_TWinControl_ref);
exit(nil);
end;
hin := GetModuleHandleA(nil);
FillChar(cls, sizeof(cls), 0);
cls.cbSize := sizeof(cls); { must be initialized }
if not GetClassInfoEx (hin, 'AppName', @cls) then
begin
with cls do
begin
style := CS_BYTEALIGNCLIENT;
lpfnWndProc := @GlobalWndProc; { window class handler }
cbClsExtra := 0;
cbWndExtra := 0;
hInstance := hin; { qualify instance! }
hIcon := LoadIconA(hin, 'APPICON');
hCursor := LoadCursorA(0, 'idc_arrow');
hbrBackground := GetSysColorBrush(COLOR_WINDOW);
lpszMenuName := 'APPMENU'; { Menu name }
lpszClassName := 'AppName'; { Window Class name }
(*hIconSm := LoadImage(
hin,
APPICON,
IMAGE_ICON,
16,
16,
LR_DEFAULTCOLOR*
);*)
end;
// the line below is always 0 - why ? - not correct cls init
if RegisterClassExA(@cls) = 0 then
begin
ShowError('regois error.');
Halt(255);
end;
end;