我从其他问题中找到了此示例代码,但我不知道如何运行此代码。当我将它粘贴到我的项目中时,我没有错误,但是当我运行代码时,它永远不会破坏这段代码。
How can I hide the taskbar in Windows 10
Imports System.Runtime.InteropServices
Module Module1
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True)>
Private Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As SetWindowPosFlags) As Boolean
End Function
<Flags>
Private Enum SetWindowPosFlags As UInteger
SynchronousWindowPosition = &H4000
DeferErase = &H2000
DrawFrame = &H20
FrameChanged = &H20
HideWindow = &H80
DoNotActivate = &H10
DoNotCopyBits = &H100
IgnoreMove = &H2
DoNotChangeOwnerZOrder = &H200
DoNotRedraw = &H8
DoNotReposition = &H200
DoNotSendChangingEvent = &H400
IgnoreResize = &H1
IgnoreZOrder = &H4
ShowWindow = &H40
End Enum
Sub Main()
Dim window As IntPtr = FindWindow("Shell_traywnd", "")
SetWindowPos(window, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.HideWindow)
End Sub
End Module
答案 0 :(得分:0)
(评论太长)
我尝试了你的代码并在控制台中添加了Debug信息,它对我来说很好用:
Sub Main()
Console.WriteLine("Finding the Window")
Dim window As IntPtr = FindWindow("Shell_traywnd", "")
Console.WriteLine("Window handle : " & window.ToString() & " - press a key to hide the taskbar")
Console.ReadKey()
SetWindowPos(window, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.HideWindow)
Console.WriteLine("Window has been hidden, press a key to show it.")
Console.ReadKey()
SetWindowPos(window, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.ShowWindow)
Console.WriteLine("Press a key to end program")
Console.ReadKey()
End Sub
在Windows 10 64位上使用Visual Studio 2012 Express制作