Jump to content
Sign in to follow this  
tuape

SysTray_UDF

Recommended Posts

kinda have a problem with this UDF in a function

yes, i included the SysTray_UDF.au3

i wanted to double click a tray icon so i made this simple func using 2 funcs from the UDF:

Func clickfunc()
    $index = _SysTrayIconIndex("process.exe", 0)
    $pos = _SysTrayIconPos($index)
    
    MouseClick("left", $pos[0], $pos[1], 2)
EndFunc

when i tested this independently, it worked

but in the script, the scite console gives me these errors:

C:\Programas\AutoIt3\Include\SysTray_UDF.au3(37,50) : ERROR: $WM_GETTEXT previously declared as a 'Const'

Const $WM_GETTEXT = 13 ; Included in GUIConstants

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Programas\AutoIt3\Include\SysTray_UDF.au3(38,36) : ERROR: $PROCESS_ALL_ACCESS previously declared as a 'Const'

Const $PROCESS_ALL_ACCESS = 2035711

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Utilizador\Ambiente de trabalho\folder\script.au3 - 2 error(s), 0 warning(s)

i have prod autoit 3.2.10.0.

Just comment those lines out.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Just comment those lines out.

omg... --' i can't believe it worked xD however, when i tried the function indepently from the rest of the script it says that those 2 constants may be being used before declared... But thanks, it works and that's what matters

Share this post


Link to post
Share on other sites

after all i really need those lines...WM_GETTEXT may be commented because it's defines in GUIContstants...but without PROCESS_ALL_ACCESS it won't get the right icons.. :S and I really need to use the Systray icon because there is no other way to open that program.. is there any other way to fix it?

Share this post


Link to post
Share on other sites

no worries! i kinda "cheated" on it.. I used the shortcut to access the trayicons ( Win + B -> #B in autoit ) and pressed right arrow how many times would be needed.

Share this post


Link to post
Share on other sites

I'm getting the following error:

Changed: DllCall(): short_ptr, long_ptr, int_ptr types deprecated. Use short*, long* and int* respectively.

When trying to use SysTray_UDF that came with my AutoIt installation.

I'm using SciTE Version 1.75 with AutoIt v3.

I'm doing something similar to what Lord Freshy is trying to do with activating a tray icon.

Thanks

Ted

Share this post


Link to post
Share on other sites

I'm getting the following error:

Changed: DllCall(): short_ptr, long_ptr, int_ptr types deprecated. Use short*, long* and int* respectively.

When trying to use SysTray_UDF that came with my AutoIt installation.

I'm using SciTE Version 1.75 with AutoIt v3.

I'm doing something similar to what Lord Freshy is trying to do with activating a tray icon.

Thanks

Ted

Sorry, I finally found the new SysTray_UDF.au3 file.

SysTray_UDF

Fixed my problem.

Ted

Share this post


Link to post
Share on other sites

In _SysTrayIconHandle, I made a simple change to support WindowsXP 64bit edition:

if(@ProcessorArch = "X64") Then

Local $str = "int;int;byte;byte;byte[6];dword;int";char[128]"

Else

Local $str = "int;int;byte;byte;byte[2];dword;int";char[128]"

EndIf


Frank

Share this post


Link to post
Share on other sites

I'm copying this question from the other thread that referred me to here:

This script is exactly what I'm looking for, but I keep getting the following error:

"Error: Could not find toolbar process id, 2"

Any thoughts? Seems to be coming from "_SysTrayIconHandle".

I'm using windows XP (SP 3). Maybe its the new SP?

"$trayHwnd = _FindTrayToolbarWindow()"

Executes properly, I've singled that out. It seems to return a valid hwnd.

However, once "Local $ret = DLLCall("user32.dll","int","GetWindowThreadProcessId", "hwnd", $trayHwnd, "int*", -1)" runs, thats when I get a problem.

Any ideas?

Share this post


Link to post
Share on other sites

This is a great UDF. I ran into a problem with it though, and ended up changing a bunch of stuff. I fixed a few things, corrected a lot of DllCall parameter types (more for correctness than functionality), and added some things. I don't remember it all. But the biggest fix was in the _SysTrayIconPids() function. The OP was using the _SysTrayIconTitles() function inside the Pids function then using WinGetProcess() on the returned titles. The problem is for multiple processes with the same title, like AutoIt scripts where the hidden window which owns the icon is always "AutoIt v3". So I changed it to use _SysTrayIconHandle() to get all the owning window handles, then used WinGetProcess() with the handle. This guarantees the correct PID is returned.

I bumped the version number to differentiate.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.2 Beta
; Author:         Tuape
;
; Script Function:
;   Systray UDF - Functions for reading icon info from system tray / removing
;   any icon.
;
; Last Update: 7/14/05
; Requirements: AutoIt3 Beta - tested on WindowsXP, might also work in win2000
;
; Functions:
; _SysTrayIconCount() - Get count of all systray icons
; _SysTrayIconTitles() - Get titles of all programs that have icon on systray
; _SysTrayIconProcesses() - Get list of all process names that have icon in systray (hidden or visible)
; _SysTrayIconPids() - Get list of all parent process id's that own an icon in systray (hidden or visible)
; _SysTrayIconRemove($index) - Remove icon (removes completely, not just hide)
; _SysTrayIconIndex($wintitle or $process or $PID) - Get icon index based on process name or wintitle or PID
; _SysTrayIconTooltip($index) - Get tooltip text of an icon based on index
;
; Notes:
; Some systray icons are actually hidden, so _SysTrayIconCount will probably return more than you see on systray.
; Some icons don't have window title on them. However, _SysTrayIconPids() & _SysTrayIconProcesses
; do return correct (parent) pid or process name
; ----------------------------------------------------------------------------
Global Const $TB_DELETEBUTTON = 1046
Global Const $TB_GETBUTTON = 1047
Global Const $TB_BUTTONCOUNT = 1048
Global Const $TB_GETBUTTONTEXT = 1099
Global Const $TB_GETBUTTONINFO = 1089
Global Const $TB_HIDEBUTTON = 1028 ; WM_USER +4
Global Const $TB_GETITEMRECT = 1053
Global Const $TB_MOVEBUTTON = 1106 ; WM_USER +82
Global Const $PROCESS_ALL_ACCESS = 2035711
Global Const $taglocalTBBUTTON = "int;int;byte;byte;byte[2];dword;int"
;===============================================================================
;
; Function Name:    _SysTrayIconTitles()
; Description:      Get list of all window titles that have systray icon
; Parameter(s):     None
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns an array with all window titles
;                   On Failure - TO BE DONE
; Author(s):        Tuape
;
;===============================================================================
Func _SysTrayIconTitles()
    Local $i, $j
    Local $count = _SysTrayIconCount()
    Local $titles[$count]
    ; Get icon owner window's title
    For $i = 0 To $count - 1
        $titles[$i] = WinGetTitle(_SysTrayIconHandle($i))
    Next
    Return $titles
EndFunc   ;==>_SysTrayIconTitles
;===============================================================================
;
; Function Name:    _SysTrayIconProcesses()
; Description:      Get list of all processes that have systray icon
; Parameter(s):     None
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns an array with all process names
;                   On Failure - TO BE DONE
; Author(s):        Tuape
;
;===============================================================================
Func _SysTrayIconProcesses()
    Local $i
    Local $j
    Local $pids = _SysTrayIconPids()
    Local $processes[UBound($pids)]
    Local $list
    ; List all processes
    $list = ProcessList()
    For $i = 0 To UBound($pids) - 1
        For $j = 1 To $list[0][0]
            If $pids[$i] = $list[$j][1] Then
                $processes[$i] = $list[$j][0]
                ExitLoop
            EndIf
        Next
    Next
    Return $processes
EndFunc   ;==>_SysTrayIconProcesses
;===============================================================================
;
; Function Name:    _SysTrayIconPids()
; Description:      Get list of all processes id's that have systray icon
; Parameter(s):     None
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns an array with all process id's
;                   On Failure - TO BE DONE
; Author(s):        Tuape
;
;===============================================================================
Func _SysTrayIconPids()
    Local $i
    Local $count = _SysTrayIconCount()
    Local $processes[$count]
    Local $ret
    For $i = 0 To $count - 1
        $processes[$i] = WinGetProcess(_SysTrayIconHandle($i))
    Next
    Return $processes
EndFunc   ;==>_SysTrayIconPids
;===============================================================================
;
; Function Name:    _SysTrayIconIndex($test, $mode=0)
; Description:      Get list of all processes id's that have systray icon
; Parameter(s):     $test = process name / window title text / process PID
;                   $mode 0 = get index by process name (default)
;                         1 = get index by window title
;                         2 = get index by process PID
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns index of found icon
;                   On Failure - Returns -1 if icon for given process/wintitle
;                                was not found.
;                              - Sets error to 1 and returns -1 in case of bad
;                                arguments
; Author(s):        Tuape
;
;===============================================================================
Func _SysTrayIconIndex($test, $mode = 0)
    Local $index = -1
    Local $compare
    Local $i
    If $mode < 0 Or $mode > 2 Or Not IsInt($mode) Then
        SetError(1)
        Return -1
    EndIf
    If $mode = 0 Then
        $compare = _SysTrayIconProcesses()
    ElseIf $mode = 1 Then
        $compare = _SysTrayIconTitles()
    ElseIf $mode = 2 Then
        $compare = _SysTrayIconPids()
    EndIf
    For $i = 0 To UBound($compare) - 1
        If $compare[$i] = $test Then
            $index = $i
            ExitLoop
        EndIf
    Next
    Return $index
EndFunc   ;==>_SysTrayIconIndex
;===============================================================================
;
; Function Name:    _SysTrayIconPos($iIndex=0)
; Description:      Gets x & y position of systray icon
; Parameter(s):     $iIndex = icon index (Note: starting from 0)
;
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns x [0] and y [1] position of icon
;                   On Failure - Returns -1 if icon is hidden (Autohide on XP etc.)
;                                Sets error to 1 if some internal error happens
;
; Author(s):        Tuape
;
;===============================================================================
Func _SysTrayIconPos($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 $TBBUTTON = DllStructCreate($taglocalTBBUTTON)
    Local $TBBUTTON2 = DllStructCreate($taglocalTBBUTTON)
    Local $ExtraData = DllStructCreate("hwnd[2]")
    Local $lpData
    Local $RECT
    Local $pId
    Local $text
    Local $procHandle
    Local $index = $iIndex
    Local $bytesRead
    Local $info
    Local $pos[2]
    Local $hidden = 0
    Local $trayHwnd
    Local $ret
    $trayHwnd = _FindTrayToolbarWindow()
    If $trayHwnd = -1 Then
        $TBBUTTON = 0
        $TBBUTTON2 = 0
        $ExtraData = 0
        SetError(1)
        Return -1
    EndIf
    $ret = DllCall("user32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $trayHwnd, "dword*", -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
        SetError(1)
        Return -1
    EndIf
    $procHandle = DllCall("kernel32.dll", 'ptr', 'OpenProcess', 'dword', $PROCESS_ALL_ACCESS, 'int', False, 'dword', $pId)
    If @error Then
        ConsoleWrite("Error: Could not read toolbar process memory, " & @error & @LF)
        $TBBUTTON = 0
        $TBBUTTON2 = 0
        $ExtraData = 0
        SetError(1)
        Return -1
    EndIf
    $lpData = DllCall("kernel32.dll", "ptr", "VirtualAllocEx", "ptr", $procHandle[0], "ptr", 0, "ulong", DllStructGetSize($TBBUTTON), "dword", 0x1000, "dword", 0x04)
    If @error Then
        ConsoleWrite(@CRLF & "VirtualAllocEx Error" & @LF)
        $TBBUTTON = 0
        $TBBUTTON2 = 0
        $ExtraData = 0
        SetError(1)
        Return -1
    Else
        DllCall("user32.dll", "int", "SendMessage", "hwnd", $trayHwnd, "int", $TB_GETBUTTON, "int", $index, "ptr", $lpData[0])
        DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'ptr', $procHandle[0], 'ptr', $lpData[0], 'ptr', DllStructGetPtr($TBBUTTON2), 'ulong', DllStructGetSize($TBBUTTON), 'ulong*', $bytesRead)
        DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'ptr', $procHandle[0], 'ptr', DllStructGetData($TBBUTTON2, 6), 'ptr', DllStructGetPtr($ExtraData), 'ulong', DllStructGetSize($ExtraData), 'ulong*', $bytesRead)
        $info = DllStructGetData($ExtraData, 1, 1)
        If Not BitAND(DllStructGetData($TBBUTTON2, 3), 8) Then ; 8 = TBHIDDEN
            $RECT = DllStructCreate("int;int;int;int")
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $trayHwnd, "int", $TB_GETITEMRECT, "int", $index, "ptr", $lpData[0])
            DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'ptr', $procHandle[0], 'ptr', $lpData[0], 'ptr', DllStructGetPtr($RECT), 'ulong', DllStructGetSize($RECT), 'ulong*', $bytesRead)
            $ret = DllCall("user32.dll", "int", "MapWindowPoints", "hwnd", $trayHwnd, "int", 0, 'ptr', DllStructGetPtr($RECT), "int", 2)
            ConsoleWrite("Info: " & $info & "RECT[0](left): " & DllStructGetData($RECT, 1) & "RECT[1](top): " & DllStructGetData($RECT, 2) & "RECT[2](right): " & DllStructGetData($RECT, 3) & "RECT[3](bottom): " & DllStructGetData($RECT, 4) & @LF)
            $pos[0] = DllStructGetData($RECT, 1)
            $pos[1] = DllStructGetData($RECT, 2)
            $RECT = 0
        Else
            $hidden = 1
        EndIf
        DllCall("kernel32.dll", "int", "VirtualFreeEx", "ptr", $procHandle[0], "ptr", $lpData[0], "ulong", 0, "dword", 0x8000) ;DllStructGetSize ( $TBBUTTON ), "int", 0x8000)
    EndIf
    DllCall('kernel32.dll', 'int', 'CloseHandle', 'ptr', $procHandle[0])
    $TBBUTTON = 0
    $TBBUTTON2 = 0
    $ExtraData = 0
    If $hidden <> 1 Then
        Return $pos
    Else
        Return -1
    EndIf
EndFunc   ;==>_SysTrayIconPos
;===============================================================================
;
; Function Name:    _SysTrayIconHandle($iIndex=0)
; Description:      Utility function. Gets hwnd of window associated with
;                   systray icon of given index
; Parameter(s):     $iIndex = icon index (Note: starting from 0)
;
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns hwnd of found icon
;                   On Failure - Returns -1 in error situations
;
; Author(s):        Tuape
;
;===============================================================================
Func _SysTrayIconHandle($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 $TBBUTTON = DllStructCreate($taglocalTBBUTTON)
    Local $TBBUTTON2 = DllStructCreate($taglocalTBBUTTON)
    Local $ExtraData = DllStructCreate("hwnd[2]")
    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
        SetError(1)
        Return -1
    EndIf
    Local $ret = DllCall("user32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $trayHwnd, "dword*", -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
        Return -1
    EndIf
    $procHandle = DllCall("kernel32.dll", 'ptr', 'OpenProcess', 'dword', $PROCESS_ALL_ACCESS, 'int', False, 'dword', $pId)
    If @error Then
        ConsoleWrite("Error: Could not read toolbar process memory, " & @error & @LF)
        $TBBUTTON = 0
        $TBBUTTON2 = 0
        $ExtraData = 0
        Return -1
    EndIf
    $lpData = DllCall("kernel32.dll", "ptr", "VirtualAllocEx", "ptr", $procHandle[0], "ptr", 0, "ulong", DllStructGetSize($TBBUTTON), "dword", 0x1000, "dword", 0x04)
    If @error Then
        ConsoleWrite("VirtualAllocEx Error" & @LF)
        $TBBUTTON = 0
        $TBBUTTON2 = 0
        $ExtraData = 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', 'ptr', $procHandle[0], 'ptr', $lpData[0], 'ptr', DllStructGetPtr($TBBUTTON2), 'ulong', DllStructGetSize($TBBUTTON), 'ulong*', $bytesRead)
        DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'ptr', $procHandle[0], 'ptr', DllStructGetData($TBBUTTON2, 6), 'ptr', DllStructGetPtr($ExtraData), 'ulong', DllStructGetSize($ExtraData), 'ulong*', $bytesRead);_MemRead($procHandle, $lpData[0], DllStructGetSize( $TBBUTTON))
        $info = DllStructGetData($ExtraData, 1, 1)
        DllCall("kernel32.dll", "int", "VirtualFreeEx", "ptr", $procHandle[0], "ptr", $lpData[0], "ulong", 0, "dword", 0x8000) ;DllStructGetSize ( $TBBUTTON ), "int", 0x8000)
    EndIf
    DllCall('kernel32.dll', 'int', 'CloseHandle', 'ptr', $procHandle[0])
    $TBBUTTON = 0
    $TBBUTTON2 = 0
    $ExtraData = 0
    $lpData = 0
    Return $info
EndFunc   ;==>_SysTrayIconHandle
;===============================================================================
;
; Function Name:    _SysTrayIconTooltip($iIndex=0)
; Description:      Utility function. Gets the tooltip text of
;                   systray icon of given index
; Parameter(s):     $iIndex = icon index (Note: starting from 0)
;
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns tooltip text of icon
;                   On Failure - Returns -1 in error situations
;
; Author(s):        Tuape
;
;===============================================================================
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 $TBBUTTON = DllStructCreate($taglocalTBBUTTON)
    Local $TBBUTTON2 = DllStructCreate($taglocalTBBUTTON)
    Local $ExtraData = DllStructCreate("hwnd[2]")
    Local $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", "dword", "GetWindowThreadProcessId", "hwnd", $trayHwnd, "dword*", -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", 'ptr', 'OpenProcess', 'dword', $PROCESS_ALL_ACCESS, 'int', False, 'dword', $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", "ptr", "VirtualAllocEx", "ptr", $procHandle[0], "ptr", 0, "ulong", DllStructGetSize($TBBUTTON), "dword", 0x1000, "dword", 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', 'ptr', $procHandle[0], 'ptr', $lpData[0], 'ptr', DllStructGetPtr($TBBUTTON2), 'ulong', DllStructGetSize($TBBUTTON), 'ulong*', $bytesRead)
        DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'ptr', $procHandle[0], 'ptr', DllStructGetData($TBBUTTON2, 7), 'ptr', DllStructGetPtr($intTip), 'ulong', DllStructGetSize($intTip), 'ulong*', 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", "ptr", $procHandle[0], "ptr", $lpData[0], "ulong", 0, "dword", 0x8000) ;DllStructGetSize ( $TBBUTTON ), "int", 0x8000))
    EndIf
    DllCall('kernel32.dll', 'int', 'CloseHandle', 'ptr', $procHandle[0])
    $TBBUTTON = 0
    $TBBUTTON2 = 0
    $ExtraData = 0
    $intTip = 0
    $lpData = 0
    Return $info
EndFunc   ;==>_SysTrayIconTooltip
;===============================================================================
;
; Function Name:    _SysTrayIconCount
; Description:      Utility function. Returns number of icons on systray
;                   Note: Hidden icons are also reported
; Parameter(s):     None
;
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns number of icons found
;                   On Failure - Returns -1
;
; Author(s):        Tuape
;
;===============================================================================
Func _SysTrayIconCount()
    Local $hWnd = _FindTrayToolbarWindow()
    Local $count = 0
    $count = DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $TB_BUTTONCOUNT, "int", 0, "int", 0)
    If @error Then Return -1
    Return $count[0]
EndFunc   ;==>_SysTrayIconCount
;===============================================================================
;
; Function Name:    _SysTrayIconVisible($flag, $index)
; Description:      Hides / unhides any icon on systray
;
; Parameter(s):     $flag = hide (1) or show (0) icon
;                   $index = icon index. Can be queried with _SysTrayIconIndex()
;
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns 1 if operation was successfull / 0 if
;                   icon was already hidden/unhidden
;                   On Failure - If invalid parameters, returns -1 and sets error
;                   to 1
;
; Author(s):        Tuape
;
;===============================================================================
Func _SysTrayIconVisible($flag, $index)
    If $flag < 0 Or $flag > 1 Or Not IsInt($flag) Then
        SetError(1)
        Return -1
    EndIf
    Local $hWnd = _FindTrayToolbarWindow()
    Local $return
    Local $TBBUTTON = DllStructCreate($taglocalTBBUTTON)
    Local $TBBUTTON2 = DllStructCreate($taglocalTBBUTTON)
    Local $pId
    Local $text
    Local $procHandle
    Local $bytesRead
    Local $info
    Local $lpData
    Local $ret = DllCall("user32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $hWnd, "dword*", -1)
    If Not @error Then
        $pId = $ret[2]
    Else
        ConsoleWrite("Error: Could not find toolbar process id, " & @error & @LF)
        $TBBUTTON = 0
        $TBBUTTON2 = 0
        Return -1
    EndIf
    $procHandle = DllCall("kernel32.dll", 'ptr', 'OpenProcess', 'dword', $PROCESS_ALL_ACCESS, 'int', False, 'dword', $pId)
    If @error Then
        ConsoleWrite("Error: Could not read toolbar process memory, " & @error & @LF)
        $TBBUTTON = 0
        $TBBUTTON2 = 0
        Return -1
    EndIf
    $lpData = DllCall("kernel32.dll", "ptr", "VirtualAllocEx", "ptr", $procHandle[0], "ptr", 0, "ulong", DllStructGetSize($TBBUTTON), "dword", 0x1000, "dword", 0x04)
    If @error Then
        ConsoleWrite("VirtualAllocEx Error" & @LF)
        $TBBUTTON = 0
        $TBBUTTON2 = 0
        Return -1
    Else
        DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $TB_GETBUTTON, "int", $index, "ptr", $lpData[0]);e(hwnd, TB_GETBUTTON, index, (LPARAM)lpData);
        DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'ptr', $procHandle[0], 'ptr', $lpData[0], 'ptr', DllStructGetPtr($TBBUTTON2), 'ulong', DllStructGetSize($TBBUTTON), 'ulong*', $bytesRead)
        $return = DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $TB_HIDEBUTTON, "int", DllStructGetData($TBBUTTON2, 2), "long", $flag)
        DllCall("kernel32.dll", "int", "VirtualFreeEx", "ptr", $procHandle[0], "ptr", $lpData[0], "ulong", 0, "dword", 0x8000) ;DllStructGetSize ( $TBBUTTON ), "int", 0x8000)
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'ptr', $procHandle[0])
    EndIf
    $TBBUTTON = 0
    $TBBUTTON2 = 0
    Return $return[0]
EndFunc   ;==>_SysTrayIconVisible
;===============================================================================
;
; Function Name:    _SysTrayIconmove($curPos, $newPos)
; Description:      Moves systray icon
;
; Parameter(s):     $curPos = icon's current index (0 based)
;                   $newPos = icon's new position
;                   ----> ($curPos+1 = one step to right, $curPos-1 = one step to left)
;
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns 1 if operation was successfull
;                   On Failure - If invalid parameters, returns -1 and sets error
;                   to 1
;
; Author(s):        Tuape
;
;===============================================================================
Func _SysTrayIconmove($curPos, $newPos)
    Local $iconCount = _SysTrayIconCount()
    If $curPos < 0 Or $newPos < 0 Or $curPos > $iconCount - 1 Or $newPos > $iconCount - 1 Or Not IsInt($curPos) Or Not IsInt($newPos) Then
        SetError(1)
        Return -1
    EndIf
    Local $hWnd = _FindTrayToolbarWindow()
    Local $return
    Local $return = DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $TB_MOVEBUTTON, "int", $curPos, "int", $newPos)
    Return $return[0]
EndFunc   ;==>_SysTrayIconmove
;===============================================================================
;
; Function Name:    _SysTrayIconRemove($index=0
; Description:      Removes systray icon completely.
;
; Parameter(s):     index = icon index. Can be queried with _SysTrayIconIndex()
;                   Default = 0
;
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns 1 if icon successfully removed
;                   On Failure - Sets error to 1 and returns -1
;
; Author(s):        Tuape
;
;===============================================================================
Func _SysTrayIconRemove($index = 0)
    If $index < 0 Or $index > _SysTrayIconCount() - 1 Then
        SetError(1)
        Return -1
    EndIf
    Local $hWnd = _FindTrayToolbarWindow()
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $TB_DELETEBUTTON, "int", $index, "int", 0)
    If Not @error Then
        Return 1
    Else
        SetError(2)
        Return -1
    EndIf
EndFunc   ;==>_SysTrayIconRemove
;===============================================================================
;
; Function Name:    _FindTrayToolbarWindow
; Description:      Utility function for finding Toolbar window hwnd
; Parameter(s):     None
;
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns Toolbar window hwnd
;                   On Failure - returns -1
;
; Author(s):        Tuape
;
;===============================================================================
Func _FindTrayToolbarWindow()
    Local $hWnd = DllCall("user32.dll", "hwnd", "FindWindow", "str", "Shell_TrayWnd", "ptr", 0)
    If @error Then Return -1
    $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "hwnd", 0, "str", "TrayNotifyWnd", "ptr", 0);FindWindowEx(hWnd,NULL,_T("TrayNotifyWnd"), NULL);
    If @error Then Return -1
    If @OSVersion <> "WIN_2000" Then
        $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "hwnd", 0, "str", "SysPager", "ptr", 0);FindWindowEx(hWnd,NULL,_T("TrayNotifyWnd"), NULL);
        If @error Then Return -1
    EndIf
    $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "hwnd", 0, "str", "ToolbarWindow32", "ptr", 0);FindWindowEx(hWnd,NULL,_T("TrayNotifyWnd"), NULL);
    If @error Then Return -1
    Return $hWnd[0]
EndFunc   ;==>_FindTrayToolbarWindow
Edited by wraithdu

Share this post


Link to post
Share on other sites

hi all,

I am trying to use systray_udf to find the icon "vnc server" and see if it's changed color. it goes black when someone is connected. what i want to do is have this script running all the time and check if someone connects to vnc, if so it pauses and downloads. i know how to do the pausing, i just don't now how to get it to check for the color without interacting with the normal use of the pc. this is not sneaky or under hand i just want to log in to my pc from work and have it pause what its doing so i can use the full bandwidth.

i have got to

#include "SysTray_UDF.au3"
MsgBox(0, "count", _SystrayIconCount ())
For $p = 0 To _SystrayIconCount ()
   ConsoleWrite(@CR & "#" & $p & "Tooltip: " & _SysTrayIconTooltip ($p))
Next
MsgBox(0, "Tooltip", _SysTrayIconTooltip (_SysTrayIconIndex ("topdesk.exe")))
$oldMatchMode = Opt("WinTitleMatchMode", 4)
$oldChildMode = Opt("WinSearchChildren", 1)
$class = "classname=Shell_TrayWnd"
$hControl = ControlGetHandle($class, "", "Button2")
; get tray position and move there. Helps if Auto Hide tray option is used.
$posTray = WinGetPos(_FindTrayToolbarWindow ())
MouseMove($posTray[0], $posTray[1])
$index = _SysTrayIconIndex ("topdesk.exe"); Change this to some other application if needed
If $index <> -1 Then
   $pos = _SysTrayIconPos ($index)
   If $pos = -1 Then
     ; ***** Moved by CatchFish *****
     ; If XP and the Hide Inactive Icons mode is active
      If $hControl <> "" And ControlCommand($class, "", $hControl, "IsVisible", "") Then
         ControlClick($class, "", $hControl)
         Sleep(250); Small delay to allow the icons to be drawn
      EndIf
     ; ******************************
      $pos = _SysTrayIconPos ($index)
      If $pos = -1 Then Exit; ** A real error this time;)
   EndIf
   MouseMove($pos[0], $pos[1])
   Sleep(1000)
   MouseClick("right")
EndIf
ConsoleWrite(@CRLF & @CRLF & "Pos[0]: " & $pos[0] & "$pos[1]: " & $pos[1])
; Restore Opt settings
Opt("WinTitleMatchMode", $oldMatchMode)
Opt("WinSearchChildren", $oldChildMode)

But i'm not sure how to just check for the color without moving the mouse and the react when the color changes. i am using topdesk.exe for testing purposes and will replace it with vnc when i get home.

Share this post


Link to post
Share on other sites

i have got as far as this

#include "SysTray_UDF.au3"
MsgBox(0, "count", _SystrayIconCount ())
For $p = 0 To _SystrayIconCount ()
   ConsoleWrite(@CR & "#" & $p & "Tooltip: " & _SysTrayIconTooltip ($p))
Next
MsgBox(0, "Tooltip", _SysTrayIconTooltip (_SysTrayIconIndex ("topdesk.exe")))
$oldMatchMode = Opt("WinTitleMatchMode", 4)
$oldChildMode = Opt("WinSearchChildren", 1)
$class = "classname=Shell_TrayWnd"
$hControl = ControlGetHandle($class, "", "Button2")
; get tray position and move there. Helps if Auto Hide tray option is used.
$posTray = WinGetPos(_FindTrayToolbarWindow ())
$index = _SysTrayIconIndex ("topdesk.exe"); Change this to some other application if needed
If $index <> -1 Then
   $pos = _SysTrayIconPos ($index)
   If $pos = -1 Then
     ; ***** Moved by CatchFish *****
     ; If XP and the Hide Inactive Icons mode is active
      If $hControl <> "" And ControlCommand($class, "", $hControl, "IsVisible", "") Then
         ControlClick($class, "", $hControl)
         Sleep(250); Small delay to allow the icons to be drawn
      EndIf
     ; ******************************
      $pos = _SysTrayIconPos ($index)
      If $pos = -1 Then Exit; ** A real error this time;)
   EndIf
   $color = PixelGetColor ($pos[0] + 7, $pos[1] + 7)
   MouseMove($pos[0] + 7, $pos[1] + 7)
   Sleep(1000)
   MsgBox(0, "color is", $color & " at " & $pos[0]& "," & $pos[1])
EndIf
ConsoleWrite(@CRLF & @CRLF & "Pos[0]: " & $pos[0] & "$pos[1]: " & $pos[1])
; Restore Opt settings
Opt("WinTitleMatchMode", $oldMatchMode)
Opt("WinSearchChildren", $oldChildMode)

which is telling me what color it finds.

could someone help me trim out what i dont need from the code. give my code a diet so to speak

Share this post


Link to post
Share on other sites

I was having trouble with this script getting this error:

"Error: Could not find toolbar process id, 2"

It turns out it was a problem with the "GetWindowThreadProcessId" call not being correct in the latest versions so I have uploaded a corrected script that includes this fix as well as the check for 64 bit windows.

I have attached it to this post.

SysTray_UDF.au3


----------------------------------------------------------------------------------------Melloware Inchttp://www.melloware.comHome of Intelliremote, take back control of your HTPC!www.intelliremote.com-----------------------------------------------------------------------------------------

Share this post


Link to post
Share on other sites

Some X64 Examples. I tried it but most of the functions return same value or nothing or is not an array.

Compile with AutoItX64.exe.

http://www.autoitscript.com/forum/style_im...-emo-button.png

:D

OK it looks like from 3.2 to 3.3 they changed @ProcessorArch to @OSArch try this one, I just used it on Vista Ultimate 64 and my script worked fine.

SysTray_UDF.au3


----------------------------------------------------------------------------------------Melloware Inchttp://www.melloware.comHome of Intelliremote, take back control of your HTPC!www.intelliremote.com-----------------------------------------------------------------------------------------

Share this post


Link to post
Share on other sites

Given examples don't work properly on x64.

Your example may be working well.

You can post your x64 compiled exe for testing for everybody.

I am not using any macros.

:D

Share this post


Link to post
Share on other sites

Given examples don't work properly on x64.

Your example may be working well.

You can post your x64 compiled exe for testing for everybody.

I am not using any macros.

:D

You are right, only some of the functions are working on X64. I still can't get ToolTips to work even though nothing is returning an error. Will have to look into it more.


----------------------------------------------------------------------------------------Melloware Inchttp://www.melloware.comHome of Intelliremote, take back control of your HTPC!www.intelliremote.com-----------------------------------------------------------------------------------------

Share this post


Link to post
Share on other sites

doesn't work on XP SP2 x64 unfortunately.

Only process that is visible is AutoIT (however there is no AutoIT icon).

Been looking for a script to interact with systray icons.

Edited by Cusem

Share this post


Link to post
Share on other sites

Highly modified version of this UDF HERE. You'll have to edit back in the 64-bit support if you want it though.

Edited by wraithdu

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...