L lsjkiki Unregistered / Unconfirmed GUEST, unregistred user! 2007-10-29 #1 “光标所在”的位置的控件句柄。<br>就是光标闪烁的地方的句柄,一般是edit,如何得到句柄,或者类名,<br>不是鼠标所在的地方的句柄。<br>用这个函数的GetCursorPos(pt) 别来;<br>望高手指点。。。[]
“光标所在”的位置的控件句柄。<br>就是光标闪烁的地方的句柄,一般是edit,如何得到句柄,或者类名,<br>不是鼠标所在的地方的句柄。<br>用这个函数的GetCursorPos(pt) 别来;<br>望高手指点。。。[]
L lsjkiki Unregistered / Unconfirmed GUEST, unregistred user! 2007-10-29 #3 就是写一个程序 来判断当前键盘光标 所在的窗口和 控件句柄 类名。
暗 暗夜中独舞 Unregistered / Unconfirmed GUEST, unregistred user! 2007-11-02 #5 {<br> 当光标被另外一个线程掌握时,就无法用GetCursor()应用接口获得光标句柄。<br> 本文阐述如何在任何线程掌握光标时都能够获取光标句柄。<br> 例如,想在屏幕截取程序中放置光标时该如何做。<br>}<br><br>function GetCursorHandle: HCURSOR;<br>var<br> hWindow: HWND;<br> pt: TPoint;<br> pIconInfo: TIconInfo;<br> dwThreadID, dwCurrentThreadID: DWORD;<br>begin<br> // 检查哪个窗体掌握光标<br> GetCursorPos(pt);<br> hWindow := WindowFromPoint(pt);<br><br> // 获得光标所有者的线程ID<br> dwThreadID := GetWindowThreadProcessId(hWindow, nil);<br><br> // 获得当前线程的ID<br> dwCurrentThreadID := GetCurrentThreadId;<br><br> // 如果光标所有者的线程不是当前线程,就要把光标所有者的线程配属到当前线程。<br> //然后调用GetCursor()来获得正确的光标句柄(hCursor)。<br><br> if (dwCurrentThreadID <> dwThreadID) then<br> begin<br> if AttachThreadInput(dwCurrentThreadID, dwThreadID, True) then<br> begin<br> // 获得光标句柄<br> Result := GetCursor;<br> AttachThreadInput(dwCurrentThreadID, dwThreadID, False);<br> end;<br> end else<br> begin<br> Result := GetCursor;<br> end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> CurPosX, CurPoxY: Integer;<br> MyCursor: TIcon;<br> pIconInfo: TIconInfo;<br>begin<br> MyCursor := TIcon.Create;<br> try<br> MyCursor.Handle := GetCursorHandle;<br> // 获得光标位置<br> GetIconInfo(MyCursor.Handle, pIconInfo);<br> CurPosX := pIconInfo.xHotspot;<br> CurPoxY := pIconInfo.yHotspot;<br> // 在窗体上画出光标<br> Canvas.Draw(CurPoxY, CurPoxY, MyCursor);<br> finally<br> MyCursor.ReleaseHandle;<br> MyCursor.Free;<br> end;<br>end;<br><br>// 另外一种解决办法:<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br> CI: TCursorInfo;<br>begin<br> CI.cbSize := SizeOf(CI);<br> GetCursorInfo(CI);<br> Image1.Picture.Icon.Handle := CI.hCursor;<br>end;
{<br> 当光标被另外一个线程掌握时,就无法用GetCursor()应用接口获得光标句柄。<br> 本文阐述如何在任何线程掌握光标时都能够获取光标句柄。<br> 例如,想在屏幕截取程序中放置光标时该如何做。<br>}<br><br>function GetCursorHandle: HCURSOR;<br>var<br> hWindow: HWND;<br> pt: TPoint;<br> pIconInfo: TIconInfo;<br> dwThreadID, dwCurrentThreadID: DWORD;<br>begin<br> // 检查哪个窗体掌握光标<br> GetCursorPos(pt);<br> hWindow := WindowFromPoint(pt);<br><br> // 获得光标所有者的线程ID<br> dwThreadID := GetWindowThreadProcessId(hWindow, nil);<br><br> // 获得当前线程的ID<br> dwCurrentThreadID := GetCurrentThreadId;<br><br> // 如果光标所有者的线程不是当前线程,就要把光标所有者的线程配属到当前线程。<br> //然后调用GetCursor()来获得正确的光标句柄(hCursor)。<br><br> if (dwCurrentThreadID <> dwThreadID) then<br> begin<br> if AttachThreadInput(dwCurrentThreadID, dwThreadID, True) then<br> begin<br> // 获得光标句柄<br> Result := GetCursor;<br> AttachThreadInput(dwCurrentThreadID, dwThreadID, False);<br> end;<br> end else<br> begin<br> Result := GetCursor;<br> end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> CurPosX, CurPoxY: Integer;<br> MyCursor: TIcon;<br> pIconInfo: TIconInfo;<br>begin<br> MyCursor := TIcon.Create;<br> try<br> MyCursor.Handle := GetCursorHandle;<br> // 获得光标位置<br> GetIconInfo(MyCursor.Handle, pIconInfo);<br> CurPosX := pIconInfo.xHotspot;<br> CurPoxY := pIconInfo.yHotspot;<br> // 在窗体上画出光标<br> Canvas.Draw(CurPoxY, CurPoxY, MyCursor);<br> finally<br> MyCursor.ReleaseHandle;<br> MyCursor.Free;<br> end;<br>end;<br><br>// 另外一种解决办法:<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br> CI: TCursorInfo;<br>begin<br> CI.cbSize := SizeOf(CI);<br> GetCursorInfo(CI);<br> Image1.Picture.Icon.Handle := CI.hCursor;<br>end;
L lsjkiki Unregistered / Unconfirmed GUEST, unregistred user! 2007-11-05 #6 请认真看题目,用GetCursorPos(pt);<br>就是错的,我要的是键盘闪烁的光标的位置,和鼠标的光标没有任何关系。。<br>[]<br>在这样就要扣分了。。。哈哈~~!!!!!!!!!!<br>再顶,希望有高手出来解决!
请认真看题目,用GetCursorPos(pt);<br>就是错的,我要的是键盘闪烁的光标的位置,和鼠标的光标没有任何关系。。<br>[]<br>在这样就要扣分了。。。哈哈~~!!!!!!!!!!<br>再顶,希望有高手出来解决!
X xubin4456 Unregistered / Unconfirmed GUEST, unregistred user! 2007-11-11 #10 楼主的意思应该是取得被激活控件的句柄[]<br><br>可以这样用 findwindowEX 找到窗体句柄,然后遍历窗体上所有的控件,用 IsWindowEnabled 来判断该控件是否被激活就OK了,拿分来~[]<br><br>或者用消息来获取 E N _ S E T F O C U S编辑框获得输入焦点。
楼主的意思应该是取得被激活控件的句柄[]<br><br>可以这样用 findwindowEX 找到窗体句柄,然后遍历窗体上所有的控件,用 IsWindowEnabled 来判断该控件是否被激活就OK了,拿分来~[]<br><br>或者用消息来获取 E N _ S E T F O C U S编辑框获得输入焦点。
A ANiDelphi Unregistered / Unconfirmed GUEST, unregistred user! 2007-11-11 #11 GetFocus();<br>The GetFocus function retrieves the handle of the window that has the keyboard focus, if the window is associated with the calling thread's message queue. <br><br>HWND GetFocus(VOID)<br> <br><br>Parameters<br><br>This function has no parameters. <br><br>Return Values<br><br>If the function succeeds, the return value is the handle of the window with the keyboard focus. If the calling thread's message queue does not have an associated window with the keyboard focus, the return value is NULL. <br><br>Remarks<br><br>Even if GetFocus returns NULL, another thread's queue may be associated with a window that has the keyboard focus. <br>Use the GetForegroundWindow function to retrieve the handle to the window with which the user is currently working. You can associate your thread's message queue with the windows owned by another thread by using the AttachThreadInput function. <br><br>下面这几个API应该能实现,不过没试过<br>GetForegroundWindow<br>GetWindowThreadProcessId<br>GetCurrentThreadId<br>AttachThreadInput<br>GetFocus
GetFocus();<br>The GetFocus function retrieves the handle of the window that has the keyboard focus, if the window is associated with the calling thread's message queue. <br><br>HWND GetFocus(VOID)<br> <br><br>Parameters<br><br>This function has no parameters. <br><br>Return Values<br><br>If the function succeeds, the return value is the handle of the window with the keyboard focus. If the calling thread's message queue does not have an associated window with the keyboard focus, the return value is NULL. <br><br>Remarks<br><br>Even if GetFocus returns NULL, another thread's queue may be associated with a window that has the keyboard focus. <br>Use the GetForegroundWindow function to retrieve the handle to the window with which the user is currently working. You can associate your thread's message queue with the windows owned by another thread by using the AttachThreadInput function. <br><br>下面这几个API应该能实现,不过没试过<br>GetForegroundWindow<br>GetWindowThreadProcessId<br>GetCurrentThreadId<br>AttachThreadInput<br>GetFocus
R rtl Unregistered / Unconfirmed GUEST, unregistred user! 2007-11-14 #13 先 GetCursorPos 得到光标的位置<br>再 WindowFromPoint 得到光标下窗口的句柄<br><br>------------------------<br>www.waibaoinfo.com
先 GetCursorPos 得到光标的位置<br>再 WindowFromPoint 得到光标下窗口的句柄<br><br>------------------------<br>www.waibaoinfo.com