Findwindow!(50分)

  • 主题发起人 主题发起人 coolmyf
  • 开始时间 开始时间
C

coolmyf

Unregistered / Unconfirmed
GUEST, unregistred user!
请问Findwindow和FindwindowEx这两个函数是如何使用的。<br>最好能给出例子!谢谢!
 
The FindWindow function retrieves the handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. <br><br>HWND FindWindow(<br><br>&nbsp; &nbsp; LPCTSTR lpClassName, // pointer to class name<br>&nbsp; &nbsp; LPCTSTR lpWindowName // pointer to window name<br>&nbsp; &nbsp;);<br><br>你首先打开附件里的计算器,<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>HWndCalculator : HWnd;<br>begin<br>// find the exist calculator window<br>HWndCalculator := FindWindow(nil, '计算器'); // close the exist Calculator<br>if HWndCalculator &lt;&gt; 0 then<br>SendMessage(HWndCalculator, WM_CLOSE, 0, 0);<br>end;
 
根据给出的类名或窗口标题名称取的该窗口的句柄<br>var<br>&nbsp; AHandle:THandle;<br>begin<br>&nbsp; AHandle:=FindWindow(nil,'我的电脑');<br>&nbsp; if AHandle&lt;&gt;0 then<br>&nbsp; begin<br>&nbsp; &nbsp; //To do add your code here<br>&nbsp; &nbsp; SendMessage(AHandle,WM_SYSCOMMAND,SC_CLOSE,0);<br>&nbsp; end;<br>end;<br><br>// &nbsp;TMyFrm=class(TForm)<br><br>var<br>&nbsp; AHandle:THandle;<br>begin<br>&nbsp; AHandle:=FindWindow(TMyFrm,nil);<br>&nbsp; if AHandle&lt;&gt;0 then<br>&nbsp; begin<br>&nbsp; &nbsp; //To do add your code here<br>&nbsp; &nbsp; SendMessage(AHandle,WM_SYSCOMMAND,SC_CLOSE,0);<br>&nbsp; end;<br>end;<br><br><br>FindwindowEx 同理只是多一点参数<br><br>&nbsp;
 
findwindowex 的功能更强<br>如果 findwindow在win2000 or NT 下实现不了的<br>findwindowex 可以实现
 
&nbsp;Wnd1:=FindWindow(PChar(FormName), PChar(FormCaption));<br>&nbsp; Wnd1:=FindWindowEx(Wnd1,Hdl,'TEdit', nil);
 
多人接受答案了。
 
后退
顶部