Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwitchToThisWindow sends current window to the back

Tags:

windows

winapi

So yes, I find myself in the dubious position of implementing a SwitchToThisWindow call to force my window to the front. I agree, its not ideal, but its not always possible to argue against product "features" that others deem necessary.

Now, I consider SwitchToThisWindow to be a win over the AttachThreadInput hack to do a forced window switch as its less likely to deadlock, and should SwitchToThisWindow be removed, or cease to function I won't complain.

However, SwitchToThisWindow has the unfortunate side effect of pushing the current foreground window to the bottom of the z-order in addition to bringing the target window to the top when FALSE is passed for the fAltTab parameter, and not doing anything if TRUE is passed.

How can I avoid this 'push current active to z-bottom' behavior without resorting to AttachThreadInput?

Alternatively, MS can just remove AttachThreadInput as a viable workaround and I can just tell my manager that the impossible, is in fact, actually, impossible.

like image 818
Chris Becke Avatar asked Feb 02 '11 07:02

Chris Becke


1 Answers

I don't know if this helps, but the only way i found out to bring my window to top reliably is to make the following 2 calls:

ShowWindow(myhwnd, SW_MINIMIZE);
ShowWindow(myhwnd, SW_RESTORE);

Obviously these calls only should be made, when your window currently is not the topmost one in order to avoid flickering. But this also should not have the side effect of bringing the current front window to the bottom of the z order.

like image 104
RED SOFT ADAIR Avatar answered Sep 16 '22 15:09

RED SOFT ADAIR