How to AutoClose a ShowMessage box

This is what I assume should be an easy question for others :

I have a Showmessage pop up dialog box message in a program.   Most of the time I want the user to read the msg & then click to close it.    However, sometimes I would like to pop up a msg for say 1 sec then programmatically close it.

Can I do this ?  Easily ?

I could create a form, & since I'd be developing the code, object (button) names etc would be available, and I could easily do this - but this seems like extra work when the ShowMessage box is already there, does pretty much what I want - but I don't know how to 'access' the close function.

If this is not possible with ShowMessage, what about MessageBox ?

Thanks
Geoff
geoffdbAsked:
Who is Participating?
 
pritaeasSoftware EngineerCommented:
Should you like to add a progressbar:

http://delphi.about.com/cs/adptips2004/a/bltip0104_2.htm
0
 
pritaeasSoftware EngineerCommented:
0
 
shaneholmesCommented:
Drop a TTimer on the form (FORM 2 - Dialog box)

Set its "Enabled" property to true

set its "Interval" property to the time you want to have the form close

1000 = 1 sec

5000 = 5 sec


In the TTimer's "OnTimer event " place the following

procedure TForm2.Timer1Timer(Sender: TObject);
begin
 Close;
end;

Now from Form 1

procedure TForm1.Button1Click(Sender: TObject);
begin
 form2.ShowModal;
end;


hope this helps

sholmes


0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Eddie ShipmanAll-around developerCommented:
Hey, pritaeas, thatnks for pointing him to my tip. I was going to suggest that one.

E. (alias-MrBaseball34)

0
 
pritaeasSoftware EngineerCommented:
No problem, why recreate something when there's already a good working solution available! ;>
0
 
shaneholmesCommented:
ooops - sorry i miss read the question

"I could create a form, & since I'd be developing the code, object (button) names etc would be available, and I could easily do this - but this seems like extra work when the ShowMessage box is already there"

sholmes
0
 
geoffdbAuthor Commented:
Pritaeas

Thanks !!  The first reference works a treat - as does the one with the progressbar.   I'm using the former - but am getting annoyed with the system beep that comes with the windows MessageBox.

Is there a way to turn this beep off - or do I need to go to the CreateMessageDialog version instead ?

Thanks, G
0
 
TheRealLokiSenior DeveloperCommented:
another method, using a messagedlg

procedure TForm1.Button1Click(Sender: TObject);
var
    i: integer;
    begin
        timer1.Enabled := True;
        i := MessageDlg('fText', mtCustom, [mbOK], 0);
        timer1.Enabled := False;
    end;

procedure TForm1.Timer1Timer(Sender: TObject);
    var
        h: THandle;
    begin
        h := FindWindow( PChar('TMessageForm' ) , PChar(Application.Title));
            // or                               , PChar('Information') );
        if h <> 0 then
          SendMessage(h, wm_Close, 0, 0);
    end;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.