获取任务栏坐标


    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

你可能感兴趣的:(获取任务栏坐标)