if messagebox(handle,'测试','提示',MB_OKCANCEL+MB_IconInformation+MB_SystemModal)=IDOK then begin
.....
end;
目的是要在这个messagebox在10秒中内没任何操作的话,会自动执行“确定”按钮!
请问如何写这个事件的代码?
...全文
31419打赏收藏
关于messagebox的问题!
if messagebox(handle,'测试','提示',MB_OKCANCEL+MB_IconInformation+MB_SystemModal)=IDOK then begin ..... end; 目的是要在这个messagebox在10秒中内没任何操作的话,会自动执行“确定”按钮! 请问如何写这个事件的代码?
创建一个Form,name Form2,再放一个时针timer
当需要的时候,show窗体(ShowModal),不要的时候把他freeandnil掉
一切由timer控制
很好做的,自己试一试
注意加
if Form2=nil then
begin
Form2:=TForm2.create(self)
Form2.Show;//或者ShowModal,根据你的要求来做了
....
end else
begin
....
end;
必须另外开启一个timer或者另外开启一个监视线程,因为messagebox执行后实际上产生了软中断,其后面的程序不会执行所以把关闭代码写在messagebox后面是不行的
timer1timer(sender:tobject);
var
h:thandle;
begin
h:=findwindow('messagebox的类名','messagebox的窗体名');//你可以查看一下vcl原代码看看messagebox的类名 你也可以用其他辅助软件捕获,或自己用enumwindows和enumchildwindows枚举自己寻找
if h<>0 then //找到窗口 或者用getactivewindow获得当前最前端窗体的handle,但是要保证你的messagebox为最前端
posemessage(h,wm_close,0,0);
end;
type
TForm2 = class(TForm)
Timer1: TTimer;
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
c:integer;
implementation
{$R *.dfm}
procedure TForm2.Button2Click(Sender: TObject);
begin
close;
end;
procedure TForm2.Timer1Timer(Sender: TObject);
begin
inc(c);
Button1.Caption:='Button1';
Button1.Caption:=Button1.Caption+'('+inttostr(c)+')';
if c=10 then
Form2.ModalResult:=mrCancel;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
c:=0;
end;