答案:完整的示例如下,希望对你有所帮助
现在窗体上添加2个按钮.
然后写入以下代码:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const SW_SHOW = 5
Private Const SW_HIDE = 0
Private Sub Command1_Click()
Dim task As Long, start As Long
task = FindWindow("Shell_TrayWnd", "")
start = FindWindowEx(task, 0, "Button", vbNullString)
Call ShowWindow(start, SW_HIDE) '隐藏
End Sub
Private Sub Command2_Click()
Dim task As Long, start As Long
task = FindWindow("Shell_TrayWnd", "")
start = FindWindowEx(task, 0, "Button", vbNullString)
Call ShowWindow(start, SW_SHOW) '显示
End SubPrivate Declare Function FindWindowEx Lib "user32" Alias _
"FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As _
Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal _
hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Const SW_HIDE = 0
Const SW_SHOW = 5
Dim bx As Boolean
Private Sub Form_Click()
Dim hLong As Long
Dim hwnd As Long
hwnd = FindWindow("Shell_TrayWnd", VBNullString)
hLong = FindWindowEx(hwnd, 0, "Button", VBNull String)
If bx Then
ShowWindow hLong, SW_SHOW
bx = False
Else
ShowWindow hLong, SW_HIDE
bx = True
End If
End Sub
还可以加入屏蔽键盘视窗键(win键)的代码,将更完美!
上一个:关于VB建立注册表问题
下一个:VB语言是什么?