获取任务栏坐标


    Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
        (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Object, ByVal fuWinIni As Long) As Long

    Const SPI_GETWORKAREA As Long = 48

    Public Structure Rect
        Public Left As Long
        Public Top As Long
        Public Right As Long
        Public Bottom As Long
    End Structure

    Public Enum AlignmentConst
        vbLeft = 0
        vbRight = 1
        vbTop = 2
        vbBottom = 3
    End Enum

    Public Function GetWorkArea() As Rect
        'PIXELS

        Dim Result As Long
        Dim WorkArea As Rect

        Result = SystemParametersInfo(SPI_GETWORKAREA, 0&, WorkArea, 0&)
        GetWorkArea = WorkArea
    End Function

    Public Function GetAlignment() As AlignmentConst
        'Find the alignment of the taskbar

        Dim WorkArea As Rect
        Dim Align As AlignmentConst

        WorkArea = GetWorkArea

        If WorkArea.Left <> 0 Then
            'the taskbar MUST be right aligned
            Align = AlignmentConst.vbLeft
        Else
            If WorkArea.Top <> 0 Then
                'The taskbar MUST be bottom aligned
                Align = AlignmentConst.vbTop
            Else
                If (WorkArea.Bottom - WorkArea.Top) = Screen.PrimaryScreen.Bounds.Height Then
                    'If the workarea height is equal to the screen height then
                    'the taskbar MUST be left aligned
                    Align = AlignmentConst.vbRight
                Else
                    Align = AlignmentConst.vbBottom
                End If
            End If
        End If

        GetAlignment = Align
    End Function

    Public Function TaskBarDimensions() As Rect
        'Find out what the taskbars', left, top, right and bottom values are
        'in TWIPS

        Const X = 0
        Const Y = 1

        Dim WorkArea As Rect
        Dim TaskBarDet As Rect
        Dim TwipsPP(2) As Byte 'Twips Per Pixel

        WorkArea = GetWorkArea
        TwipsPP(X) = Screen.PrimaryScreen.Bounds.Left
        TwipsPP(Y) = Screen.PrimaryScreen.Bounds.Top

        'set the taskbars' default values to the screen size
        TaskBarDet.Top = 0
        TaskBarDet.Bottom = Screen.PrimaryScreen.Bounds.Height
        TaskBarDet.Left = 0
        TaskBarDet.Right = Screen.PrimaryScreen.Bounds.Width

        'change the appropiate value according to alignment
        Select Case GetAlignment
            Case AlignmentConst.vbLeft
                TaskBarDet.Right = (WorkArea.Left * TwipsPP(X))
            Case AlignmentConst.vbRight
                TaskBarDet.Left = (WorkArea.Right * TwipsPP(X))
            Case AlignmentConst.vbTop
                TaskBarDet.Bottom = (WorkArea.Top * TwipsPP(Y))
            Case AlignmentConst.vbBottom
                TaskBarDet.Top = (WorkArea.Bottom * TwipsPP(Y))
        End Select

        'return result
        TaskBarDimensions = TaskBarDet
    End Function

转载于:https://www.cnblogs.com/lbnnbs/p/4782066.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值