一窗口包含了某字符,如何获得其句柄?(100分)

  • 主题发起人 主题发起人 leo.1999
  • 开始时间 开始时间
L

leo.1999

Unregistered / Unconfirmed
GUEST, unregistred user!
例如<br>delphi 7<br>delphi 6<br>delphi 5<br>他们都包含了“delphi”我就是要获得标题包含“delphi”的窗口的句柄<br>
 
FindWindow,然后取这个窗体的文字,然后用POS判断你的文字是否包含在此窗口中,<br>循环查找
 
var<br>&nbsp; &nbsp;i: HWnd;<br>&nbsp; &nbsp;szText: array[0..254] of char;<br>begin<br>&nbsp; listbox1.Items.Clear;<br>&nbsp; i := GetWindow(Handle, GW_HWNDFIRST);<br>&nbsp; while i &lt;&gt; 0 do<br>&nbsp; begin<br>&nbsp; &nbsp; if ( GetWindowText(i, @szText, 255)&gt;0 ) then <br>&nbsp; &nbsp; &nbsp; if ( pos('delphi',szText)&gt;0 ) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; listbox1.items.Add(StrPas(@szText));<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; i:=GetWindow(i, GW_HWNDNEXT);<br>&nbsp; end;<br>end;<br>
 
var<br>&nbsp;hwnd:Integer; &nbsp;// handle to parent window<br>&nbsp;str1:array[0..255] of char;<br>begin<br>&nbsp;hwnd:=FindWindow(nil,nil);<br>&nbsp;While hwnd&gt;0 do<br>&nbsp;begin<br>&nbsp; &nbsp;GetWindowText(hwnd,str1,255);<br>&nbsp; &nbsp;if (pos('delphi',str1)&gt;0 ) then<br>&nbsp; &nbsp; &nbsp;Memo1.Lines.Add(str1);<br>&nbsp; &nbsp;hwnd:=GetNextWindow(hwnd,GW_HWNDNEXT);<br>&nbsp;end;<br>end; &nbsp;<br>
 
不要句柄也可以。<br>var<br>&nbsp; I:integer;<br>begin<br>&nbsp; for I:=0 to screen.formcount-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; if pos('delphi',screen.form.name) &nbsp;&gt;0 then<br>&nbsp; &nbsp; &nbsp;Listbox1.items.add(screen.form.name);<br>&nbsp; end;<br>
 
var<br>hcrrentwindow:hwnd;<br>sztext:array[0..254] of char;<br>s:string;<br>begin<br>hcrrentwindow:=GetWindow(handle,GW_HWNDFIRST);<br>while hcrrentwindow&lt;&gt;0 do<br>begin<br>if GetWindowtext(hcrrentwindow,@sztext,255)&gt;0 then<br>begin<br>s:=strpas(@sztext);<br>if pos('Microsoft Excel',s)&lt;&gt;0 then//如果发现含有Microsoft Excel的窗口将其关闭。<br>SendMessage(hcrrentwindow,WM_CLOSE,0,0);<br>Memo1.Lines.Add(s);<br>end;<br>hcrrentwindow:=GetWindow(hcrrentwindow,GW_HWNDNEXT);<br>end;<br>end;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
后退
顶部