【不解】微软搞的什么鬼?(WindowFromPoint)(100分)

  • 主题发起人 主题发起人 ypy
  • 开始时间 开始时间
Y

ypy

Unregistered / Unconfirmed
GUEST, unregistred user!
今天用 WindowFromPoint 函数,MSDN上说可以找回指定坐标下的窗口句柄,<br>但磁盘共享属性页里的“共享名”等static、edit的句柄却找不到,<br>为什么???<br>用SPY++来找有时可以,有时也找不到,好奇怪!!!
 
可能是因为这个原因:<br><br>Remarks<br>The WindowFromPoint function does not retrieve a handle to a hidden or disabled window, even if the point is within the window. An application should use the ChildWindowFromPoint function for a nonrestrictive search. <br><br>
 
我是2001 July的msdn。<br>上面有个例子,好好看看:<br>Interface from Running Object Table<br>A running object table (ROT) tells what object instances are active. By querying this table, you can accelerate the process of connecting a client to an object when the object is already running. Before programs can access TOM interfaces through the running object table, a TOM instance with a window needs to register in the ROT using a moniker. You construct the moniker from a string containing the hexadecimal value of its HWND. The following code sample shows how to do this.<br><br>// This TOM implementation code is executed when a new windowed <br>// instance starts up. <br>// Variables with leading underscores are members of this class.<br><br>OLECHAR szBuf[10]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Place to put moniker<br>MONIKER *pmk;<br>wsprintf(szBuf, "%x", _hwnd);<br>CreateFileMoniker(szBuf, &amp;pmk);<br>OleStdRegisterAsRunning(this, pmk, &amp;_dwROTcookie);<br>....................<br>&nbsp;<br>// Accessibility Client: <br>// &nbsp; &nbsp;Find hwnd for window pointed to by mouse cursor.<br><br>GetCursorPos(&amp;pt);<br>hwnd = WindowFromPoint(pt);<br><br>// Look in ROT (running object table) for an object attached to hwnd<br><br>wsprintf(szBuf, "%x", hwnd);<br>CreateFileMoniker(szBuf, &amp;pmk);<br>CreateBindContext(0, &amp;pbc);<br>pmk-&gt;BindToObject(pbc, NULL, IID_ITextDocument, &amp;pDoc);<br>pbc-&gt;Release();<br><br>if( pDoc )<br>{<br>&nbsp; &nbsp; pDoc-&gt;RangeFromPoint(pt.x, pt.y, &amp;pRange);<br>&nbsp; &nbsp; // ...now do whatever with the range pRange<br><br>
 
hoho !<br>这里也回答一个???
 
没人理解吗?还是我的问题太高深了???
 
&gt;&gt; 用SPY++来找有时可以,有时也找不到,好奇怪!!!<br>我在 2000 下用相同软件每次都可以看到。<br>&gt;&gt; 没人理解吗?还是我的问题太高深了???<br>我能正常使用这个函数,包括你说的“磁盘共享属性页里的"共享名"等static、edit的句柄”,也<br>都一一可以看到。<br>&gt;&gt; 为什么???<br>不知道。
 
1.可能是我spy++有问题,我从网上下的<br>2.你用WindowFromPoint能找到“共享名”及其后的EDIT,“权限”“缓存”等button的句柄吗?<br>如果能可否给我一段实现的代码,我愿意再加分,因为这个问题困扰我好长时间了,一直<br>搞不明白为什么
 
我是过了,spy++的确可以看到,每次都可以。 windowfrompoint不行。<br><br>这只能证明:spy++不是用的windowfrompoint
 
1.当点“不共享该文件夹”时,你说的部分被 Disable 。不能取得内部句柄。<br>2.当点“共享该文件夹”时,你说的部分被 Enable 。必须点一次内部的框框,才可以取得内部句柄。<br>&nbsp; “共享名” &nbsp;其后的EDIT :67312<br>&nbsp; “备注” &nbsp; &nbsp;其后的EDIT :67318<br>&nbsp; “权限” &nbsp;Button &nbsp; &nbsp; &nbsp; :67334<br>&nbsp; “缓存” &nbsp;Button &nbsp; &nbsp; &nbsp; :67338<br>以上由 WindowFromPoint 函数取得,问题是,实际取时,位置并不是正好在鼠标下。<br>事件 : FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);<br>pt.x:=X;pt.y:=y;<br>ClientToScreen(pt);<br>WndHand:=WindowFromPoint(pt);<br>用 Spy++ 获取时就没有这样的前提条件,并且位置也很准确。
 
新建工程,窗体上放置一个Button,一个Edit.使用方法:先点击button,然后点击想要得到句柄的窗体.下面是代码<br>unit Unit1; <br><br>interface <br><br>uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; <br><br>type <br>&nbsp; TForm1 = class(TForm) <br>&nbsp; &nbsp; Button1: TButton; <br>&nbsp; &nbsp; Edit1: TEdit; <br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject); <br>&nbsp; &nbsp; procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); <br>&nbsp; private <br>&nbsp; { Private declarations } <br>&nbsp; public <br>&nbsp; { Public declarations } <br>&nbsp; end; <br><br>var Form1: TForm1; <br><br>implementation <br><br>{$R *.DFM} <br>procedure TForm1.Button1Click(Sender: TObject); <br>begin <br>&nbsp; setcapture(handle); // 设置捕获鼠标输入 <br>end; <br><br>procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); <br>var point : TPoint; <br>&nbsp; &nbsp; hwnd : THandle; <br>begin <br>&nbsp; point.x := x; <br>&nbsp; point.y := y; <br>&nbsp; point := ClientToScreen(point); // 客户区坐标转换到屏幕坐标 <br>&nbsp; hwnd := WindowFromPoint(point); // 取鼠标点击的窗体句柄 <br>&nbsp; ReleaseCapture; // 终止捕获鼠标输入 <br>&nbsp; if hwnd=handle then edit1.text := '没有点击其他窗体!' <br>&nbsp; else <br>&nbsp; &nbsp; edit1.Text := inttostr(hwnd); // 将捕捉到的窗体句柄显示在edit1中<br>end; <br>end.
 
谢谢小雨哥,怎么我点出来“共享名” &nbsp;其后的EDIT &nbsp;“备注” &nbsp; &nbsp;其后的EDIT 的句柄都<br>一样啊 我用的是win2k + sp3 ,d6编译的
 
我找到啦:<br>前天找了一个函数可以实现,翻译成delphi<br>function SmallestWindowFromPoint(Point: TPoint): HWND;<br>var<br>&nbsp; &nbsp; rect, rectSearch:TRECT;<br> hParentWnd, hWnd, hSearchWnd:THandle;<br>begin<br>&nbsp; &nbsp; hWnd := WindowFromPoint(point);<br>&nbsp; &nbsp; if (hWnd&gt;0)then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; // Get the size and parent for compare later<br> GetWindowRect(hWnd, rect);<br> hParentWnd := GetParent(hWnd);<br><br> // We only search further if the window has a parent<br> if(hParentWnd &gt;0 ) then<br> begin<br> // Search from the window down in the Z-Order<br> hSearchWnd := hWnd;<br> repeat<br> hSearchWnd := GetWindow(hSearchWnd, GW_HWNDNEXT);<br> // Does the search window also contain the point, have the same parent, and is visible?<br> GetWindowRect(hSearchWnd, rectSearch);<br> if(Windows.PtInRect(rectSearch, point) and (GetParent(hSearchWnd) = hParentWnd) and IsWindowVisible(hSearchWnd)) then<br> begin<br> // It does, but is it smaller?<br> if(((rectSearch.right - rectSearch.left) * (rectSearch.bottom - rectSearch.top)) &lt; ((rect.right - rect.left) * (rect.bottom - rect.top))) then<br> begin<br> // Found new smaller window, update compare window<br> hWnd := hSearchWnd;<br> GetWindowRect(hWnd, rect);<br> end;<br> end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; until (hSearchWnd&lt;=0);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; result:= hWnd;<br>end;<br><br>昨天看windows.pas里面有这样一个函数<br>RealChildWindowFromPoint<br>看delphi带的windows sdk ,faint没有!!<br>看定义用吧,kao 可以达到跟上面那个函数一样的效果,白费了我这么都劲!<br><br>今天上msdn里看了看,里面也有这个说明,还是要新版msdn,delphi的帮助真差<br>
 
结束了,谢谢大家
 
后退
顶部