L
landina
Unregistered / Unconfirmed
GUEST, unregistred user!
我想在自己定义的类中使用线程,在线程中要发送windows消息到类实例中,要如何做?
我是如下定义的,但老是出错,为什么?
TTest=class(TInterfacedObject,ITest)
private:
FHandle: HWND;
procedure CommonThreadProc(var msg: TMessage);
public
constructor Create;
end;
procedure TTest.CommWndProc(var msg: TMessage);
begin
end;
constructor TCamera.Create;
begin
FHandle := Classes.AllocateHWnd(CommWndProc);
end;
线程定义:
unit TriggerEdgeSnapThreadU;
interface
uses
Windows, Classes, IntfCamera, QDialogs;
type
TTestThread = class(TThread)
private
{ Private declarations }
hWinHandle: THandle;
protected
procedure Execute
override;
public
constructor Create(CreateSuspend: Boolean
WindowsHandle: HWND);
end;
implementation
constructor TTestThread.Create(CreateSuspend: Boolean;
WindowsHandle: HWND);
begin
hWinHandle := WindowsHandle;//出错语句
end;
procedure TTestThread.Execute;
begin
while not Terminated do
begin
PostMessage( hWinHandle, WM_SNAPSHOT, 0, 0 ) ;
end;
end;
end.
我是如下定义的,但老是出错,为什么?
TTest=class(TInterfacedObject,ITest)
private:
FHandle: HWND;
procedure CommonThreadProc(var msg: TMessage);
public
constructor Create;
end;
procedure TTest.CommWndProc(var msg: TMessage);
begin
end;
constructor TCamera.Create;
begin
FHandle := Classes.AllocateHWnd(CommWndProc);
end;
线程定义:
unit TriggerEdgeSnapThreadU;
interface
uses
Windows, Classes, IntfCamera, QDialogs;
type
TTestThread = class(TThread)
private
{ Private declarations }
hWinHandle: THandle;
protected
procedure Execute
override;
public
constructor Create(CreateSuspend: Boolean
WindowsHandle: HWND);
end;
implementation
constructor TTestThread.Create(CreateSuspend: Boolean;
WindowsHandle: HWND);
begin
hWinHandle := WindowsHandle;//出错语句
end;
procedure TTestThread.Execute;
begin
while not Terminated do
begin
PostMessage( hWinHandle, WM_SNAPSHOT, 0, 0 ) ;
end;
end;
end.