Discuz!NT
欢迎 游客 , 注册 | 登录 | 会员 | 界面 | 简洁版本 | 在线 | 帮助
商都网教育宝典宝库

发表新主题 回复该主题
本主题被查看241次, 共1个帖子, 1页, 当前为第1页     选择页数: 1      跳转到第   上一主题   下一主题
标题: 获取ACCESS背景区域位置及大小
-[尕硴]
超级版主
UID: 71
来自:
精华: 130
积分: 14003
帖子: 12909
注册: 2007-10-22 17:59:00
状态: 离线
威望: 444.00
金钱: 3355.00 元
只看楼主 2008-04-11 14:31
获取ACCESS背景区域位置及大小
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
#1  
发表新主题 回复该主题
本主题被查看241次, 共1个帖子, 1页, 当前为第1页     选择页数: 1      跳转到第







现在的时间是 2008-07-06 03:10:55

版权所有 商都网教育宝典
         Powered by Discuz!NT 1.0.6666    Copyright © 2001-2008 Comsenz Inc.
Processed in 0.032 seconds