获取ACCESS背景区域位置及大小
来源:优易学  2011-12-9 17:43:14   【优易学:中国教育考试门户网】   资料下载   IT书店

Option Compare Database

Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Declare Function apiGetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
Private Declare Function apiReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function apiGetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Const LOGPIXELSX = 88
Private Const LOGPIXELSY = 90
Public Const DIRECTION_VERTICAL = 1
Public Const DIRECTION_HORIZONTAL = 0

Function gFunPixelsToTwips(rlngPixels As Long, rlngDirection As Long) As Long
'像素转换成缇

    On Error GoTo Err_gFunPixelsToTwips
   
    Dim lngDeviceHandle As Long
    Dim lngPixelsPerInch As Long
    lngDeviceHandle = apiGetDC(0)
    If rlngDirection = DIRECTION_HORIZONTAL Then
        lngPixelsPerInch = apiGetDeviceCaps(lngDeviceHandle, LOGPIXELSX)
    Else
        lngPixelsPerInch = apiGetDeviceCaps(lngDeviceHandle, LOGPIXELSY)
    End If
    lngDeviceHandle = apiReleaseDC(0, lngDeviceHandle)
    gFunPixelsToTwips = rlngPixels * 1440 / lngPixelsPerInch
   
Exit_gFunPixelsToTwips:
    On Error Resume Next
    Exit Function
   
Err_gFunPixelsToTwips:
    MsgBox Err.Description, vbExclamation, "提示"
    Resume Exit_gFunPixelsToTwips
   
End Function

'建个窗体,用按钮测试

Private Sub Command0_Click()
'获取ACCESS背景区域位置及大小

    Dim intTop As Long, intLeft As Long, intWidth As Long, intHeight As Long
    Dim lngRet As Long, Rc As RECT, HwndMDI As Long
    HwndMDI = FindWindowEx(Application.hWndAccessApp, 0&, "MDIClient", "")
    lngRet = GetWindowRect(HwndMDI, Rc)
    With Rc
        .Right = .Right - .Left
        .Bottom = .Bottom - .Top
        '把取出的像素值转化成缇值
        intTop = gFunPixelsToTwips(.Top, DIRECTION_VERTICAL)
        intLeft = gFunPixelsToTwips(.Left, DIRECTION_HORIZONTAL)
        intWidth = gFunPixelsToTwips(.Right, DIRECTION_HORIZONTAL)
        intHeight = gFunPixelsToTwips(.Bottom, DIRECTION_VERTICAL)
        Debug.Print "Top像素值", .Top
        Debug.Print "Left像素值", .Left
        Debug.Print "Right像素值", .Right
        Debug.Print "bottom像素值", .Bottom
        Debug.Print "Top缇值", intTop
        Debug.Print "Left缇值", intLeft
        Debug.Print "Right缇值", intWidth
        Debug.Print "bottom缇值", intHeight
    End With

End Sub

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训