Jump to content
Sign in to follow this  
Nico Preto

Application.MessageBox in multiples monitors

Recommended Posts

I'm using Application.MessageBox in my project.

When used in multiple monitors, when called then message appears every time in the primary monitor.

 

But I need the message centered in the current visible form.

 

Any idea?

 

 

Share this post


Link to post
var
  MyMsg: TForm;
begin
   MyMsg := CreateMessageDialog('put Message in here...', mtCustom, [mbOK]);
   MyMsg.Position := poOwnerFormCenter;
   MyMsg.ShowModal;
end;

Easiest solution this might be?

Share this post


Link to post
1 hour ago, Nico Preto said:

I'm using Application.MessageBox in my project.

When used in multiple monitors, when called then message appears every time in the primary monitor.

 

But I need the message centered in the current visible form.

That's one of my major gripes with Windows.

 

The only solution I know is to roll your own or use an existing library. So I wrote my own. You can find it here;

 

https://osdn.net/projects/dzlib-tools/svn/view/dzlib/trunk/forms/?root=dzlib-tools

 

in Unit w_dzDialog.

Share this post


Link to post
10 hours ago, Nico Preto said:

Thanks guys

Could you at least tell what solution was working well for you to enlighten others by reading your topic?

Share this post


Link to post
Guest

hi @Nico Preto

 

you can try my sample:

  • MessageDLGPOS() will go use "TTaskMessageDialog" and you can use it directly include saying the "POSITION"  on the screen.
    • say... it will use "TCustomTaskDialog"
procedure TForm1.Button1Click(Sender: TObject);
var
  lMyMonitor: TMonitor;
  //
  X1                 : integer;
  Y1                 : integer;
  lOffSetWindowWidth : integer;
  lOffSetWindowHeight: integer;
begin
  lMyMonitor := Screen.MonitorFromWindow(Self.Handle);
  //
  lOffSetWindowWidth  := 100; // needs calculate it before show the window, of course...
  lOffSetWindowHeight := 50;
  //
  X1 := Random(lMyMonitor.Width - lOffSetWindowWidth);
  Y1 := Random(lMyMonitor.Height - lOffSetWindowHeight);;
  //
  try
    Memo1.Lines.Add(Format('Monitor = %d', [lMyMonitor.MonitorNum]));
    Memo1.Lines.Add(Format('Monitor Height=%d, Width=%d', [lMyMonitor.Height, lMyMonitor.Width]));
    Memo1.Lines.Add(Format('Monitor Left=%d, Top=%d, Height=%d, Width=%d', [ { }
      lMyMonitor.WorkareaRect.Left,                                          { }
      lMyMonitor.WorkareaRect.Top,                                           { }
      lMyMonitor.WorkareaRect.Height,                                        { }
      lMyMonitor.WorkareaRect.Width                                          { }
      ]));
    //
    Memo1.Lines.Add(Format('X1=%d, Y1=%d', [X1, Y1]));
    //
    Vcl.Dialogs.MessageDlgPos('msg string', mtInformation, [mbOK], 0, X1, Y1);
  finally
    //
  end;
end;

 

image.thumb.png.35601ed3a8d804211c6e51cd37ab576a.png

 

hug

Edited by Guest

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×