Ich versuche gerade noch das ganze über eine Callback zu machen.
Hab aber so meine Probleme damit!
DummyApp:
Delphi-Quellcode:
type
TPowerMessageCallback = procedure (WParam:Cardinal);
procedure TSendMessageThread.Execute;
var
PowerMessageCallback : TPowerMessageCallback;
begin
@PowerMessageCallback := fcb;
PowerMessageCallback(fWParam);
Terminate;
end;
constructor TSendMessageThread.Create(cb : Pointer; WParam: Cardinal);
begin
inherited Create(True);
fWParam := WParam;
fcb := cb;
Resume;
end;
Wird so aufgerufen:
Delphi-Quellcode:
TSendMessageThread.Create(Clients[i],4);
//wobei:
Clients: Array of Pointer;
Der Client schickt per Sendmessage seinen Callbackpointer:
Delphi-Quellcode:
TMyClass =
class(TComponent)
public
constructor Create(AOwner: TComponent);
override;
{ create hidden window here: store handle in fHWnd}
destructor Destroy;
override;
{ free hidden window here }
procedure PowerMessageCallback(WParam:Cardinal);
end;
SendMessage(FindWindow('
TFormTestApp',
nil),ClientRegister,Int64(@TMyClass.PowerMessageCallback),0);
procedure TMyClass.PowerMessageCallback(WParam:Cardinal);
begin
//do wcallback work
end;
die so bei der DummyApp empfangen und gespeichert wird:
Clients[High(Clients)] := Pointer(MyMessage.WParam);