function ForceForegroundWindow(const hWnd: THandle): Boolean; var hCurWnd: THandle; begin Result := False; if not isWindow(hWnd) then Exit; hCurWnd := GetForegroundWindow; if (hCurWnd = hWnd) then begin Result := True; Exit; end; if (GetWindowLong(hWnd, GWL_STYLE) and WS_MINIMIZE) <> 0 then begin if (GetWindowLong(hWnd, GWL_HWNDPARENT) = 0) and (IsWindowVisible(hWnd) or IsIconic(hWnd)) and // На WinXP появляется доп окно "GDI+ Window" ((GetWindowLong(hWnd, GWL_EXSTYLE) and (WS_EX_WINDOWEDGE or WS_EX_APPWINDOW)) <> 0) then ShowWindow(hWnd, SW_SHOWNOACTIVATE); end; AttachThreadInput(GetWindowThreadProcessId(hCurWnd, nil), GetCurrentThreadId, True); Application_ProcessMessages(); SetForegroundWindow(hWnd); AttachThreadInput(GetWindowThreadProcessId(hCurWnd, nil), GetCurrentThreadId, False); Result := GetForegroundWindow = hWnd; end; |