以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  求助,能不能获取窗口的位置?并跟随?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=139041)

--  作者:zto001
--  发布时间:2019/8/4 9:24:00
--  求助,能不能获取窗口的位置?并跟随?
求助,能不能获取窗口的位置?并跟随?
--  作者:有点蓝
--  发布时间:2019/8/4 20:50:00
--  
e.form.top
e.form.left

--  作者:zto001
--  发布时间:2019/8/5 18:44:00
--  
是第三方的窗口,比如qq、微信。获取他的位置,然后我在指定窗口的位置达到跟随的效果
--  作者:有点蓝
--  发布时间:2019/8/5 20:22:00
--  
http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=139043&skin=0
--  作者:zto001
--  发布时间:2019/8/6 12:37:00
--  
窗口找到了
然后怎么获取位置?
Dim hwnd As IntPtr = FindWindow(Nothing, "钉钉")
If hwnd <> IntPtr.Zero Then
    msgbox("找到窗口")

End If

--  作者:有点蓝
--  发布时间:2019/8/6 14:04:00
--  
需要调用系统api,系统api相关用法请自行百度解决:https://blog.csdn.net/lidawei201/article/details/9183163
--  作者:zto001
--  发布时间:2019/8/6 21:17:00
--  
API函数getWindowRect()的定义

Private Declare Auto Function GetWindowRect Lib "user32" (ByVal hwnd As IntPtr, ByVal lpRect As RECT) As Long

位置信息结构体

    Public Structure RECT
        Public left As Int32
        Public top As Int32
        Public right As Int32
        Public bottom As Int32
    End Structure

调用

GetWindowRect(Me.Handle, p1)

问题描述:

使用GetWindowRect函数来获取窗体的位置信息时,RECT中的left ,top ,right ,bottom 都是0




产生问题的原因:
API传递结构一般不用ByVal

解决方案:
ByVal lpRect As RECT改成ByRef lpRect As RECT



没看懂

--  作者:zto001
--  发布时间:2019/8/6 21:18:00
--  
全局代码
    Public Structure RECT
        Public left As Int32
        Public top As Int32
        Public right As Int32
        Public bottom As Int32
    End Structure


其他就都没看懂了


--  作者:zto001
--  发布时间:2019/8/7 11:29:00
--  
Private Declare Auto Function GetWindowRect Lib "user32" (ByVal hwnd As IntPtr, ByVal lpRect As RECT) As Long
  Public Structure RECT
        Public left As Int32
        Public top As Int32
        Public right As Int32
        Public bottom As Int32
    End Structure


我把上面放在全局代码里面,执行
GetWindowRect(Me.Handle, p1)提示错误
未声明GetWindowRect

--  作者:有点蓝
--  发布时间:2019/8/7 11:56:00
--  
Windows api的用法请自行百度学习解决