Private Const PROCESS_TERMINATE As Long = 1
Private Const SPI_GETDESKWALLPAPER As Long = 115
Private Const SPI_SETDESKWALLPAPER As Long = 20
Private Const SW_HIDE = 0
Private Const SW_SHOW = 5
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Declare Function SystemParametersInfo Lib "user32.dll" Alias "SystemParametersInfoA" _
(ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As String, ByVal fuWinIni As
Long) As Long
Private Declare Function EnumWindows Lib "user32.dll" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function ShowWindow Lib "user32.dll" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" _
(ByVal hwnd As Long, ByRef lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long)
As Long
Private Declare Function TerminateProcess Lib "kernel32.dll" _
(ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As Long) As Long
Dim myHandle As Long, list() As Long
Dim filename As String, index As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
EnumWindowsProc = 1
If IsWindowVisible(hwnd) <> 0 And hwnd <> myHandle Then
[COLOR=#0000ff]' nếu cửa sổ đang hiển thị và không phải của ta thì cho handle của nó vào danh sách
[/COLOR] index = index + 1
ReDim Preserve list(1 To index)
list(index) = hwnd
End If
End Function
Sub HideWindows(ByVal hwnd As Long)
Dim hWindow As Long, hProc As Long, ProcID As Long, k As Long
[COLOR=#0000ff]' ghi nhớ handle của cửa sổ của ta
[/COLOR] myHandle = hwnd
index = 0
filename = String(256, Chr(0))
[COLOR=#0000ff]' đọc và ghi nhớ wallpaper hiện hành[/COLOR]
SystemParametersInfo SPI_GETDESKWALLPAPER, 256, filename, 0
[COLOR=#0000ff]' duyệt các cửa sổ top-level có trong system[/COLOR]
EnumWindows AddressOf EnumWindowsProc, 0
[COLOR=#0000ff]' giấu các cửa sổ có trong danh sách - các cửa sổ đang hiển thị
[/COLOR] For k = LBound(list) To UBound(list)
ShowWindow list(k), SW_HIDE
Sleep 40
Do While IsWindowVisible(list(k)) <> 0
ShowWindow list(k), SW_HIDE
Sleep 40
Loop
Next k
[COLOR=#0000ff]' đọc handle của dải Start - "đồ" của Explorer[/COLOR]
hWindow = FindWindow("Shell_TrayWnd", vbNullString)
If hWindow <> 0 Then
[COLOR=#0000ff]' đọc process identifier của Explorer
[/COLOR] GetWindowThreadProcessId hWindow, ProcID
[COLOR=#0000ff]' đọc handle của process Explorer[/COLOR]
hProc = OpenProcess(PROCESS_TERMINATE, 0, ProcID)
If hProc <> 0 Then
[COLOR=#0000ff]' "thịt" chú Explorer
[/COLOR] TerminateProcess hProc, 1
CloseHandle hProc
End If
[COLOR=#0000ff]' lấy ảnh của ta làm hình nền[/COLOR]
SystemParametersInfo SPI_SETDESKWALLPAPER, 0, _
App.Path & "\forest.bmp", SPIF_SENDCHANGE
End If
End Sub
Sub ShowWindows()
Dim k As Long
[COLOR=#0000ff]' Explorer cũ bị ta "thịt" rồi nên phải "đúc" Explorer mới
[/COLOR] ShellExecute 0, "open", "explorer.exe", vbNullString, vbNullString, SW_SHOW
[COLOR=#0000ff]' hiển thị lại các cửa sổ đã bị ẩn[/COLOR]
For k = LBound(list) To UBound(list)
ShowWindow list(k), SW_SHOW
Next k
[COLOR=#0000ff]' phục hồi lại hình nền cũ[/COLOR]
SystemParametersInfo SPI_SETDESKWALLPAPER, 0, filename, SPIF_SENDCHANGE
End Sub