vb6 用代码让窗体在任务栏的上方显示
时间: 2024-02-13 18:06:57 浏览: 174
可以使用以下代码让 VB6 窗体在任务栏的上方显示:
```vb
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Const SPI_GETWORKAREA = 48
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
'获取任务栏高度
Dim taskbarHeight As Long
Dim rc As RECT
Call SystemParametersInfo(SPI_GETWORKAREA, 0, rc, 0)
taskbarHeight = Screen.Height - (rc.Bottom - rc.Top)
'设置窗体在任务栏上方显示
Me.WindowState = vbNormal
Me.Top = -taskbarHeight
Me.Left = (Screen.Width - Me.Width) / 2
End Sub
```
首先,通过调用 SystemParametersInfo 函数获取任务栏的高度。然后,将窗体的状态设置为 vbNormal,将窗体的 Top 属性设置为任务栏高度的负值,这样窗体就会在任务栏的上方显示。最后,为了让窗体居中显示,还需要将窗体的 Left 属性设置为屏幕宽度减去窗体宽度的一半。这样窗体就会在任务栏的上方居中显示。
阅读全文