Solved

Help with ShowMessagePos

Posted on 1998-08-29
5
359 Views
Last Modified: 2010-04-03
Could someone give me an example of how to get ShowMessagePos to center itself in the active form.

Thanks
0
Comment
Question by:evel
5 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1338123
Why don't you use MessageDlgPos?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1338124
Here is an example from Delphi help file =)

procedure TForm1.Button1Click(Sender: TObject);
begin
  MessageDlgPos('Are you there?',mtConfirmation, mbYesNoCancel, 0, 200, 200);
end;

Regards,
Viktor Ivanov
0
 
LVL 3

Expert Comment

by:vladika
ID: 1338125
All procedures (ShowMessage, MessageDlgPos etc) found on the function CreateMessageDialog
For details see dialogs.pas

So, I wrote procedure ShowMessageCenter.
You can use it instead of ShowMessagePos or you can modify it for your needs.

procedure ShowMessageCenter(const Msg: string);
var R: TRect;
begin
  if not Assigned(Screen.ActiveForm) then ShowMessage(Msg) else
  with CreateMessageDialog(Msg, mtCustom, [mbOK]) do
  try
    GetWindowRect(Screen.ActiveForm.Handle, R);
    Left := R.Left + ((R.Right - R.Left) div 2) - (Width div 2);
    Top := R.Top + ((R.Bottom - R.Top) div 2) - (Height div 2);
    ShowModal;
  finally
    Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessageCenter('I am centered in the active form');
end;


0
 

Author Comment

by:evel
ID: 1338126
Thanks vladika, that's just what I was looking for. Please answer the question so I can give you credit.
0
 
LVL 3

Accepted Solution

by:
vladika earned 100 total points
ID: 1338127
Ok. This is my "official answer".

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now