gpt4 book ai didi

ms-access - 如何在 MS-Access 中找到父窗口的宽度

转载 作者:行者123 更新时间:2023-12-04 16:37:37 25 4
gpt4 key购买 nike

我试图强制 MS-Access 窗体相对于主窗口的右边缘占据某个位置(实际上我想将它居中,但我也可以看到想要将它停靠在一侧或另一侧)。我可以用 Me.Move 重新定位这个表单,例如,

    Me.Move newWindowLeft, newWindowTop, newWidth, newHeight

但是,我怎样才能知道父窗口的宽度?

最佳答案

您可以使用 Windows API:

(更新以返回缇)

Type Rect
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type

Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As Rect) As Long

Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long

Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long

Const LOGPIXELSX = 88
Const LOGPIXELSY = 90
Const DIRECTION_VERTICAL = 1
Const DIRECTION_HORIZONTAL = 0

Public Function GetMainWindowSize()

Dim MDIRect As Rect
Dim lWidthPixels As Long
Dim lWidthTwips As Long

' Get the screen coordinates and window size of the MDIClient area'
GetClientRect Application.hWndAccessApp, MDIRect

lWidthPixels = MDIRect.x2 - MDIRect.x1
lWidthTwips = PixelsToTwips(lWidthPixels, DIRECTION_HORIZONTAL)

MsgBox "Width (Pixels) = " & lWidthPixels & " Width (Twips) = " & lWidthTwips

End Function


Function PixelsToTwips(lPixels As Long, lDirection As Long) As Long

Dim lDeviceHandle As Long
Dim lPixelsPerInch As Long

lDeviceHandle = GetDC(0)

If lDirection = DIRECTION_HORIZONTAL Then
lPixelsPerInch = GetDeviceCaps(lDeviceHandle, LOGPIXELSX)
Else

lPixelsPerInch = GetDeviceCaps(lDeviceHandle, LOGPIXELSY)
End If

lDeviceHandle = ReleaseDC(0, lDeviceHandle)

PixelsToTwips = lPixels * 1440 / lPixelsPerInch

End Function

关于ms-access - 如何在 MS-Access 中找到父窗口的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1290125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com