Foxtable(狐表)用户栏目专家坐堂 → [求助] 在文本框的当前输入位置打开独立窗口


  共有1815人关注过本帖树形打印复制链接

主题:[求助] 在文本框的当前输入位置打开独立窗口

帅哥哟,离线,有人找我吗?
大红袍
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/12/18 17:06:00 [显示全部帖子]

mark 获取焦点坐标

 

全局代码

 

#Region "得到光标在屏幕上的位置"
<DllImport("user32")> _
Public Function GetCaretPos(ByRef lpPoint As Point) As Boolean
End Function
<DllImport("user32.dll")> _
Public Function GetForegroundWindow() As IntPtr
End Function
<DllImport("user32.dll")> _
Public Function GetFocus() As IntPtr
End Function
<DllImport("user32.dll")> _
Public Function AttachThreadInput(idAttach As IntPtr, idAttachTo As IntPtr, fAttach As Integer) As IntPtr
End Function
<DllImport("user32.dll")> _
Public Function GetWindowThreadProcessId(hWnd As IntPtr, ProcessId As IntPtr) As IntPtr
End Function
<DllImport("kernel32.dll")> _
Public Function GetCurrentThreadId() As IntPtr
End Function
<DllImport("user32.dll")> _
Public Sub ClientToScreen(hWnd As IntPtr, ByRef p As Point)
End Sub

Public Function CaretPos() As Point
Dim ptr As IntPtr = GetForegroundWindow()
Dim p As New Point()

'得到Caret在屏幕上的位置
If ptr.ToInt32() <> 0 Then
    Dim targetThreadID As IntPtr = GetWindowThreadProcessId(ptr, IntPtr.Zero)
    Dim localThreadID As IntPtr = GetCurrentThreadId()
   
    'If localThreadID <> targetThreadID Then
        AttachThreadInput(localThreadID, targetThreadID, 1)
        ptr = GetFocus()
        If ptr.ToInt32() <> 0 Then
            GetCaretPos(p)
            ClientToScreen(ptr, p)
        End If
        AttachThreadInput(localThreadID, targetThreadID, 0)
    'End If
End If
Return p
End Function
#End Region


 

调用代码

 

Dim p = CaretPos()
msgbox(p.x & " " & p.y)


 回到顶部