'=================================================================== |
' DISCLAIMER: |
'------------------------------------------------------------------- |
' |
' This sample is provided as is and is not meant for use on a |
' production environment. It is provided only for illustrative |
' purposes. The end user must test and modify the sample to suit |
' their target environment. |
' |
' Microsoft can make no representation concerning the content of |
' this sample. Microsoft is providing this information only as a |
' convenience to you. This is to inform you that Microsoft has not |
' tested the sample and therefore cannot make any representations |
' regarding the quality, safety, or suitability of any code or |
' information found here. |
' |
'=================================================================== |
|
Imports System.Runtime.InteropServices |
|
Public Class ToggleDesktopIcon |
|
<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 GetWindow( _ |
ByVal hWnd As IntPtr, _ |
ByVal uCmd As UInteger) As IntPtr |
End Function |
|
Private Enum GetWindowCmd As UInteger |
GW_HWNDFIRST = 0 |
GW_HWNDLAST = 1 |
GW_HWNDNEXT = 2 |
GW_HWNDPREV = 3 |
GW_OWNER = 4 |
GW_CHILD = 5 |
GW_ENABLEDPOPUP = 6 |
End Enum |
|
<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 Enum SW As Int32 |
Hide = 0 |
Normal = 1 |
ShowMinimized = 2 |
ShowMaximized = 3 |
ShowNoActivate = 4 |
Show = 5 |
Minimize = 6 |
ShowMinNoActive = 7 |
ShowNA = 8 |
Restore = 9 |
ShowDefault = 10 |
ForceMinimize = 11 |
Max = 11 |
End Enum |
|
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ |
Private Shared Function IsWindowVisible(ByVal hwnd As IntPtr) As Boolean |
End Function |
|
Public Shared Sub Toggle() |
Dim hWnd As IntPtr = FindWindow("ProgMan", Nothing) |
hWnd = GetWindow(hWnd, GetWindowCmd.GW_CHILD) |
|
If IsWindowVisible(hWnd) Then |
ShowWindow(hWnd, SW.Hide) |
Else |
ShowWindow(hWnd, SW.ShowNoActivate) |
End If |
End Sub |
|
End Class |