Click here to Skip to main content
15,897,090 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:
XML
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
Posted

1 solution

If FindWindowEx for SHELLDLL_DefView gives you 0, try FindWindowEx again with WorkerW (name used in windows 7).

Good luck!
 
Share this answer
 
Comments
Member 10628309 14-Nov-15 14:53pm    
Thank you for your response. The one machine that was not working has Fn + F5 for cycling three settings for the monitor...Internal, External and Both. I cycled a few times and then the code worked perfectly.
Thanks Again
Ed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900