if messagebox(handle,'测试','提示',MB_OKCANCEL+MB_IconInformation+MB_SystemModal)=IDOK then begin ..... end;目的是要在这个messagebox在10秒中内没任何操作的话,会自动执行“确定”按钮!请问如何写这个事件的代码?
必须另外开启一个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;
创建一个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有效,数10秒,自动进行下一步操作。代码自己写了,练练手
我想应该是在messagebox的前一句给变量一个值,比如count;=10。timer中加入如果count不等于0就执行dec(count)。然后在begin中用一个while,如果按过确定或取消句跳出循环,count=0则执行确定。我试的写了一下,可惜messagebox的确定和取消这些句柄不知道怎么获得。如果能获得句柄应该就解决了吧
可以让timer每1秒执行一次,当数10次时就做你想做的事。我不管你用什么方法。
最好你了解一下什么叫timer
而且你要做的事有什么意义吗?
为什么非用messagebox
比如自己新建一个窗体,在窗体上放一个timer组件,窗体的oncreate事件里把timer组件激活。然后计时。当10秒后返回。button1.modalresult属性送一个值 过去就行了,窗体就关了。
当然这个新窗体要用showmodal方法显示它。思路大约就是这样吧。自己写一个窗体显示提示信息,不一定非用messagebox。这样更灵活。
这样不是麻烦么? 还要修改DELPHI源代码. whitetiger8(键盘未敲坏,基本功未练成) ( ) 的可行性最好!
keybd_event(13,0,KEYEVENTF_EXTENDEDKEY,0); //KEYDOWN,
有没有messagebox的函数代码啊!我找不到
这样可以更灵活,也少死一些脑细胞:)
FORM1调用对话窗口的窗口
FORM2(自己做的仿MESSAGEBOX对话窗口)---------------------------
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
Form2:=TForm2.Create(nil);
Form2.ShowModal;
end;end.
----------------------------------------------------------------------------------
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;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;end.
------------------------------------------------
不知道楼主是不是这个意思,FORM2只有3个控件BUTTON1 BUTTON2 和TIMER1 具体的对话框其他功能楼主可以自己扩展。
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;
当需要的时候,show窗体(ShowModal),不要的时候把他freeandnil掉
一切由timer控制
很好做的,自己试一试
注意加
if Form2=nil then
begin
Form2:=TForm2.create(self)
Form2.Show;//或者ShowModal,根据你的要求来做了
....
end else
begin
....
end;