如何抓住另一窗口的edit框的句柄?(30分)

  • 主题发起人 主题发起人 coolbaby
  • 开始时间 开始时间
一点参考:<br>得出Edit的Rect<br>先取得需要抓住的那个窗口的句柄<br>再用GetWindow 和 GetNextWindow 遍历子窗口(即那个窗口中的所有组件),<br>直到其Rect符合条件即是
 
var<br>&nbsp; DC: HDC;<br>begin<br>&nbsp; DC := GetDC(form2.edit1.handle);<br>end;
 
“另一窗口”,是同一个程序的,还是别个程序的另一窗口,<br>如果是别个程序的就看看吧<br>procedure TForm1.Button1Click(Sender: TObject);<br>&nbsp;function EnumChildWindowsProc(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br>&nbsp; var<br>&nbsp; &nbsp; buffer: array[0..255] of Char;<br>&nbsp; begin<br>&nbsp; &nbsp; Result := True;<br>&nbsp; &nbsp; //得到目标窗口的控件<br>&nbsp; &nbsp; GetClassName(hwnd,buffer,256);<br>&nbsp; &nbsp; //找到发消息的目标窗口的目标控件<br>&nbsp; &nbsp; if StrPas(Buffer)='TEdit' then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; PInteger(lparam)^ := hwnd; 得到目标控件的Hwnd(句柄)<br>&nbsp; &nbsp; &nbsp; Result:=False; &nbsp;//终止循环<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>var<br>&nbsp; Handle: Integer;<br>&nbsp; buffer: Array[0..1023] of Char;<br>begin<br>&nbsp; Handle := FindWindow(nil,'另个窗口名'); &nbsp;//就是窗口的Caption<br>&nbsp; if Handle&lt;&gt;0 then<br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; EnumChildWindows(Handle,@EnumChildWindowsProc,Integer(@Handle));<br>&nbsp; &nbsp; &nbsp;//如果找到就是Handle,如果没找到Handle,还是窗口<br>&nbsp; &nbsp; &nbsp;//下面这句是测试<br>&nbsp; &nbsp; &nbsp; SendMessage(Handle,WM_SETTEXT,0,Integer(pchar('Your String')));<br>&nbsp; &nbsp; end;<br>end;
 
多人接受答案了。
 
后退
顶部