用vb如何获得windows任务栏的高度大小
 

解决方案 »

  1.   

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End TypeDim R As RECT
    GetWindowRect FindWindow("Shell_TrayWnd", vbNullString), R
    Debug.Print R.Left; R.Top; R.Right; R.Bottom
    在我的机器上输出-2  572  802  602 ,表明任务栏是超出了屏幕范围的.
      

  2.   

    我覺得這個更適合一些。Option ExplicitPrivate Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End TypePrivate Type APPBARDATA
        cbSize As Long
        hwnd As Long
        uCallbackMessage As Long
        uEdge As Long
        rc As RECT
        lParam As Long '  message specific
    End TypePrivate Const ABM_GETTASKBARPOS = &H5Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As LongDim lpData As APPBARDATAPrivate Sub Command1_Click()
        SHAppBarMessage ABM_GETTASKBARPOS, lpData
        With lpData.rc
            Debug.Print "左: " & .Left
            Debug.Print "上: " & .Top
            Debug.Print "寬: " & .Right - .Left
            Debug.Print "高: " & .Bottom - .Top
        End With
    End Sub
      

  3.   

    你可以不用攷慮它的值到底是多少,你只要知道它的這幾個值就可以了。
    .Left      ' 左邊界
    .Top       ' 上邊界
    .Right     ' 右邊界
    .Bottom    ' 下邊界
      

  4.   

    在 windows 經典界面下它的值就是 -2,就像 ColdMooon(月光寒) 說的那樣它是超過屏幕範圍的,我是在 xp 界面下測試的,因此大小適中,如果改爲 windows 經典界面則會出現以下值。
    左: -2
    上: 572
    寬: 804
    高: 30