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