实例说明@H_404_1@
在本实例中,我们将制作一个能够控制开始按钮和任务栏的显示与隐藏功能的应用程序。程序运行结果如图92-1所示。@H_404_1@
图92-1 运行结果@H_404_1@
技术要点@H_404_1@
实现过程@H_404_1@
■ 新建项目@H_404_1@
打开Visual Studio.NET,选择"新建项目",在项目类型窗口中选择"Visual Basic项目",在模板窗口中选择"Windows应用程序",在名称域中输入"ShowStart",然后选择保存路径。单击"确认"。@H_404_1@
在窗体上添加两个GroupBox控件,在每个GroupBox控件上添加两个RadioButton控件,@H_404_1@
将窗体和各控件的Text属性设置为和界面一致。@H_404_1@
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer,ByVal hWnd2 As Integer,ByVal lpsz1 As String,ByVal lpsz2 As String) As Integer@H_404_1@
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Integer,ByVal nCmdShow As Integer) As Integer@H_404_1@
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String,ByVal lpWindowName As String) As Integer@H_404_1@
Private Const SW_HIDE As Short = 0@H_404_1@
Private Const SW_SHOW As Short = 5@H_404_1@
Private Const SW_SHOWNORMAL = 1@H_404_1@
Dim hLong As Integer@H_404_1@
Dim hwnd As Integer@H_404_1@
Private Sub optShowStart_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles optShowStart.Click@H_404_1@
If optShowStart.Checked Then@H_404_1@
hwnd = FindWindow("Shell_TrayWnd",vbNullString)@H_404_1@
hLong = FindWindowEx(hwnd,"Button",Nothing)@H_404_1@
ShowWindow(hLong,SW_SHOW)@H_404_1@
End If@H_404_1@
End Sub@H_404_1@
'隐藏开始按钮@H_404_1@
Private Sub optHideStart_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles optHideStart.Click@H_404_1@
If optHideStart.Checked Then@H_404_1@
hwnd = FindWindow("Shell_TrayWnd",SW_HIDE)@H_404_1@
End If@H_404_1@
End Sub@H_404_1@
'隐藏任务栏@H_404_1@
Private Sub optHideTask_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles optHideTask.Click@H_404_1@
If optHideTask.Checked Then@H_404_1@
hwnd = FindWindow("Shell_TrayWnd",vbNullString)@H_404_1@
'隐藏任务栏@H_404_1@
ShowWindow(hwnd,SW_HIDE)@H_404_1@
End If@H_404_1@
End Sub@H_404_1@
Private Sub optShowTask_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles optShowTask.Click@H_404_1@
If optShowTask.Checked Then@H_404_1@
hwnd = FindWindow("Shell_TrayWnd",vbNullString)@H_404_1@
ShowWindow(hwnd,SW_SHOWNORMAL)@H_404_1@
End If@H_404_1@
End Sub@H_404_1@
■ 运行程序@H_404_1@
单击菜单"调试|启动"或单击 图标运行程序。@H_404_1@
小结@H_404_1@