|
供参考:
Private Declare Sub SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Const SM_CYCAPTION = 4 '标题高度
Const SM_CXFRAME = 32 '可调边框宽度
Const SM_CYFRAME = 33 ''可调边框高度
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim FrmHwnd As Long
Dim Rec As RECT
'获得整个窗口的范围矩形
GetWindowRect Me.hwnd, Rec
'假设Command7在窗体主体上的某个控件(这里不考虑页眉)
'则Command7的Left坐标为:
Rec.Left = Rec.Left + (Me.Command7.Left / 15) + GetSystemMetrics(SM_CXFRAME)
'则Command7的Top坐标为:
Rec.Top = Rec.Top + (Me.Command7.Top + Me.Command7.Height) / 15 + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME)
'这里以打开"选择"窗体作例子
DoCmd.OpenForm "选择", acNormal
'取得"选择"窗体的句柄
FrmHwnd = Forms!选择.hwnd
'重置"选择"窗体位置
SetWindowPos FrmHwnd, HWND_TOPMOST, Rec.Left, Rec.Top, 0, 0, SWP_NOSIZE |
|