views:

28

answers:

2

I have a TimerProc which calls MessageBox. I want the MessageBox to stay on top of other windows. So for example, the parent window sets the timer, then I move another window on top of that. When the timer fires, I want to MessageBox to appear on top of the window that is covering the app. Is this possible, and how should I go about doing it?

+1  A: 

Do you need the same message box which is already open to go to the top? Or a new one to open up above the other windows?

If you want the same MessageBox which is already open just brought to the top:

I think you can get a MessageBox window handle if you use EnumThreadWindows but I've never tried it myself. So if that works you could use its window handle in a call to BringWindowToTop.

If getting the MessageBox handle isn't working for you, you can simply create your own window which looks like a message box instead and then call BringWindowToTop instead.

If you want to popup a new MessageBox on the top:

If you want a new MessageBox each time you can use the MB_SYSTEMMODAL flag as described in the MessageBox documentation. MB_TOPMOST is said to be ignored in Vista and above.

Brian R. Bondy
+2  A: 

I think you want to make it System Modal as MB_SYSTEMMODAL as described here.

And/or make the window that is on top be the owner of the MessageBox.

ho1