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

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

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


这里附上SysTray_UDF中所用函数的代码

  1. Func _SysTrayIconTooltip($iIndex=0)
  2. ;=========================================================
  3. ;   Create the struct _TBBUTTON
  4. ;   struct {
  5. ;        int         iBitmap;
  6. ;    int         idCommand;
  7. ;    BYTE     fsState;
  8. ;    BYTE     fsStyle;
  9. ;       
  10. ;        #ifdef _WIN64
  11. ;    BYTE     bReserved[6]     // padding for alignment
  12. ;        #elif defined(_WIN32)
  13. ;    BYTE     bReserved[2]     // padding for alignment
  14. ;        #endif
  15. ;    DWORD_PTR   dwData;
  16. ;    INT_PTR          iString;

  17. ;   }
  18. ;=========================================================
  19. Local $str        = "int;int;byte;byte;byte[2];dword;int"
  20. Dim $TBBUTTON   = DllStructCreate($str)
  21. Dim $TBBUTTON2   = DllStructCreate($str)
  22. Dim $ExtraData = DllStructCreate("dword[2]")
  23. Dim $intTip = DllStructCreate("short[1024]")


  24. Local $pId
  25. Local $text
  26. Local $procHandle
  27. Local $index = $iIndex
  28. Local $bytesRead
  29. Local $info
  30. Local $lpData
  31. Local $trayHwnd


  32. $trayHwnd = _FindTrayToolbarWindow()
  33. If $trayHwnd = -1 Then
  34.         $TBBUTTON = 0
  35.         $TBBUTTON2 = 0
  36.         $ExtraData = 0
  37.         $intTip = 0
  38.         ;SetError(1)
  39.         Return -1
  40. EndIf

  41. Local $ret = DLLCall("user32.dll","int","GetWindowThreadProcessId", "hwnd", $trayHwnd, "int*", -1)
  42. If Not @error Then
  43.                 $pId = $ret[2]
  44. Else
  45.         ConsoleWrite("Error: Could not find toolbar process id, " & @error & @LF)
  46.         $TBBUTTON = 0
  47.         $TBBUTTON2 = 0
  48.         $ExtraData = 0
  49.         $intTip = 0
  50.         Return -1
  51. EndIf
  52. $procHandle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', $PROCESS_ALL_ACCESS, 'int', False, 'int', $pId)
  53. If @error Then
  54.         ConsoleWrite("Error: Could not read toolbar process memory, " & @error & @LF)
  55.         $TBBUTTON = 0
  56.         $TBBUTTON2 = 0
  57.         $ExtraData = 0
  58.         $intTip = 0
  59.         return -1
  60. EndIf

  61. $lpData = DLLCall("kernel32.dll","int","VirtualAllocEx", "int", $procHandle[0], "int", 0, "int", DllStructGetSize ( $TBBUTTON ), "int", 0x1000, "int", 0x04)
  62. If @error Then
  63.         ConsoleWrite("VirtualAllocEx Error" & @LF)
  64.         $TBBUTTON = 0
  65.         $TBBUTTON2 = 0
  66.         $ExtraData = 0
  67.         $intTip = 0
  68.         Return -1
  69. Else
  70.         DLLCall("user32.dll","int","SendMessage", "hwnd", $trayHwnd, "int", $TB_GETBUTTON, "int", $index, "ptr",$lpData[0]);e(hwnd, TB_GETBUTTON, index, (LPARAM)lpData);
  71.         DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $procHandle[0], 'int', $lpData[0], 'ptr', DllStructGetPtr($TBBUTTON2), 'int', DllStructGetSize( $TBBUTTON), 'int', $bytesRead)
  72.         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))

  73.         ; go through every character
  74.         $i = 1
  75.         While $i < 1024
  76.                 $tipChar = ""
  77.        
  78. #cs       
  79.                 BOOL ReadProcessMemory(
  80.   HANDLE hProcess,
  81.   LPCVOID lpBaseAddress,
  82.   LPVOID lpBuffer,
  83.   SIZE_T nSize,
  84.   SIZE_T* lpNumberOfBytesRead
  85. );
  86. #ce

  87.                
  88.                 $tipChar = Chr(DllStructGetData($intTip,1,$i))

  89.                 If $tipChar = "" Then
  90.                         ExitLoop
  91.                 EndIf
  92.                 ;ConsoleWrite(@CRLF & $i & " Char: " & $tipChar & @LF)
  93.                 $info =  $info & $tipChar

  94.                 $i = $i + 1
  95.         Wend
  96.        
  97.         If $info = "" Then
  98.                 $info = "No tooltip text"
  99.         EndIf
  100.        
  101.         DLLCall("kernel32.dll","int","VirtualFreeEx", "int", $procHandle[0], "ptr", $lpData[0], "int", 0, "int", 0x8000) ;DllStructGetSize ( $TBBUTTON ), "int", 0x8000))
  102. EndIf

  103. DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $procHandle[0])       
  104. $TBBUTTON = 0
  105. $TBBUTTON2 = 0
  106. $ExtraData = 0
  107. $intTip = 0
  108. $lpData = 0
  109. return $info
  110. EndFunc
复制代码
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2026-9-25 08:15 , Processed in 0.061608 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

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