Software snipets for the Delphi & Pascal Community
Sep 05, 2010 - 06:00 AM
alt1
Borland :: Mailing Lists
alt1
Search  
alt1
alt1 alt1 alt1
alt1
Main Menu
alt1
· Home
· Your Account

Other Options

· AvantGo
· Downloads
· FAQ
· Members List
· Messages
· News
· Recommend Us
· Reviews
· Search
· Sections
· Stats
· Submit News
· Topics
· Top List
· Web Links

alt1
Who's online
alt1
There are currently, 5 guest(s) and 0 member(s) online.

You are an anonymous user. You can register for free by clicking here


alt1
alt1
How can I close a MessageBox()
Posted by: Gayle
alt1
Topic System API
Closing a Message Box (by Ralph Friedman)



How can I close a MessageBox()


(by Ralph Friedman)

You can use a thread to achieve that:

unit MsgThread;

interface

uses
.linksarray[0]., Messages, SysUtils, Classes, Controls, Forms, StdCtrls, ExtCtrls;

type
TMboxThread = class(TThread)
private
{ private declarations }
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
{ public declarations }
end;

var
FrmMsgThread: TFrmMsgThread;

implementation

{$R *.DFM}

{ TMboxThread }

constructor TMboxThread.Create;
begin
FreeOnTerminate := True;
inherited Create(False);
end;

procedure TMboxThread.Execute;
begin
{ Place thread code here }
MessageBox(Application.Handle, 'Text', 'Caption',
MB_APPLMODAL + MB_SETFOREGROUND);
end;

{ TForm1 }

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.



alt1
alt1
 
alt1
Login
alt1
Username

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like a theme manager, comments configuration and posting comments with your name.

alt1
Related links
alt1
· More about System API
· News by admin
· Microsoft


Most read story in System API:
How can I close a MessageBox()


Printer friendly page  Send this story to a friend

"How can I close a MessageBox()" | Login/Create an account | 2 Comments
Threshold
Comments are owned by the poster. We aren't responsible for their content.
Re: How can I close a MessageBox()(Score: 0)
by Anonymous on Feb 26, 2009 - 04:50 AM
Hi. Explore our blog with top info: graigslist, Face book


[ Comments not allowed for anonymous users, please register ]

Re: How can I close a MessageBox()(Score: 0)
by Anonymous on Aug 12, 2009 - 05:23 PM
Hi. Check our blog with best informations: www.myspace.com, download you tube videos


[ Comments not allowed for anonymous users, please register ]

alt1
Report Bugs :: Tasks :: Developers 
alt1




alt1