如何查找其它程序窗口中指定子窗口的句柄?(200分)

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

ch_yahuu

Unregistered / Unconfirmed
GUEST, unregistred user!
那个主窗口上有4个edit框.每个edit的类名都是一样的.不像delphi中用edit1.edit2.edit3等.<br>我只想得到第一个和第三个的内容.可就是不知道如何得到句柄.通常用findwindowex只能得到第一个的.<br>请大家帮忙得到其它的句柄.我记得以前有一个人.它在这里发表了一个文张.说可以向几个edit中发一个消息.当作标记.<br>可我再次收所论坛时就找不到了.不知哪个还记得倒啊.告诉小弟一声啊.谢谢
 
//取得Mouse所在处的句柄<br><br>var<br>&nbsp; Pos &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : TPoint;<br>&nbsp; Handle &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: HWND;<br>&nbsp; Buf &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : array[0..1024] of Char;<br>begin<br>&nbsp; GetCursorPos(Pos);<br>&nbsp; Handle := WindowFromPoint(Pos);<br>&nbsp; GetClassName(Handle, Buf, 1024);<br>......<br>end;
 
这个问题应该用EnumChildWindows吧,<br>你看下面这个例子。<br><br>function EnumChildWindowsProc(H: HWnd; lparam: longint): Boolean; stdcall;<br>var<br>&nbsp; Buffer: array[0..10] of Char;<br>begin<br>&nbsp; Result := True; //設定為True才會再找下一個<br>&nbsp; getclassname(h,buffer,10);<br>&nbsp; if trim(StrPas(Buffer))='Edit' then<br>&nbsp; begin<br>&nbsp; &nbsp; ThisUrl:= StrAlloc(250);<br>&nbsp; &nbsp; SendMessage(h,WM_GETTEXT,249,Integer(ThisUrl));<br>&nbsp; &nbsp; Result:=False;//設定為false不找下一個<br>&nbsp; end;<br>end;<br><br>procedure GetUrl;<br>begin<br>&nbsp; EnumChildWindows(ParentWindow, @EnumChildWindowsProc, 0);<br>end;
 
先用 Findwindowex 获得父窗口句柄<br><br>再用<br>BOOL EnumChildWindows(<br>&nbsp; &nbsp; HWND hWndParent, // handle to parent window<br>&nbsp; &nbsp; WNDENUMPROC lpEnumFunc, // pointer to callback function<br>&nbsp; &nbsp; LPARAM lParam // application-defined value<br>&nbsp; &nbsp;);<br>枚举子类,逐个检查类名,并按照出现次序 找到你要的第一,第三
 
不是啊.兄弟们.我说的是有几个类名都是edit的啊(类名相同.我如何分别它们啊.).我要用程序自动取和第一个和第三个的内容啊.<br>不取第二个的啊.<br><br>edit中的内容是不确定的.我相用程序自动取得第一个和第三个中用户输入的信息.不取第二个啊.<br>
 
按创建顺序依次取并判断,要则处理不要就忽略,如果你不知道创建顺序,试一下不就知道了
 
按照 轻松虎 的方法,遇到第二个则仍调,不就行了。<br>每取一个侧将一个计数器加一,如果计数器值为 1(第二个),则不要
 
谢谢.我明白了意思了.但是我不知道轻松兄弟的api是什么意思啊.<br>我不会用api啊.你能不能给我个源码.<br>还有英文我看不懂啊.<br>兄弟.小弟给你磕头了.<br>api中的英文说明你给我写中文吧.谢谢了.实在谢谢了.<br>
 
多人接受答案了。
 
顶部