Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi messagebox appearing behind other form

I am using the code below to create a messagebox in Delphi 7. However I also have another form on screen who's FormStyle is set to fsStayOnTop and the messagebox appears behind this form.

Is there any way to force the messagebox to appear in front?

    if Application.MessageBox('Amessage here','Title', +MB_APPLMODAL + MB_ICONQUESTION + MB_YESNO) = IDNO then
like image 296
colin Avatar asked Nov 04 '11 09:11

colin


2 Answers

Call NormalizeTopMosts prior to showing the message box.

Use NormalizeTopMosts to allow a message box or dialog box that is displayed using the Windows API functions (such as MessageBox and MessageDlg) directly, appear on top of a topmost form. Otherwise the topmost form remains on top, and may obscure the message box.

(Hope it's available in Delphi 7.)

Edit: Not sure about the downvote. If it hints in the direction that OP should use the native MessageBox function and set its parent HWND to the topmost window - I would agree. But maybe this is not possible for some reason.

like image 75
Heinrich Ulbricht Avatar answered Oct 06 '22 01:10

Heinrich Ulbricht


In Windows.pas you can find more flags to MessageBox():

MB_APPLMODAL = $00000000;
MB_SYSTEMMODAL = $00001000;
MB_TASKMODAL = $00002000;

Read about them in MessageBox documentation

You can even use MB_TOPMOST flag.

like image 38
Michał Niklas Avatar answered Oct 05 '22 23:10

Michał Niklas