procedure TFrmMain.ActiveApplication;
var
nForeThread, nAppThread: DWORD;
lnHWND: HWND;
begin
lnHWND := GetForegroundWindow();
nForeThread := GetWindowThreadProcessId(lnHWND, nil);
nAppThread := GetCurrentThreadId();
var
nForeThread, nAppThread: DWORD;
lnHWND: HWND;
begin
lnHWND := GetForegroundWindow();
nForeThread := GetWindowThreadProcessId(lnHWND, nil);
nAppThread := GetCurrentThreadId();
lnHWND := Application.Handle;
if nForeThread <> nAppThread then
begin
AttachThreadInput(nForeThread, nAppThread, true);
BringWindowToTop(lnHWND);
ShowWindow(lnHWND,SW_SHOW);
AttachThreadInput(nForeThread, nAppThread, false);
end
else
begin
BringWindowToTop(lnHWND);
ShowWindow(lnHWND, SW_SHOW);
end;
end;
begin
AttachThreadInput(nForeThread, nAppThread, true);
BringWindowToTop(lnHWND);
ShowWindow(lnHWND,SW_SHOW);
AttachThreadInput(nForeThread, nAppThread, false);
end
else
begin
BringWindowToTop(lnHWND);
ShowWindow(lnHWND, SW_SHOW);
end;
end;