function TForm1.SetForegroundWindow98(const Wnd: HWND): Boolean;
var
ForeThreadID, NewThreadID: DWORD;
begin
if GetForegroundWindow <> Wnd then
begin
ForeThreadID := GetWindowThreadProcessId(GetForegroundWindow, nil);
NewThreadID := GetWindowThreadProcessId(Wnd, nil);
if ForeThreadID <> NewThreadID then
begin
AttachThreadInput(ForeThreadID, NewThreadID, True);
Result := SetForegroundWindow(Wnd);
AttachThreadInput(ForeThreadID, NewThreadID, False);
if Result then
Result := SetForegroundWindow(Wnd);
end
else
Result := SetForegroundWindow(Wnd);
end
else
Result := True;
End; |