[VB.NET]控制开始按钮和任务栏

前端之家收集整理的这篇文章主要介绍了[VB.NET]控制开始按钮和任务栏前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
控制开始按钮和任务栏

实例说明

在本实例中,我们将制作一个能够控制开始按钮和任务栏的显示与隐藏功能的应用程序。程序运行结果如图92-1所示。

图92-1 运行结果

技术要点

l 显示/隐藏任务栏

l 显示/隐藏开始按钮

实现过程

■ 新建项目

打开Visual Studio.NET,选择"新建项目",在项目类型窗口中选择"Visual Basic项目",在模板窗口中选择"Windows应用程序",在名称域中输入"ShowStart",然后选择保存路径。单击"确认"。

添加控件

在窗体上添加两个GroupBox控件,在每个GroupBox控件上添加两个RadioButton控件,

■ 设置属性

将窗体和各控件的Text属性设置为和界面一致。

添加代码

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

Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Integer,ByVal nCmdShow As Integer) As Integer

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String,ByVal lpWindowName As String) As Integer

Private Const SW_HIDE As Short = 0

Private Const SW_SHOW As Short = 5

Private Const SW_SHOWNORMAL = 1

Dim hLong As Integer

Dim hwnd As Integer

'显示开始按钮

Private Sub optShowStart_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles optShowStart.Click

If optShowStart.Checked Then

hwnd = FindWindow("Shell_TrayWnd",vbNullString)

hLong = FindWindowEx(hwnd,"Button",Nothing)

ShowWindow(hLong,SW_SHOW)

End If

End Sub

'隐藏开始按钮

Private Sub optHideStart_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles optHideStart.Click

If optHideStart.Checked Then

hwnd = FindWindow("Shell_TrayWnd",SW_HIDE)

End If

End Sub

'隐藏任务栏

Private Sub optHideTask_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles optHideTask.Click

If optHideTask.Checked Then

hwnd = FindWindow("Shell_TrayWnd",vbNullString)

'隐藏任务栏

ShowWindow(hwnd,SW_HIDE)

End If

End Sub

'显示任务栏

Private Sub optShowTask_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles optShowTask.Click

If optShowTask.Checked Then

hwnd = FindWindow("Shell_TrayWnd",vbNullString)

ShowWindow(hwnd,SW_SHOWNORMAL)

End If

End Sub

■ 运行程序

单击菜单"调试|启动"或单击 图标运行程序。

小结

本实例讲述了如何进行显示和隐藏开始按钮或任务栏的方法

原文链接:https://www.f2er.com/vb/264271.html

猜你在找的VB相关文章