Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How can I close a MessageBox() Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
23-Aug-02
Category
Dialogs
Language
Delphi 2.x
Views
95
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How can I close a MessageBox()

Answer:

You can use a thread to achieve that: 

1   unit MsgThread;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Controls, Forms, StdCtrls, ExtCtrls;
7   
8   type
9     TMboxThread = class(TThread)
10    private
11      { private declarations }
12    protected
13      procedure Execute; override;
14    public
15      constructor Create;
16    end;
17  
18  type
19    TFrmMsgThread = class(TForm)
20      BtnClose: TButton;
21      Edit1: TEdit;
22      Edit2: TEdit;
23      Timer1: TTimer;
24      procedure BtnCloseClick(Sender: TObject);
25      procedure Timer1Timer(Sender: TObject);
26    private
27      FFirst: boolean;
28      FMboxThread: TMBoxThread;
29      FWinHandle: HWnd;
30    public
31      { public declarations }
32    end;
33  
34  var
35    FrmMsgThread: TFrmMsgThread;
36  
37  implementation
38  
39  {$R *.DFM}
40  
41  { TMboxThread }
42  
43  constructor TMboxThread.Create;
44  begin
45    FreeOnTerminate := True;
46    inherited Create(False);
47  end;
48  
49  procedure TMboxThread.Execute;
50  begin
51    { Place thread code here }
52    MessageBox(Application.Handle, 'Text', 'Caption',
53      MB_APPLMODAL + MB_SETFOREGROUND);
54  end;
55  
56  { TForm1 }
57  
58  procedure TFrmMsgThread.BtnCloseClick(Sender: TObject);
59  begin
60    FMBoxThread := TMBoxThread.Create;
61    FFirst := true;
62    Timer1.Enabled := true;
63  end;
64  
65  procedure TFrmMsgThread.Timer1Timer(Sender: TObject);
66  begin
67    Timer1.Enabled := false;
68    if FFirst then
69    begin
70      FWinHandle := GetForegroundWindow;
71      FFirst := false;
72      Timer1.Enabled := true;
73    end
74    else
75      SendMessage(FWinHandle, WM_CLOSE, 0, 0);
76  end;
77  
78  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC