1,066
社区成员
发帖
与我相关
我的任务
分享
Attribute VB_Name = "Module1"
Option Explicit
Private Const WM_USER = &H400
Private Const TB_BUTTONCOUNT = (WM_USER + 24)
Private Const TB_HIDEBUTTON = (WM_USER + 4)
Private Const TB_GETBUTTONTEXTA = (WM_USER + 45)
Private Const TB_AUTOSIZE = (WM_USER + 33)
Private Const MEM_COMMIT = &H1000
Private Const MEM_RESERVE = &H2000
Private Const MEM_RELEASE = &H8000
Private Const PAGE_READWRITE = &H4
Private Const PROCESS_VM_OPERATION = (&H8)
Private Const PROCESS_VM_READ = (&H10)
Private Const PROCESS_VM_WRITE = (&H20)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function VirtualAllocEx Lib "kernel32.dll" (ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32.dll" (ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Public AllIconText() As String
Sub GetAllIconText()
Dim pIdExplorer As Long, hwnd2 As Long, hExplorer As Long, lpIconText As Long
Dim i As Integer
Dim BtnCount As Integer
Dim IconText As String
hwnd2 = FindWindow("Shell_TrayWnd", vbNullString)
hwnd2 = FindWindowEx(hwnd2, 0, "TrayNotifyWnd", vbNullString)
hwnd2 = FindWindowEx(hwnd2, 0, "SysPager", vbNullString)
hwnd2 = FindWindowEx(hwnd2, 0, "ToolbarWindow32", vbNullString)
GetWindowThreadProcessId hwnd2, pIdExplorer
hExplorer = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, pIdExplorer)
lpIconText = VirtualAllocEx(ByVal hExplorer, ByVal 0&, Len(IconText), MEM_COMMIT Or MEM_RESERVE, PAGE_READWRITE)
BtnCount = SendMessage(hwnd2, TB_BUTTONCOUNT, 0, 0)
Dim lLen As Long, sBuff As String
ReDim AllIconText(BtnCount - 1)
For i = 0 To BtnCount - 1
IconText = Space$(1024)
lLen = SendMessage(hwnd2, TB_GETBUTTONTEXTA, i, ByVal lpIconText)
ReadProcessMemory hExplorer, ByVal lpIconText, ByVal IconText, Len(IconText), 0
If lLen <> -1 Then IconText = Left$(IconText, InStr(1, IconText, Chr$(0)) - 1)
AllIconText(i) = IconText
Next
VirtualFreeEx hExplorer, lpIconText, Len(IconText), MEM_RELEASE
CloseHandle hExplorer
End Sub
Function RemoveWinIcoArea(IcoText As String, Optional Remove As Boolean = True) As Boolean
Dim pIdExplorer As Long, hwnd2 As Long, hExplorer As Long, lpIconText As Long
Dim i As Integer
Dim BtnCount As Integer
Dim IconText As String
hwnd2 = FindWindow("Shell_TrayWnd", vbNullString)
hwnd2 = FindWindowEx(hwnd2, 0, "TrayNotifyWnd", vbNullString)
hwnd2 = FindWindowEx(hwnd2, 0, "SysPager", vbNullString)
hwnd2 = FindWindowEx(hwnd2, 0, "ToolbarWindow32", vbNullString)
GetWindowThreadProcessId hwnd2, pIdExplorer
hExplorer = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, pIdExplorer)
lpIconText = VirtualAllocEx(ByVal hExplorer, ByVal 0&, Len(IconText), MEM_COMMIT Or MEM_RESERVE, PAGE_READWRITE)
BtnCount = SendMessage(hwnd2, TB_BUTTONCOUNT, 0, 0)
Dim lLen As Long, sBuff As String
For i = 0 To BtnCount - 1
IconText = Space$(1024)
lLen = SendMessage(hwnd2, TB_GETBUTTONTEXTA, i, ByVal lpIconText)
ReadProcessMemory hExplorer, ByVal lpIconText, ByVal IconText, Len(IconText), 0
If lLen <> -1 Then IconText = Left$(IconText, InStr(1, IconText, Chr$(0)) - 1)
If IconText = IcoText Then
SendMessage hwnd2, TB_HIDEBUTTON, i, ByVal Remove
SendMessage hwnd2, TB_AUTOSIZE, 0, 0
RemoveWinIcoArea = True
End If
Next
VirtualFreeEx hExplorer, lpIconText, Len(IconText), MEM_RELEASE
CloseHandle hExplorer
End Function
Form1.frm:
VERSION 5.00
Begin VB.Form Form1
Caption = "任务栏通知区图标隐藏工具"
ClientHeight = 2400
ClientLeft = 120
ClientTop = 450
ClientWidth = 5295
LinkTopic = "Form1"
ScaleHeight = 2400
ScaleWidth = 5295
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer1
Interval = 2000
Left = 1200
Top = 960
End
Begin VB.TextBox Text1
Enabled = 0 'False
Height = 1455
Left = 120
MultiLine = -1 'True
TabIndex = 2
Text = "Form1.frx":0000
Top = 360
Width = 5055
End
Begin VB.CommandButton Command2
Caption = "显示"
Height = 375
Left = 2880
TabIndex = 1
Top = 1920
Width = 2295
End
Begin VB.CommandButton Command1
Caption = "隐藏"
Height = 375
Left = 120
TabIndex = 0
Top = 1920
Width = 2295
End
Begin VB.Label Label1
Caption = "当前任务栏通知区图标文字(每两秒自动切换为下一个图标):"
Height = 375
Left = 120
TabIndex = 3
Top = 120
Width = 5175
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim i As Long
Private Sub Command1_Click()
If Text1 <> "" Then RemoveWinIcoArea Text1
End Sub
Private Sub Command2_Click()
If Text1 <> "" Then RemoveWinIcoArea Text1, False
End Sub
Private Sub Form_Load()
i = -1
Text1 = ""
GetAllIconText
End Sub
Private Sub Timer1_Timer()
i = i + 1
If i > UBound(AllIconText) Then i = 0
Text1 = AllIconText(i)
End Sub