如何判断指定句柄的窗口/控件是否还存在(100分)

S

swlove

Unregistered / Unconfirmed
GUEST, unregistred user!
我用下面的代码获得了某个主程序的一个控件的句柄,然后我想用定时器利用前面获得的句<br><br>柄来每隔一段时间判断它是否还存在,那该如何判断呢 ?<br>谢谢<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, Buttons, XPMan;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; BitBtn1: TBitBtn;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; XPManifest1: TXPManifest;<br>&nbsp; &nbsp; procedure BitBtn1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormMouseDown(Sender: TObject; Button: TMouseButton;<br>&nbsp; &nbsp; &nbsp; Shift: TShiftState; X, Y: Integer);<br>&nbsp; &nbsp; procedure FormShow(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>begin<br>&nbsp; setcapture(handle); // &nbsp; 设置捕获鼠标输入<br>end;<br><br>procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;<br>&nbsp; Shift: TShiftState; X, Y: Integer);<br>var point: TPoint;<br>&nbsp; hwnd: THandle;<br>begin<br>&nbsp; point.x := x;<br>&nbsp; point.y := y;<br>&nbsp; point := ClientToScreen(point); // &nbsp; 客户区坐标转换到屏幕坐标<br>&nbsp; hwnd := WindowFromPoint(point); // &nbsp; 取鼠标点击的窗体句柄<br>&nbsp; ReleaseCapture; // &nbsp; 终止捕获鼠标输入<br>&nbsp; if hwnd = handle then edit1.text := '没有点击其他窗体!'<br>&nbsp; else<br>&nbsp; &nbsp; edit1.Text := inttostr(hwnd); // &nbsp; 将捕捉到的窗体句柄显示在edit1中<br>end;<br><br><br>procedure TForm1.FormShow(Sender: TObject);<br>begin<br>&nbsp; SetWindowPos(handle, HWND_TopMost, 0, 0, 0, 0, SWP_NoMove or SWP_NoSize or SWP_ShowWindow);<br>end;<br><br>end.
 
IsWindow<br>IsWindowVisible<br>这两个API不知道能源满足你的要求不
 
为什么我这样不行?<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; if IsWindow(67154)&lt;&gt;0 then<br>&nbsp; &nbsp; Application.MessageBox('YES','提示',MB_OK)<br>&nbsp; else<br>&nbsp; &nbsp; Application.MessageBox('NO','提示',MB_OK);<br>end;<br><br>提示类型不对...<br>里面的67154我用开始的代码获得的...<br><br>到底该怎样做呢 ?
 
去下载个 CnFindWnd<br>里面有完整源代码
 
句柄我找到了<br><br>可怎样利用找到的句柄来判断窗口是否还存在就不懂了
 
你不是用定时器检测句柄吗?获取句柄后检测是否为0不就可以了,当这个句柄为0的时候就说明已经不存在啊!~
 
if IsWindow(67154) then &nbsp; // IsWindow返回的是bool值!<br>&nbsp; &nbsp; Application.MessageBox('YES','提示',MB_OK)<br>&nbsp; else<br>&nbsp; &nbsp; Application.MessageBox('NO','提示',MB_OK);
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
511
import
I
顶部