TThread , TThread , CreateWindow() , . , CreateWindow() TThread Execute(), , :
type
TDataThread = class(TThread)
private
FTitle: String;
FWnd: HWND;
FWndClass: WNDCLASS;
FRegistered: boolean;
class function WindowProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; static;
protected
procedure Execute; override;
procedure DoTerminate; override;
public
constructor Create(const Title:String); reintroduce;
end;
constructor TDataThread.Create(const Title: String);
begin
inherited Create(False);
FTitle := Title;
with FWndClass do
begin
Style := 0;
lpfnWndProc := @WindowProc;
cbClsExtra := 0;
cbWndExtra := 0;
hInstance := HInstance;
hIcon := 0;
hCursor := LoadCursor(0, IDC_ARROW);
hbrBackground := COLOR_WINDOW;
lpszMenuName := nil;
lpszClassName := 'TDataForm';
end;
end;
procedure TDataThread.Execute;
var
Msg: TMsg;
begin
FRegistered := Windows.RegisterClass(FWndClass) <> 0;
if not FRegistered then Exit;
FWnd := CreateWindow(FWndClass.lpszClassName, PChar(FTitle), WS_DLGFRAME, XPos, YPos, 698, 517, 0, 0, HInstance, nil);
if FWnd = 0 then Exit;
while GetMessage(Msg, FWnd, 0, 0) > 0 do
begin
TranslateMessage(msg);
DispatchMessage(msg)
end;
end;
procedure TDataThread.DoTerminate;
begin
if FWnd <> 0 then DestroyWindow(FWnd);
if FRegistered then Windows.UnregisterClass(FWndClass.lpszClassName, HInstance);
inherited;
end;
function TDataThread.WindowProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
Result := 0;
case uMsg of
WM_DATA_AVA:
MessageBox(0, 'Data Available', 'Test', 0);
else
Result := DefWindowProc(hwnd, uMsg, wParam, lParam);
end;
end;