VB获取托盘图标提示文字

VB获取托盘图标提示文字,第1张

概述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

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

总结

以上是内存溢出为你收集整理的VB获取托盘图标提示文字全部内容,希望文章能够帮你解决VB获取托盘图标提示文字所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1290285.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存