找回密码
 加入
搜索
查看: 3295|回复: 0

[GUI管理] 如何获取系统托盘的工具提示ToolTip ?

[复制链接]
发表于 2013-4-14 01:39:25 | 显示全部楼层 |阅读模式
例如XP中鼠标放在托盘上的任务管理器上的时候显示“CPU 使用 x%”  ,放在喇叭上就显示“音量”,我需要获取指定进程的托盘提示信息。
使用SysTray_UDF.au3好像对中文支持不太好,经常只显示一部分(例如任务管理器只显示“CPU”,虚拟DAEMON管理器只显示“虚”)。
而GuiToolTip网上讲解的较少,我自己实验失败。


这里附上SysTray_UDF中所用函数的代码
Func _SysTrayIconTooltip($iIndex=0)
;=========================================================
;   Create the struct _TBBUTTON
;   struct {
;        int         iBitmap; 
;    int         idCommand; 
;    BYTE     fsState; 
;    BYTE     fsStyle; 
;        
;        #ifdef _WIN64
;    BYTE     bReserved[6]     // padding for alignment
;        #elif defined(_WIN32)
;    BYTE     bReserved[2]     // padding for alignment
;        #endif
;    DWORD_PTR   dwData; 
;    INT_PTR          iString; 

;   }
;=========================================================
Local $str        = "int;int;byte;byte;byte[2];dword;int"
Dim $TBBUTTON   = DllStructCreate($str)
Dim $TBBUTTON2   = DllStructCreate($str)
Dim $ExtraData = DllStructCreate("dword[2]")
Dim $intTip = DllStructCreate("short[1024]")


Local $pId
Local $text
Local $procHandle
Local $index = $iIndex
Local $bytesRead
Local $info
Local $lpData
Local $trayHwnd


$trayHwnd = _FindTrayToolbarWindow()
If $trayHwnd = -1 Then
        $TBBUTTON = 0
        $TBBUTTON2 = 0
        $ExtraData = 0
        $intTip = 0
        ;SetError(1)
        Return -1
EndIf

Local $ret = DLLCall("user32.dll","int","GetWindowThreadProcessId", "hwnd", $trayHwnd, "int*", -1)
If Not @error Then
                $pId = $ret[2]
Else
        ConsoleWrite("Error: Could not find toolbar process id, " & @error & @LF)
        $TBBUTTON = 0
        $TBBUTTON2 = 0
        $ExtraData = 0
        $intTip = 0
        Return -1
EndIf
$procHandle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', $PROCESS_ALL_ACCESS, 'int', False, 'int', $pId)
If @error Then
        ConsoleWrite("Error: Could not read toolbar process memory, " & @error & @LF)
        $TBBUTTON = 0
        $TBBUTTON2 = 0
        $ExtraData = 0
        $intTip = 0
        return -1
EndIf

$lpData = DLLCall("kernel32.dll","int","VirtualAllocEx", "int", $procHandle[0], "int", 0, "int", DllStructGetSize ( $TBBUTTON ), "int", 0x1000, "int", 0x04)
If @error Then 
        ConsoleWrite("VirtualAllocEx Error" & @LF)
        $TBBUTTON = 0
        $TBBUTTON2 = 0
        $ExtraData = 0
        $intTip = 0
        Return -1
Else
        DLLCall("user32.dll","int","SendMessage", "hwnd", $trayHwnd, "int", $TB_GETBUTTON, "int", $index, "ptr",$lpData[0]);e(hwnd, TB_GETBUTTON, index, (LPARAM)lpData);
        DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $procHandle[0], 'int', $lpData[0], 'ptr', DllStructGetPtr($TBBUTTON2), 'int', DllStructGetSize( $TBBUTTON), 'int', $bytesRead)
        DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $procHandle[0], 'int', DllStructGetData($TBBUTTON2,7), 'int', DllStructGetPtr($intTip), 'int', DllStructGetSize( $intTip), 'int', 0);_MemRead($procHandle, $lpData[0], DllStructGetSize( $TBBUTTON))

        ; go through every character
        $i = 1
        While $i < 1024 
                $tipChar = ""
        
#cs        
                BOOL ReadProcessMemory(
  HANDLE hProcess,
  LPCVOID lpBaseAddress,
  LPVOID lpBuffer,
  SIZE_T nSize,
  SIZE_T* lpNumberOfBytesRead
);
#ce

                
                $tipChar = Chr(DllStructGetData($intTip,1,$i))

                If $tipChar = "" Then 
                        ExitLoop 
                EndIf
                ;ConsoleWrite(@CRLF & $i & " Char: " & $tipChar & @LF)
                $info =  $info & $tipChar

                $i = $i + 1
        Wend
        
        If $info = "" Then 
                $info = "No tooltip text"
        EndIf
        
        DLLCall("kernel32.dll","int","VirtualFreeEx", "int", $procHandle[0], "ptr", $lpData[0], "int", 0, "int", 0x8000) ;DllStructGetSize ( $TBBUTTON ), "int", 0x8000))
EndIf

DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $procHandle[0])        
$TBBUTTON = 0
$TBBUTTON2 = 0
$ExtraData = 0
$intTip = 0
$lpData = 0
return $info
EndFunc
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-5 07:01 , Processed in 0.078264 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表