Delphi 7 - ShowMessage to Stay on Top and not to be Able to Click Other Windows of applications unless you Press ''ok'' button in the message

StackOverflow https://stackoverflow.com/questions/22557739

  •  18-06-2023
  •  | 
  •  

Question

How can i do that?

procedure TFMain.Button2Click(Sender: TObject);
begin
ShowMessage('Cya!!');
Application.Terminate;
end;

Is there any way to be able to only click the ''OK'' from the ShowMessage and if I dont i wont be able to click anything else in my interface?

Was it helpful?

Solution 2

I think you're looking for the MB_SYSTEMMODAL flag on MessageBox. Instead of ShowMessage, call MessageBoxdirectly, like this:

MessageBox(Application.Handle,'Cya!!',PChar(Application.Title),MB_OK or MB_ICONINFORMATION or MB_SYSTEMMODAL);

OTHER TIPS

There is no supported way to show a window that prevents interaction with other applications.

You can use ShowMessage to show a modal dialog that will always appear top-most in your application, and whose modality covers all other windows in your application. That is the user is prevented from interacting with other windows in your application while the message box is shown. That is the maximum amount of modality that is supported by the system.

You can create a modal dialog that has the show on top property. You cannot prevent the user from interacting with other applications but you can make sure that your window is always on top of the window the user wants to work with. Take a minute now to consider how the user will react to your application doing that.

Should you decide that you want to do that you can use MessageBox with MB_SYSTEMMODAL. Or you can create your own form (or use CreateMessageDialog) and set its show on top property (set FormStyle to fsStayOnTop) before you call ShowModal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top