16,555
社区成员
发帖
与我相关
我的任务
分享
Imports System.Net.Sockets
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Text
Module Module1
<DllImport("User32.dll", EntryPoint:="FindWindow")>
Private Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True)>
Public Function FindWindowEx(parentHandle As IntPtr, childAfter As IntPtr, className As String, windowTitle As String) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="ShowWindow")>
Public Function ShowWindow(hwnd As IntPtr, nCmdShow As Integer) As Integer
End Function
<DllImport("user32.dll")>
Public Function IsWindowVisible(hwnd As IntPtr) As Boolean
End Function
Public Const SW_SHOW As Integer = 5
Public Const SW_HIDE As Integer = 0
''' <summary>
''' 命令行程序入口位置
''' </summary>
Public Sub Main()
HideDeskTopIcon()
Threading.Thread.Sleep(5000)
ShowDeskTopIcon()
End Sub
''' <summary>
''' 显示之前隐藏过的桌面图标
''' </summary>
Private Sub ShowDeskTopIcon()
GetDesktopHwnd()
If hWndDeskop <> IntPtr.Zero Then
If Not IsWindowVisible(hWndDeskop) Then
ShowWindow(hWndDeskop, SW_SHOW)
Else
Debug.Print("已经显示啦")
End If
End If
End Sub
''' <summary>
''' 隐藏桌面图标
''' </summary>
Private Sub HideDeskTopIcon()
GetDesktopHwnd()
If hWndDeskop <> IntPtr.Zero Then
If IsWindowVisible(hWndDeskop) Then
ShowWindow(hWndDeskop, SW_HIDE)
Else
Debug.Print("已经隐藏啦")
End If
End If
End Sub
Private hWndDeskop As IntPtr = IntPtr.Zero
''' <summary>
''' 获取桌面图标句柄
''' </summary>
''' <returns></returns>
Private Function GetDesktopHwnd() As IntPtr
Dim hWndPm As IntPtr = IntPtr.Zero
hWndPm = FindWindow(Nothing, "Program Manager")
If hWndPm = IntPtr.Zero Then
Debug.Print("无法找到桌面。" & "错误")
Else
Dim hWndPm2 As IntPtr = IntPtr.Zero
hWndPm2 = FindWindowEx(hWndPm, IntPtr.Zero, Nothing, "")
If hWndPm2 = IntPtr.Zero Then
Debug.Print("无法找到窗口。" & "错误")
Else
hWndDeskop = FindWindowEx(hWndPm2, IntPtr.Zero, Nothing, "FolderView")
If hWndDeskop = IntPtr.Zero Then
Debug.Print("无法找到窗口。" & "错误")
End If
End If
End If
End Function
End Module