vb.net用API函数getWindowRect()获取窗体位置信息失败解决

来源:互联网 发布:悟 无人机 知乎 编辑:程序博客网 时间:2024/05/18 15:57

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