如何将相对对象坐标转换为绝对坐标

时间:2016-03-09 14:15:18

标签: vba ms-access

我在表单上有一个按钮,打开弹出菜单。我需要在按钮下打开此弹出菜单。 ShowPopup函数接受绝对桌面坐标。如果我知道表格上的按钮位置,如何计算绝对坐标?

目前我正在使用这个技巧:

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function GetFocus Lib "user32" () As Long

Private Sub Command1_Click()
    Dim r As RECT
    Dim chwnd As Long
    Dim h As Long

    Me.Text1.SetFocus
    chwnd = GetFocus
    Me.Command1.SetFocus
    h = GetWindowRect(chwnd, r)
    CommandBars("PopupMenu").ShowPopup r.Left, r.Bottom
End Sub

它可以工作,但是在按钮下方的附加TextBox Text1允许使用API​​获得绝对位置并不是真正好的解决方案,想要计算而不是使用人工"书签"

0 个答案:

没有答案