Se me ocurre una solución, modificamos la unit de roman de esta manera:
Código Delphi
[-]
unit UIApp;
interface
uses
Windows, SysUtils, Forms;
procedure Registrar(sActivar, sMutex: string);
procedure Activar;
implementation
var
mActivar : Cardinal;
Mutex : Cardinal;
PrevWndProc : TFarProc;
function AppWndProc(Handle: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LongInt; stdcall;
var
FgThreadId : DWORD;
AppThreadId : DWORD;
begin
if Msg = mActivar then
begin
if IsIconic(Handle) then
ShowWindow(Handle, SW_RESTORE)
else
begin
FgThreadId := GetWindowThreadProcessId(GetForegroundWindow, nil);
AppThreadId := GetWindowThreadProcessId(Handle, nil);
AttachThreadInput(AppThreadId, FgThreadId, true);
SetForegroundWindow(Handle);
AttachThreadInput(AppThreadId, FgThreadId, false);
end;
Result := 0;
end
else
Result := CallWindowProc(PrevWndProc, Handle, Msg, wParam, lParam);
end;
procedure Activar;
begin
SendMessage(HWND_BROADCAST, mActivar, 0, 0);
end;
procedure Registrar(sActivar, sMutex: string);
begin
mActivar := RegisterWindowMessage(sActivar);
Mutex := CreateMutex(nil, true, sMutex);
if GetLastError = ERROR_ALREADY_EXISTS then
begin
Mutex := 0;
abort;
end
else
begin
PrevWndProc := TFarProc(GetWindowLong(Application.Handle, GWL_WNDPROC));
SetWindowLong(Application.Handle, GWL_WNDPROC, LongWord(@AppWndProc));
end;
end;
initialization
finalization
if Mutex <> 0 then ReleaseMutex(Mutex);
end.
Luego en el dpr de nuestra aplicación, colocamos esto al principio:
Código Delphi
[-]
try
Registrar(sActivar, sMutex); except
Activar;
Halt;
end;
¿que te parece?