给线程发送消息让它执行不同的处理(自己建立消息循环,非常有意思) good

unit Unit2;

interface

uses
System.Classes, Windows, Messages;

const
WM_DO = WM_USER + 1;

type
TDemoThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;

implementation

{ TDemoThread }

procedure TDemoThread.Execute;
var
Msg: TMsg;
begin
{ Place thread code here }
while GetMessage(Msg, 0, 0, 0) do
begin
case Msg.message of
WM_DO:
; // do it
WM_CLOSE:
Break;
end;
Sleep(100);
end;

end;

http://www.cnblogs.com/hnxxcxg/p/4259407.html

具体使用:PostThreadMessage
https://msdn.microsoft.com/en-us/library/windows/desktop/ms644946(v=vs.85).aspx

原文地址:https://www.cnblogs.com/findumars/p/5236995.html