隐藏任务栏和开始按钮windows 7 32位vb.net
我试图在我的应用程序打开时隐藏任务栏和“开始”按钮,并在关闭时重新显示它们。对于64位版本的应用程序,我设法做到了这一点,但当我在目标cpu的visual studio中将其设置为32位时,我得到了一个异常“算术运算导致溢出” 以下是我在64位上使用和使用的方法隐藏任务栏和开始按钮windows 7 32位vb.net,vb.net,Vb.net,我试图在我的应用程序打开时隐藏任务栏和“开始”按钮,并在关闭时重新显示它们。对于64位版本的应用程序,我设法做到了这一点,但当我在目标cpu的visual studio中将其设置为32位时,我得到了一个异常“算术运算导致溢出” 以下是我在64位上使用和使用的方法 Public Class frmShowHideStartBar Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdS
Public Class frmShowHideStartBar
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
Private Const SW_HIDE = 0
Private Const SW_SHOW = 1
Public Function HideStartButton() As Boolean
Dim retval = False
Try
HideTaskBar()
Dim hwndStartButton = FindWindow("Button", "Start")
If hwndStartButton <> IntPtr.Zero Then
retval = ShowWindow(hwndStartButton, SW_HIDE)
End If
Catch ex As Exception
MsgBox("HideStartButton " + ex.Message)
End Try
Return retval
End Function
Public Function HideTaskBar() As Boolean
Dim retval = False
Try
Dim hwndTaskBar = FindWindow("Shell_TrayWnd", "")
If hwndTaskBar <> IntPtr.Zero Then
retval = ShowWindow(hwndTaskBar, SW_HIDE)
End If
Catch ex As Exception
MsgBox("HideTaskBar " + ex.Message)
End Try
Return retval
End Function
Public Function ShowStartButton() As Boolean
Dim retval1 = False
Try
ShowHideTaskBar()
Dim hwndstartbutton = FindWindow("Button", "Start")
If hwndstartbutton <> IntPtr.Zero Then
retval1 = ShowWindow(hwndstartbutton, SW_SHOW)
End If
Catch ex As Exception
MsgBox("ShowStartButton " + ex.Message)
End Try
Return retval1
End Function
Public Function ShowHideTaskBar() As Boolean
Dim retval2 = False
Try
Dim hwndTaskBar = FindWindow("Shell_TrayWnd", "")
If hwndTaskBar <> IntPtr.Zero Then
retval2 = ShowWindow(hwndTaskBar, SW_SHOW)
End If
Catch ex As Exception
MsgBox("ShowHideTaskBar " + ex.Message)
End Try
Return retval2
End Function
End Class
公共类frmShowHideStartBar
私有声明函数ShowWindow Lib“user32”(ByVal hwnd为Long,ByVal nCmdShow为Long)为Long
私有声明函数findwindowlib“user32”别名“FindWindowA”(ByVal lpClassName作为字符串,ByVal lpWindowName作为字符串),长度为
私有常量SW_HIDE=0
私人施工SW_SHOW=1
公共函数HideStartButton()为布尔值
Dim retval=False
尝试
HideTaskBar()
Dim hwndStartButton=FindWNDOW(“按钮”、“开始”)
如果hwndStartButton IntPtr.Zero,则
retval=ShowWindow(hwndStartButton,SW_隐藏)
如果结束
特例
MsgBox(“HideStartButton”+ex.Message)
结束尝试
返回返回
端函数
作为布尔值的公共函数HideTaskBar()
Dim retval=False
尝试
Dim hwndTaskBar=FindWindow(“Shell\u TrayWnd”,”)
如果hwndTaskBar IntPtr.Zero,则
retval=ShowWindow(hwndTaskBar,SW_隐藏)
如果结束
特例
MsgBox(“HideTaskBar”+ex.Message)
结束尝试
返回返回
端函数
公共函数ShowStartButton()为布尔值
Dim retval1=错误
尝试
ShowHideTaskBar()
Dim hwndstartbutton=FindWNDOW(“按钮”、“开始”)
如果hwndstartbutton IntPtr.Zero,则
retval1=显示窗口(hwndstartbutton,SW_SHOW)
如果结束
特例
MsgBox(“ShowStartButton”+ex.Message)
结束尝试
归还租金1
端函数
公共函数ShowHideTaskBar()为布尔值
Dim retval2=错误
尝试
Dim hwndTaskBar=FindWindow(“Shell\u TrayWnd”,”)
如果hwndTaskBar IntPtr.Zero,则
retval2=ShowWindow(hwndTaskBar,SW_SHOW)
如果结束
特例
MsgBox(“ShowHideTaskBar”+ex.Message)
结束尝试
归还2
端函数
末级
我尝试将它们设置为整数而不是long,它对隐藏有效,但对取消隐藏无效。
有没有关于如何使用32位的方法的想法?不要按照您尝试的方式来做!你工作太辛苦了,只是在乞求虫子
有:如果你想创建一个覆盖任务栏的全屏窗口,那么就这样做,让任务栏自动离开。链接博客帖子解释了所有的细节,但是代码是用C++编写的,如果你正在编写VB.NET .< /P>,这可能是很难理解的。
幸运的是,WinForms框架很好地包装了这一切。您只需执行以下操作:
Public Class frmFullScreen
Public Sub MakeFullScreen()
' Hide the window borders.
Me.FormBorderStyle = FormBorderStyle.None
' Change the size and location of the form so that it fills entire screen.
' (This works correctly with multiple monitors; the form fills the screen that it is on or closest to.)
Dim rect As Rectangle = Screen.GetBounds(Me)
Me.Location = rect.Location
Me.Size = rect.Size
End Sub
Public Sub MakeNormal()
' Restore the standard window borders (or any other style you like).
Me.FormBorderStyle = FormBorderStyle.Sizable
' Change the form's size back to its default size, and
' set the location automatically by centering it.
Me.Size = Me.DefaultSize
Me.CenterToScreen()
End Sub
End Class
经过全面测试,工作正常,即使有多个监视器。当全屏显示时,表单会覆盖整个屏幕,包括任务栏、开始菜单和其他任何碰巧出现的内容
要启动它,请添加一个按钮或其他东西,以便您可以连接其事件处理程序来调用
MakeFullScreen
和/或MakeNormal
方法。下面是一个在Win7上应该可以正常工作的语言扩展方法
用法
扩展
Module FormExtensions
Private Declare Function SetWindowPos Lib "user32.dll" _
Alias "SetWindowPos" (ByVal hWnd As IntPtr,
ByVal hWndIntertAfter As IntPtr,
ByVal X As Integer,
ByVal Y As Integer,
ByVal cx As Integer,
ByVal cy As Integer,
ByVal uFlags As Integer) As Boolean
Private HWND_TOP As IntPtr = IntPtr.Zero
Private Const SWP_SHOWWINDOW As Integer = 64
''' <summary>
''' Place form into full screen
''' </summary>
''' <param name="sender"></param>
''' <param name="TaskBar">True to hide Windows TaskBar</param>
''' <remarks></remarks>
<System.Runtime.CompilerServices.Extension()> _
Public Sub FullScreen(ByVal sender As Form, ByVal TaskBar As Boolean)
sender.WindowState = FormWindowState.Maximized
sender.FormBorderStyle = FormBorderStyle.None
sender.TopMost = True
If TaskBar Then
SetWindowPos(sender.Handle, HWND_TOP, 0, 0,
Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
SWP_SHOWWINDOW _
)
End If
End Sub
''' <summary>
''' Restore to original size/position
''' </summary>
''' <param name="sender"></param>
''' <remarks></remarks>
<System.Runtime.CompilerServices.Extension()> _
Public Sub NormalMode(ByVal sender As Form)
sender.WindowState = FormWindowState.Normal
sender.FormBorderStyle = FormBorderStyle.FixedSingle
sender.TopMost = True
End Sub
End Module
模块表单扩展
私有声明函数SetWindowPos Lib“user32.dll”_
别名“SetWindowPos”(ByVal hWnd作为IntPtr,
ByVal HwnIntertafter作为IntPtr,
ByVal X作为整数,
ByVal Y作为整数,
ByVal cx作为整数,
ByVal cy作为整数,
ByVal uFlags(作为整数)作为布尔值
私有HWND_TOP作为IntPtr=IntPtr.Zero
私有常量SWP_显示窗口为整数=64
'''
''将窗体置于全屏
'''
'''
''真以隐藏Windows任务栏
'''
_
公共子全屏(ByVal发送器作为表单,ByVal任务栏作为布尔值)
sender.WindowsState=FormWindowsState.Maximized
sender.FormBorderStyle=FormBorderStyle.None
sender.topmest=True
如果是的话
设置窗口位置(发送器手柄、HWND_顶部、0、0、,
Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
SWP_展示窗口_
)
如果结束
端接头
'''
''恢复到原始尺寸/位置
'''
'''
'''
_
公共次正常模式(ByVal发送方作为表单)
sender.WindowsState=FormWindowsState.Normal
sender.FormBorderStyle=FormBorderStyle.FixedSingle
sender.topmest=True
端接头
端模块
这可能是一个错误,您不想隐藏任务栏/菜单,而是想隐藏它。如果应用程序崩溃,用户将如何恢复任务栏/开始菜单?您在哪一行看到错误?
Module FormExtensions
Private Declare Function SetWindowPos Lib "user32.dll" _
Alias "SetWindowPos" (ByVal hWnd As IntPtr,
ByVal hWndIntertAfter As IntPtr,
ByVal X As Integer,
ByVal Y As Integer,
ByVal cx As Integer,
ByVal cy As Integer,
ByVal uFlags As Integer) As Boolean
Private HWND_TOP As IntPtr = IntPtr.Zero
Private Const SWP_SHOWWINDOW As Integer = 64
''' <summary>
''' Place form into full screen
''' </summary>
''' <param name="sender"></param>
''' <param name="TaskBar">True to hide Windows TaskBar</param>
''' <remarks></remarks>
<System.Runtime.CompilerServices.Extension()> _
Public Sub FullScreen(ByVal sender As Form, ByVal TaskBar As Boolean)
sender.WindowState = FormWindowState.Maximized
sender.FormBorderStyle = FormBorderStyle.None
sender.TopMost = True
If TaskBar Then
SetWindowPos(sender.Handle, HWND_TOP, 0, 0,
Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
SWP_SHOWWINDOW _
)
End If
End Sub
''' <summary>
''' Restore to original size/position
''' </summary>
''' <param name="sender"></param>
''' <remarks></remarks>
<System.Runtime.CompilerServices.Extension()> _
Public Sub NormalMode(ByVal sender As Form)
sender.WindowState = FormWindowState.Normal
sender.FormBorderStyle = FormBorderStyle.FixedSingle
sender.TopMost = True
End Sub
End Module