cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Brandon_Lowe
Level 6

How do I force a messageBox to the forground in BasicMSI

I have a BasicMSI installation I'm working with. In a couple places I display a AskYesNo question and some times that will pop up under the forground window. Is they a command I can use right before the AskYesNo to force it to the top?

Thanks
Brandon
Labels (1)
0 Kudos
(2) Replies
rguggisberg
Level 13

Ahhh yes... that subject comes up every now and then! Here's what I recently did. Add the custom action below and then just add the line
SetWindowFocus();
to your desired Custom Actions where you have this issue. Of course this is not goof proof because someone could be navigating willy-nilly around the screen after you have SetWindowFocus... but it solves the problem for most practical cases.
-----------------------------------------------------------
function SetWindowFocus()
HWND hMain;

begin
hMain = GetWindowHandle( HWND_INSTALL );
//Attach foreground window thread to installation thread
AttachThreadInput( GetWindowThreadProcessId( GetForegroundWindow(), NULL ), GetCurrentThreadId(), TRUE );

//Bring to foreground
SetWindowPos( hMain, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
SetForegroundWindow( hMain );

//Detach the attached thread
AttachThreadInput( GetWindowThreadProcessId( GetForegroundWindow(), NULL ), GetCurrentThreadId(), FALSE );
SetFocus( hMain );
end;
-----------------------------------------------------------
0 Kudos
MichaelU
Level 12 Flexeran
Level 12 Flexeran

For a Basic MSI, you should probably use MsiProcessMessage instead. This will allow Windows Installer to properly parent the dialog, and suppress it in scenarios that should not show UI. However the API will not work if the custom action is invoked in response to a ControlEvent (such as a button press on a dialog).
0 Kudos