VB获取托盘图标提示文字

前端之家收集整理的这篇文章主要介绍了VB获取托盘图标提示文字前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Option Explicit

Private Const TBSTATE_HIDDEN = &H8
Private Const MEM_COMMIT As Long = &H1000
Private Const PAGE_READWRITE As Long = &H4

Private Const WM_USER = &H400
Private Const TB_GETBUTTON As Long = (WM_USER + 23)
Private Const TB_BUTTONCOUNT As Long = (WM_USER + 24)

Private Const SYNCHRONIZE As Long = &H100000
Private Const STANDARD_RIGHTS_required As Long = &HF0000
Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_required Or SYNCHRONIZE Or &HFFF)

Private Type TBBUTTON
iBitmap As Long
idCommand As Long
fsState As Byte
fsStyle As Byte
bReserved1 As Byte
bReserved2 As Byte
dwData As Long
iString As Long
End Type

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

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 OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long,ByVal bInheritHandle As Long,ByVal dwProcessId As Long) 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 ReadProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long,lpBaseAddress As Any,lpBuffer As Any,ByVal nSize As Long,lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hWnd As Long,lpdwProcessId As Long) As Long
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String,ByVal nSize As Long) As Long

Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long,lpRect As RECT) As Long
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 Sub Command1_Click() Dim lpRect As RECT Dim lpHwnd As Long Dim lpHeight As Long Dim lTrayPid As Long Dim lCount As Long Dim lret As Long Dim hProcess As Long Dim lAddress As Long Dim udtTb As TBBUTTON Dim asTip(0 To 1024) As Byte Dim sTip As String Dim i As Integer lpHwnd = FindWindow("Shell_TrayWnd",vbNullString) '任务栏句柄 If lpHwnd <> 0 Then lpHwnd = FindWindowEx(lpHwnd,"TrayNotifyWnd",vbNullString) lpHwnd = FindWindowEx(lpHwnd,"SysPager",vbNullString) If lpHwnd <> 0 Then lpHwnd = FindWindowEx(lpHwnd,"ToolbarWindow32",vbNullString) '托盘句柄 End If End If lret = GetWindowThreadProcessId(lpHwnd,lTrayPid) lCount = SendMessage(lpHwnd,TB_BUTTONCOUNT,ByVal 0&) '获取托盘图标个数 hProcess = OpenProcess(PROCESS_ALL_ACCESS,lTrayPid) lAddress = VirtualAllocEx(hProcess,ByVal 0&,ByVal 4096&,MEM_COMMIT,PAGE_READWRITE) For i = 0 To lCount - 1 lret = SendMessage(lpHwnd,TB_GETBUTTON,ByVal i,ByVal lAddress) lret = ReadProcessMemory(hProcess,ByVal lAddress,ByVal VarPtr(udtTb),ByVal Len(udtTb),ByVal 0&) If Not CBool((udtTb.fsState And TBSTATE_HIDDEN)) Then lret = ReadProcessMemory(hProcess,ByVal udtTb.iString,ByVal VarPtr(asTip(0)),ByVal 1024,ByVal 0&) sTip = asTip Else sTip = "[Hidden Icon]" End If Print Left(sTip,InStr(1,sTip,Chr(0)) - 1) Next i End Sub

原文链接:https://www.f2er.com/vb/260743.html

猜你在找的VB相关文章