Real SetForegroundWindow()
Posted: Wed Sep 03, 2003 9:05 am
Code updated For 5.20+
Here is a snippet I need for my work, to really put a window in the foreground, instead of flashing taskbar for Win98/2000 or XP. Warning, use it with care and only when needed, as it's not very smart to grab the user input without notice
Here is a snippet I need for my work, to really put a window in the foreground, instead of flashing taskbar for Win98/2000 or XP. Warning, use it with care and only when needed, as it's not very smart to grab the user input without notice
Code: Select all
; Code by Elvis Rox erox@etree.com
Procedure ReallySetForegroundWindow(Window)
hWnd = WindowID(Window)
; If the window is in a minimized state, maximize now
If GetWindowLong_(hWnd, #GWL_STYLE) & #WS_MINIMIZE
ShowWindow_(hWnd, #SW_MAXIMIZE)
UpdateWindow_(hWnd)
EndIf
; Check To see If we are the foreground thread
foregroundThreadID = GetWindowThreadProcessId_(GetForegroundWindow_(), 0)
ourThreadID = GetCurrentThreadId_()
; If not, attach our thread's 'input' to the foreground thread's
If (foregroundThreadID <> ourThreadID)
AttachThreadInput_(foregroundThreadID, ourThreadID, #TRUE);
EndIf
; Bring our window To the foreground
SetForegroundWindow_(hWnd)
; If we attached our thread, detach it now
If (foregroundThreadID <> ourThreadID)
AttachThreadInput_(foregroundThreadID, ourThreadID, #FALSE)
EndIf
; Force our window To redraw
InvalidateRect_(hWnd, #NULL, #TRUE)
EndProcedure