Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
New related comments Number of comments in the last 48 hoursAdd a page to a tabbed notebook (TTabbedNotebook) 1 new comments
|
How can I close a MessageBox()
This article has not been rated yet. After reading, feel free to leave comments and rate it.
(by Ralph Friedman)
You can use a thread to achieve that:
 | |  | | unit MsgThread;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms, StdCtrls, ExtCtrls;
type
TMboxThread = class(TThread)
private
protected
procedure Execute; override;
public
constructor Create;
end;
type
TFrmMsgThread = class(TForm)
BtnClose: TButton;
Edit1: TEdit;
Edit2: TEdit;
Timer1: TTimer;
procedure BtnCloseClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
FFirst: boolean;
FMboxThread: TMBoxThread;
FWinHandle: HWnd;
public
end;
var
FrmMsgThread: TFrmMsgThread;
implementation
constructor TMboxThread.Create;
begin
FreeOnTerminate := True;
inherited Create(False);
end;
procedure TMboxThread.Execute;
begin
MessageBox(Application.Handle, 'Text', 'Caption',
MB_APPLMODAL + MB_SETFOREGROUND);
end;
procedure TFrmMsgThread.BtnCloseClick(Sender: TObject);
begin
FMBoxThread := TMBoxThread.Create;
FFirst := true;
Timer1.Enabled := true;
end;
procedure TFrmMsgThread.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := false;
if FFirst then
begin
FWinHandle := GetForegroundWindow;
FFirst := false;
Timer1.Enabled := true;
end
else
SendMessage(FWinHandle, WM_CLOSE, 0, 0);
end;
end. | |  | |  |
Comments:
|