So hab die Lösung:
Man muss natürlich erstmal ein eigenen Message Handler machen
Hier mal meine Lösung:
Die Klasse:
Delphi-Quellcode:
TrrRegistryAutoUpdater = class(TThread)
private
FSignalShutdown : Boolean;
FWinHandle : HWND;
FWaitMessage : Cardinal;
FOnMessage : TNotifyEvent;
procedure DeallocateHWnd(Wnd: HWND);
published
property OnMessage: TNotifyEvent read FOnMessage write FOnMessage;
protected
procedure Execute; override;
procedure WndProc(var msg: TMessage);
public
constructor Create(Msg: Cardinal);
destructor Destroy; override;
end;
Der Code zur Klasse:
Delphi-Quellcode:
//------------------------------------------------------------------------------
// Regist
constructor TrrRegistryAutoUpdater.Create(Msg: Cardinal);
begin
FSignalShutdown := False;
FWinHandle := AllocateHWND(WndProc);
FreeOnTerminate := TRUE;
FWaitMessage := Msg;
inherited Create(TRUE);
end;
destructor TrrRegistryAutoUpdater.Destroy;
begin
inherited;
end;
procedure TrrRegistryAutoUpdater.WndProc(var msg: TMessage);
begin
if Msg.Msg = FWaitMessage then begin
if Assigned(FOnMessage) then FOnMessage(Self);
end else
Msg.Result := DefWindowProc(FWinHandle, Msg.Msg, Msg.wParam, Msg.lParam);
end;
procedure TrrRegistryAutoUpdater.Execute;
begin
while not Terminated do begin
Sleep(10);
end;
DeallocateHWnd(FWinHandle);
end;
procedure TrrRegistryAutoUpdater.DeallocateHWnd(Wnd: HWND);
var Instance: Pointer;
begin
Instance := Pointer(GetWindowLong(Wnd, GWL_WNDPROC));
if Instance <> @DefWindowProc then begin
SetWindowLong(Wnd, GWL_WNDPROC, Longint(@DefWindowProc));
FreeObjectInstance(Instance);
end;
DestroyWindow(Wnd);
end;
procedure TrrRegistryAutoUpdater.Shutdown;
begin
Terminate;
end;
Jetzt noch die Message registrieren:
Delphi-Quellcode:
initialization
WM_RRPC_UPDATEREGISTRY := RegisterWindowMessage('RRPCUpdateRegistry');
Vielleicht hilft es ja einem weiter
Gruss Andi