Andrew Smith Andrew Smith - 18 days ago 6
Vb.net Question

Vb.net Hide Task bar in Windows 10

I found this sample code from another question but I don't know how to run this code. When I paste this into my project I have no errors but when I run the code it never breaks into this code.

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

Answer

(Too long for a comment)

I tried your code and added Debug info in a console, it works fine for me :

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

Made using Visual Studio 2012 Express on Windows 10 64 Bits