Vb.net 隐藏任务栏 Windows 10

Vb.net Hide Task bar 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

(评论太长)

我试过你的代码并在控制台中添加了调试信息,对我来说效果很好:

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

使用 Visual Studio 2012 Express 在 Windows 10 64 位

上制作