如何得到当前鼠标所在的窗口句柄 ? (100分)

少林

Unregistered / Unconfirmed
GUEST, unregistred user!
用什麽方法得到鼠标当前所在的窗口句柄 ?<br>当前鼠标所在的窗口句柄: 是指Screen中的任意窗口的句柄. <br>
 
Hi 少林:<br>function WindowFromPoint(Point: tpoint): hWnd;
 
建议你先<br>&nbsp; &nbsp;Application.Minimize;//最小化<br>然后<br>&nbsp; &nbsp;GetCursorPos( P1 );//取得鼠标的位置 in windows.pas<br>再<br>&nbsp; &nbsp;Handles := WindowFromPoint( P1 );//取得鼠标所在窗口的句柄 in <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //windows.pas<br>
 
为什么同一个窗口返回值是一个变量 ?<br><br>curWnd := WindowFromPoint(Point(x,y));<br><br>x,y 是鼠标当前的坐标, 当鼠标在同一个窗口中移动(X,Y改变)时,curWnd也改变.
 
返回不同的值应该是正确的, WindowFormPoint返回的是一个hWnd的ID, 也就是一个<br>Windowed Control的把柄, 这个hWnd可能是一个EditBox,ListBox,ClientArea, or Button根据当前点下面的窗体而定.
 
Remarks<br><br>The WindowFromPoint function does not retrieve the handle of a hidden <br>or disabled window, even if the point is within the window. An <br>application should use the ChildWindowFromPoint function for a <br>nonrestrictive search. <br><br>桌面上不同的window中只有一个是enabled的, 那么另外的window通过WindowFromPoint<br>无法取得handle了(尽管point在那个window中)?<br><br>是不是可以通过ChildWindowFromPoint(GetDesktopWindow,point(x,y))取得各个<br>进程的main form的handle呢?<br>
 
eYes: WindowFromPoint可以得到所有可见的Window. 相关的Window可以用下面的<br>函数查询到:<br><br>function GetWindow(Wnd: hWnd; uCmd: byte): hWnd; 得到<br>其中:<br>&nbsp; Wnd //当前window<br>&nbsp; uCmd //关系标志常数, 取值范围如下 <br>GW_CHILD &nbsp; &nbsp; -- 子窗体<br>GW_HWNDFIRST -- 同级窗体中的最前面的<br>GW_HWNDLAST &nbsp;-- 同级窗体中的最后面的<br>GW_HWNDNEXT &nbsp;-- 下一个<br>GW_HWNDPREV &nbsp;-- 前一个<br>GW_OWNER &nbsp; &nbsp;-- 父窗体<br><br>此外Enabled窗体只有一个的说法不正确, Enabled窗体是指那些(不是一个)能够接受<br>键盘鼠标输入的窗体.
 
huizhang说的不错!<br><br><br>huizhang: <br>&nbsp; &nbsp; 你回答我的那个问题能否再给我一些提示? <br>&nbsp; &nbsp; how to import a ActiveX form Acad.tlb to Acad_tlb.ocx? <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; my Email:huiyugan@263.net or huiyugan@163.net <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; but the speed of 163 is slow! <br>&nbsp;
 
接受答案了.
 

Similar threads

回复
0
查看
476
不得闲
回复
0
查看
683
不得闲
回复
0
查看
957
不得闲
S
回复
0
查看
745
SUNSTONE的Delphi笔记
S
顶部