question

HemantSalwan-7883 avatar image
0 Votes"
HemantSalwan-7883 asked RLWA32-6355 commented

How to use LockSetForegroundWindow API in Win32 application

I have written two applications A and B (both Win32 apps) running on Windows 8.1. Application A has message box pop up at many places with the Topmost flag. In application B, i want to prevent application A dialog boxes to come in front of it while running. I figured out that there is LockSetForegroundWindow API which can disable other processes to set their windows in the foreground. But it does not seems to work in my case. I am not sure what i am doing wrong here.

Is there a way to achieve this?

windows-api
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Maybe other processes also use Topmost windows and LockSetForegroundWindow?


0 Votes 0 ·

There is no role of other processes because i know that user is going to run only two applications A and B on the system. I want that while B (whose window i have already made topmost) is running, the topmost dialog boxes of A should not come in front of it.

I tried with using LockSetForeGroundWindow in B in order to prevent topmost dialog box of A to come in front. But it is not working.

A working example of LockSetForeGroundWindow will be helpful. Alternatively, if there is a short way so that topmost dialog boxes of A never comes over topmost window of B.















0 Votes 0 ·

If the user is going to run only two applications A and B, then do not use Topmost dialogs in A.


0 Votes 0 ·

If you are able to prevent message boxes from application A from appearing over windows from Application B in the z-order then the user will not see them. Will this be a problem since application A will essentially do nothing as it waits for the user to respond to modal message boxes that cannot be seen?

0 Votes 0 ·

Actually application B has higher priority than A. That's why dialog boxes of A are not so important while B is running. But when B is not running, then A needs to be topmost. There is no other 3rd party application running on the system other than the explorer, etc.

Moreover, i do not want to make large changes in any of these applications.





0 Votes 0 ·

1 Answer

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered RLWA32-6355 commented

From Windows perspective, the TOPMOST modal message boxes are not the foreground windows. In my test they appeared over notepad in the z-order but notepad retained the keyboard focus and the message boxes were not the active windows. Don't confuse TOPMOST in the z-order with the foreground.

And for an application that used MB_TOPMOST | MB_SETFOREGROUND for the messagebox function the result was that the message box was TOPMOST but not the foreground window. The taskbar button for the application was flashing to indicate to the user that it wanted to become the foreground window.

If it is absolutely essential refer to the solution of using UIAccess privileges to create a TOPMOST window that will appear over all other TOPMOST windows (except for those created by other UIAccess enabled processes) as discussed here - display-a-customized-osd-on-screen-display-like-wi.html.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks @RLWA32-6355 it is working.

0 Votes 0 ·

You're welcome.

0 Votes 0 ·