Tải bản đầy đủ (.docx) (2 trang)

Các chiêu thức trong lập trình Ẩn thanh Taskbar hoặc các thành phần khác

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (59.55 KB, 2 trang )

Ẩn thanh Taskbar hoặc các thành phần khác
Binh khí : (Nếu bạn muốn test thì tự vẽ thêm các đối tượng vì đoạn code đã tương đối chi tiết)
Xuất xứ : www.pscode.com
Đoạn mã
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long,
ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx
As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA"
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal
lpsz2 As String) As Long
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_FRAMECHANGED = &H20
Private TaskBarhWnd As Long
Private StartButtonhWnd As Long
Private SysTrayhWnd As Long
Private ClockhWnd As Long
Private FirstBarhWnd As Long
Private SecondBarhWnd As Long
Private ThirdBarhWnd As Long
Private FourthBarhWnd As Long

Public Function HideTaskBarParts(whattohide As String) As Boolean
TaskBarhWnd = FindWindow("Shell_TrayWnd", "")
StartButtonhWnd = FindWindowEx(TaskBarhWnd, 0, "Button" & vbNullString,
vbNullString)
SysTrayhWnd = FindWindowEx(TaskBarhWnd, 0, "traynotifywnd" &
vbNullString, vbNullString)
ClockhWnd = FindWindowEx(SysTrayhWnd, 0, "TrayClockWClass" &


vbNullString, vbNullString)
FirstBarhWnd = FindWindowEx(TaskBarhWnd, 0, "ReBarWindow32" &
vbNullString, vbNullString)
SecondBarhWnd = FindWindowEx(FirstBarhWnd, 0, "ToolBarWindow32" &
vbNullString, vbNullString)
ThirdBarhWnd = FindWindowEx(FirstBarhWnd, 0, "MSTaskSwWClass" &
vbNullString, vbNullString)
FourthBarhWnd = FindWindowEx(ThirdBarhWnd, 0, "SysTabControl32" &
vbNullString, vbNullString)
If TaskBarhWnd = 0 Or StartButtonhWnd = 0 Or SysTrayhWnd = 0 Or
ClockhWnd = 0 Or FirstBarhWnd = 0 Or SecondBarhWnd = 0 Or ThirdBarhWnd = 0
Or FourthBarhWnd = 0 Then
MsgBox "Error recieving window handles !!!", vbCritical, "No hWnd
detected"
Exit Function
End If

If whattohide = "Taskbar" Then
X = SetWindowPos(TaskBarhWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
ElseIf whattohide = "Systray" Then
X = SetWindowPos(SysTrayhWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
ElseIf whattohide = "Clock" Then
X = SetWindowPos(ClockhWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
ElseIf whattohide = "Quickstart" Then
X = SetWindowPos(SecondBarhWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
ElseIf whattohide = "Tasklist" Then
X = SetWindowPos(ThirdBarhWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
ElseIf whattohide = "Startbutton" Then
X = SetWindowPos(StartButtonhWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
Else

X = 0
End If
HideTaskBarParts = X
End Function
Public Function ShowTaskBarParts(whattoshow As String) As Boolean
If whattoshow = "Taskbar" Then
X = SetWindowPos(TaskBarhWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)
ElseIf whattoshow = "Systray" Then
X = SetWindowPos(SysTrayhWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)
ElseIf whattoshow = "Clock" Then
X = SetWindowPos(ClockhWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)
ElseIf whattoshow = "Quickstart" Then
X = SetWindowPos(SecondBarhWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)
ElseIf whattoshow = "Tasklist" Then
X = SetWindowPos(ThirdBarhWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)
ElseIf whattoshow = "Startbutton" Then
X = SetWindowPos(StartButtonhWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)
Else
X = 0
End If
Call SetWindowPos(TaskBarhWnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED)
ShowTaskBarParts = X
End Function

×