Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bring other app window to front without activating it?

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?

like image 738
SathOkh Avatar asked Mar 10 '11 09:03

SathOkh


People also ask

How do I move an app window to the front?

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.

How do I move a window to front Windows 11?

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.


1 Answers

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].

like image 172
Sertac Akyuz Avatar answered Sep 19 '22 18:09

Sertac Akyuz