获取屏幕工作区、定位任务栏、窗口置顶

Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type


' 获取屏幕工作区大小用
Declare Function SystemParametersInfo& Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long)

' 窗口置顶用
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Public Function GetTaskbarHeight() As Integer
    Dim lRes As Integer
    Dim rectVal As RECT
    lRes = SystemParametersInfo(SPI_GETWORKAREA, 0, rectVal, 0)
    GetTaskbarHeight = (Screen.Height / Screen.TwipsPerPixelY - rectVal.Bottom) * Screen.TwipsPerPixelY
End Function


'Private Sub Form_Resize() ' 窗口置顶
'    SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
'End Sub

'Private Sub Form_Initialize() ' 设置窗口在任务栏上方
'    Me.Top = Screen.Height - GetTaskbarHeight() - Me.Height
'    Me.Left = Screen.Width - Me.Width
'End Sub

原文地址:https://www.cnblogs.com/lbnnbs/p/4784607.html