加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB获取托盘图标提示文字

发布时间:2020-12-16 22:45:41 所属栏目:大数据 来源:网络整理
导读: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_BUTTONCO

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读