I have prepared code to, Hide-Show Desktop Icons, using VB.Net. I have 4 notebooks of various vintages all with windows 7 and two newer ones with Windows 10. The code below works fine on all of the notebooks except one of the windows 7 machines. I am guessing that there is some windows setting on that machine that does not allow the app to work, but I have no idea as to what. Can anyone out there tell me what the problem is? Here is the code:
Imports System.Runtime.InteropServices
Public Class Form1
Private Sho As Boolean = False
Private Const SW_HIDE As Integer = 0
Private Const SW_SHOW As Integer = 5
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, ByVal lclassName As String, ByVal windowTitle As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Int32) As Boolean
End Function
Private Function GetDesktopListviewHandle() As IntPtr
Dim handle As IntPtr
Dim progManager As IntPtr = FindWindow("Progman", Nothing)
Dim desktop As IntPtr = FindWindowEx(progManager, IntPtr.Zero, "SHELLDLL_DefView", Nothing)
handle = FindWindowEx(desktop, IntPtr.Zero, "SysListView32", Nothing)
Return handle
End Function
Private Sub btnHide_Click(sender As Object, e As EventArgs) Handles btnHide.Click
Sho = Not Sho
Dim desktopListview As IntPtr = Me.GetDesktopListviewHandle()
ShowWindow(desktopListview, If(Me.Sho, SW_HIDE, SW_SHOW))
End Sub
End Class