Vote count:
0
I am trying to do Inter-Thread Communication however with message loop in the thread the background worker cannot process other work such as execute various algorithms. Is it possible to process messages while the thread is executing other work?
I've used this snippet:
procedure TMyThread.Execute;
var
Message: TMsg;
begin
FWnd := AllocateHWnd(WndProc);
try
while not Terminated do
begin
if MsgWaitForMultipleObjects(0, nil^, False, 1000, QS_ALLINPUT) = WAIT_OBJECT_0 then
begin
while PeekMessage(Message, 0, 0, 0, PM_REMOVE) do
begin
TranslateMessage(Message);
DispatchMessage(Message);
end;
end;
end;
finally
DeallocateHWnd(FWnd);
end;
end;
procedure TMyThread.WndProc(var Message: TMessage);
begin
if Message.Msg = WM_COPYDATA then
begin
...
Message.Result := ...;
end else
Message.Result := DefWindowProc(FWnd, Message.Msg, Message.WParam, Message.LParam);
end;
asked 48 secs ago
Aucun commentaire:
Enregistrer un commentaire