I want to bring to front a window(from other application). Currently I'm using:
::SetWindowPos(hwnd, GetForegroundWindow(), 0, 0, 0, 0, SWP_ASYNCWINDOWPOS | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
It works fine, but in some (unknown to me) cases, it makes the window always on top. According to MSDN, I should use HWND_NOTOPMOST
in the place of GetForegroundWindow()
but it doesn't work—the window stays under other (not always on top) windows.
How can I bring a window to the front without activating it?
Hold down the Shift key, then right-click on the appropriate application icon in the Windows taskbar. On the resulting pop-up, select the Move option.
1. Open Control Panel > Vew mode: Big icon > Select Ease of Access Center > Click Make the mouse easier to use > Uncheck Activate a windows by hovering over it witth the mouse under Make it easier to manage Windows option. 2.
The other application's window can be made temporarily 'top-most' to bring it to front without activating it, first by specifying HWND_TOPMOST
as 'hWndInsertAfter' in a SetWindowPos
call and then by specifying HWND_NOTOPMOST
in a second call (both calls with SWP_NOACTIVATE
in 'uFlags'). If there's a risk of removing the top-most style of a window which is already top-most as a consequence of the operation, the WS_EX_TOPMOST
ex-style can be tested beforehand with a call to GetWindowLong[Ptr]
.
If there's a particular window that the other application's window need to be in front (as opposed to being in front of all windows), that window's owner can be set, again temporarily, to the window it needs to be in front. GetWindowLong[Ptr]
with GWL_HWNDPARENT
can be used to store the window's original owner, then a call to SetWindowLong[Ptr]
to set the temporary owner, followed by a call to SetWindowPos
with HWND_TOP
, and then restoring the original owner with again SetWindowLong[Ptr]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With