精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Delphi>>其他>>线程>>采用多线程技术来关闭application.messagebox.

主题:采用多线程技术来关闭application.messagebox.
发信人: showskyws()
整理人: teleme(2001-03-26 23:04:52), 站内信件
采用多线程技术来关闭application.messagebox. 

//主要思路:在另个个线程查找到该消息框,然后发WM_CLOSE消息 
//为区别是其他的程序的消息框,我在提示的标题上多了一个空格,其实也可以用其他的办法。 希望大家可以有更好的办法,相互讨论。
//原码如下: 


var   myclose:tcloseother; 

begin 
  myclose:=tcloseother.Create(false); 
  myclose.FreeOnTerminate:=true; 
  application.MessageBox('程序已经运行!','消息提示 ',mb_ok+mb_iconinformation); 
end; 

unit closeother; 

interface 

uses 
  Classes,messages,sysutils,windows,forms; 

type 
  tcloseother = class(TThread) 
  private 
    { Private declarations } 
  protected 
    procedure Execute; override; 
  public 
    //procedure create(myhwnd:integer); 
  end; 

implementation 

{ Important: Methods and properties of objects in VCL can only be used in a 
  method called using Synchronize, for example, 

      Synchronize(UpdateCaption); 

  and UpdateCaption could look like, 

    procedure tcloseother.UpdateCaption; 
    begin 
      Form1.Caption := 'Updated in a thread'; 
    end; } 

{ tcloseother } 


//procedure tcloseother.create(myhwnd: integer); 
//begin 
//end; 

procedure tcloseother.Execute; 
const 
  NumSec=5;  //设置5秒后自动关闭 
var 
  messagehwnd:integer; 
  starttime:tdatetime; 
begin 
  StartTime := now; 
  repeat 
    Application.ProcessMessages; 
  until Now > StartTime + NumSec * (1/24/60/60); 
  messagehwnd:=FindWindow(nil,'消息提示 '); 
  postmessage(messagehwnd,wm_close,0,0); 
end; 

end. 



//作为北京社区DELPHI的版副,我想说的是,希望北京和广州的DELPHI版加强技术交流,能够相互合作。相互讨论技术问题。


----
我每天都在努力,因为每天都要进步!
沉迷网络,程序人生,这就是我!
欢迎光临我的个人主页:示天工作室 


网易北京社区 DELPHI版 版副发贴印 
               

[关闭][返回]