vb删除其他程序在任务栏中的图标

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



Private Sub Form_Load()
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(256)
 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 = "音量" Then
   SendMessage hwnd2, TB_HIDEBUTTON, i, True
   SendMessage hwnd2, TB_AUTOSIZE, 0, 0
 End If
Next
VirtualFreeEx hExplorer, lpIconText, Len(IconText), MEM_RELEASE
CloseHandle hExplorer




继续更新增加恢复和刷新功能

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

Private Sub Command1_Click() '隐藏
 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$(256)
   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 = List1.List(List1.ListIndex) Then ' "音量" Then
       SendMessage hwnd2, TB_HIDEBUTTON, i, ByVal True
       SendMessage hwnd2, TB_AUTOSIZE, 0, 0
   End If
 Next
 VirtualFreeEx hExplorer, lpIconText, Len(IconText), MEM_RELEASE
 CloseHandle hExplorer
End Sub

Private Sub Command2_Click()   '显示列表
 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$(256)
   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 = List1.List(List1.ListIndex) Then ' "音量" Then
       SendMessage hwnd2, TB_HIDEBUTTON, i, ByVal False
       SendMessage hwnd2, TB_AUTOSIZE, 0, 0
   End If
 Next
 VirtualFreeEx hExplorer, lpIconText, Len(IconText), MEM_RELEASE
 CloseHandle hExplorer
End Sub

Private Sub Command3_Click() '刷新列表
 List1.Clear
 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$(256)
   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)
   List1.AddItem IconText

 Next
 VirtualFreeEx hExplorer, lpIconText, Len(IconText), MEM_RELEASE
 CloseHandle hExplorer
End Sub

Private Sub Form_Load()
 Command3_Click
End Sub
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值