比如:知道picturebox1、form1的句柄,如何确定Picturebox1在form1的位置,要用API函数,在容器套容器的复杂情况下,这样更直接些,希望大家帮助一下。

解决方案 »

  1.   


    '获得整个窗口的范围矩形
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End TypePrivate Sub Command1_Click()
        Dim myRect As RECT    GetWindowRect From1.Picture1.hwnd, myRect
        Me.Print myRect.Top
        Me.Print myRect.Left
        Me.Print myRect.Bottom
        Me.Print myRect.Right
    End Sub
      

  2.   

    Private Sub Command1_Click()
        Dim rc As RECT
        GetWindowRect Picture2.hWnd, rc
        MapWindowPoints 0, Me.hWnd, rc, 2
        Debug.Print rc.Left, rc.Top, rc.Right, rc.bottom
    End Sub