Jump to content

windows tray icon


Recommended Posts

Hi Guys,

I want to write a script that right clicks on an icon in the system tray and then left clicks on "Log Out". Log out is only there if the user is logged in. So far I can right click the tray icon using this snippet:

Opt("WinTitleMatchMode", 2)

Global $hSysTray_Handle, $iSystray_ButtonNumber
Global $sToolTipTitle = "GoToMeeting "

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Is GoToMeeting Running?")
    Exit
Else
    Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
EndIf


Func Get_Systray_Index($sToolTipTitle)

    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf

    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf

    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) = 1 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc

The problem now is looking if the 'Log Out' is there? I'm not sure how I would do this? the IfWinExisits won't and work so I'm a little stuck??

Thanks for any help!

3MGB

Link to comment
Share on other sites

HI,

what program? Maybe you can do it without using the trayicon?

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

3mustgetbeers,

That was a good way to spend a grey afternoon! ;)

Credit goes to rover who posted a much more comprehensive script dealing with popups in general. I have just extracted the relevant parts:

; Add this once the popup menu has appeared
$aPopUp_Text = GetPopUpText()
If $aPopUp_Text[0] = 0 Then
    MsgBox(16, "Error", "Non-standard Pop-up Menu")
Else
    _ArrayDisplay($aPopUp_Text)
EndIf


;And add this function to the script
Func GetPopUpText()

    Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
    Local $hWnd = $aPopUp_List[1][0]
    Local $sClass = $aPopUp_List[1][1]
    If $sClass = "#32768" Then
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            Local $aPopUp_Text[1] = [0]
            For $j = 0 To $iCount - 1
                If Not _GUICtrlMenu_GetItemType($hMenu, $j, True) = $MFT_SEPARATOR Then
                    $aPopUp_Text[0] += 1
                    ReDim $aPopUp_Text[$aPopUp_Text[0] + 1]
                    $aPopUp_Text[$aPopUp_Text[0]] = _GUICtrlMenu_GetItemText($hMenu, $j)
                EndIf
            Next
        EndIf
    EndIf

    Return $aPopUp_Text

EndFunc

If it is a nonstandard menu then I cannot help further. But I have only one in my systray (COMODO) so fingers crossed! :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

3mustgetbeers,

I get the "Non-standard Pop-up Menu"

:)

Could you please add this line and see what class of pop-up we are dealing with? ;)

Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
Local $hWnd = $aPopUp_List[1][0]
Local $sClass = $aPopUp_List[1][1]
ConsoleWrite($sClass & @CRLF) : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
If $sClass = "#32768" Then

Despite my comment yesterday, there are a couple of other possibilites we might try. :idiot:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi,

is there any difference between logoff and killing the process? :)

You can also try using this :

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 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) - Get icon index based on process name or wintitle
; _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
; ----------------------------------------------------------------------------
#NoTrayIcon

Const $TB_DELETEBUTTON = 1046
Const $TB_GETBUTTON = 1047
Const $TB_BUTTONCOUNT = 1048
Const $TB_GETBUTTONTEXT = 1099
Const $TB_GETBUTTONINFO = 1089
Const $TB_HIDEBUTTON = 1028 ; WM_USER +4
Const $TB_GETITEMRECT = 1053
Const $TB_MOVEBUTTON = 1106 ; WM_USER +82
Const $WM_GETTEXT = 13 ; Included in GUIConstants
Const $PROCESS_ALL_ACCESS = 2035711
Const $NO_TITLE = "---No title---" ; text that is used when icon window has no title




;===============================================================================
;
; 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
    Local $j
    Local $max = _SysTrayIconCount()
    Local $info[$max]
    Local $titles[$max]
    Local $var

    ; Get info (hwnd) of all icons
    For $i = 0 To $max - 1
        $info[$i] = _SysTrayIconHandle($i)
    Next

    ; Get window title text
    $var = WinList()
    For $i = 0 To $max - 1
        For $j = 1 To $var[0][0]
            ;If $info[$i] = Dec($var[$j][1]) Then
            If $info[$i] = HWnd($var[$j][1]) Then
                If $var[$j][0] <> "" Then
                    $titles[$i] = $var[$j][0]
                Else
                    $titles[$i] = $NO_TITLE
                EndIf

                ExitLoop

            EndIf
        Next
    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 $titles = _SysTrayIconTitles()
    Local $processes[UBound($titles)]
    Local $ret

    For $i = 0 To UBound($titles) - 1
        If $titles[$i] <> $NO_TITLE Then
            $processes[$i] = WinGetProcess($titles[$i])
        Else
            ; Workaround for systray icons that have no title
            $ret = DllCall("user32.dll", "int", "GetWindowThreadProcessId", "int", _SysTrayIconHandle($i), "int*", -1)
            If Not @error Then
                $processes[$i] = $ret[2]

            EndIf


        EndIf
    Next

    Return $processes


EndFunc   ;==>_SysTrayIconPids


;===============================================================================
;
; Function Name:    _SysTrayIconIndex($name, $mode=0)
; Description:      Get list of all processes id's that have systray icon
; Parameter(s):     $name = process name / window title text
;                   $mode 0 = get index by process name (default)
;                         1 = get index by window title
;                         2 = get index by icon's tooltip text
; 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($name, $mode = 0)
    Local $index = -1
    Local $process
    Local $i
    If $mode < 0 Or $mode > 2 Or Not IsInt($mode) Then
        SetError(1)
        Return -1
    EndIf

    If $mode = 0 Then
        $process = _SysTrayIconProcesses()

    Else
        $process = _SysTrayIconTitles()
    EndIf

    For $i = 0 To UBound($process) - 1
        If $process[$i] = $name Then
            $index = $i
        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 $str = "int;int;byte;byte;byte[2];dword;int"
    Dim $TBBUTTON = DllStructCreate($str)
    Dim $TBBUTTON2 = DllStructCreate($str)
    Dim $ExtraData = DllStructCreate("dword[2]")
    Dim $lpData
    Dim $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", "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
        SetError(1)
        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
        SetError(1)
        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(@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', '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, 6), 'int', DllStructGetPtr($ExtraData), 'int', DllStructGetSize($ExtraData), 'int', $bytesRead)

        $info = DllStructGetData($ExtraData, 1, 1)
        If Not BitAND(DllStructGetData($TBBUTTON2, 3), 8) Then ; 8 = TBHIDDEN

            $str = "int;int;int;int"
            $RECT = DllStructCreate($str)

            DllCall("user32.dll", "int", "SendMessage", "hwnd", $trayHwnd, "int", $TB_GETITEMRECT, "int", $index, "ptr", $lpData[0])
            DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $procHandle[0], 'int', $lpData[0], 'ptr', DllStructGetPtr($RECT), 'int', DllStructGetSize($RECT), 'int', $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)

            ;MouseMove(DllStructGetData($RECT,1),DllStructGetData($RECT,2))
            ;Sleep(1000)
            ;MouseClick("left")
            $pos[0] = DllStructGetData($RECT, 1)
            $pos[1] = DllStructGetData($RECT, 2)
            $RECT = 0
        Else
            $hidden = 1
        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

    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 $str = "int;int;byte;byte;byte[2];dword;int";char[128]"
    Dim $TBBUTTON = DllStructCreate($str)
    Dim $TBBUTTON2 = DllStructCreate($str)
    Dim $ExtraData = DllStructCreate("dword[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", "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
        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
        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
        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, 6), 'int', DllStructGetPtr($ExtraData), 'int', DllStructGetSize($ExtraData), 'int', $bytesRead);_MemRead($procHandle, $lpData[0], DllStructGetSize( $TBBUTTON))

        $info = DllStructGetData($ExtraData, 1)
        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
    $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 $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   ;==>_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 $str = "int;int;byte;byte;byte[2];dword;int";char[128]"
    Dim $TBBUTTON = DllStructCreate($str)
    Dim $TBBUTTON2 = DllStructCreate($str)



    Local $pId
    Local $text
    Local $procHandle
    Local $bytesRead
    Local $info
    Local $lpData

    Local $ret = DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $hWnd, "int*", -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", '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
        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
        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', 'int', $procHandle[0], 'int', $lpData[0], 'ptr', DllStructGetPtr($TBBUTTON2), 'int', DllStructGetSize($TBBUTTON), 'int', $bytesRead)

        $return = DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $TB_HIDEBUTTON, "int", DllStructGetData($TBBUTTON2, 2), "long", $flag)
        ;ConsoleWrite(@CRLF & "Return: " & $return[0])

        DllCall("kernel32.dll", "int", "VirtualFreeEx", "int", $procHandle[0], "ptr", $lpData[0], "int", 0, "int", 0x8000) ;DllStructGetSize ( $TBBUTTON ), "int", 0x8000)


        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $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", "int", 0)

    If @error Then Return -1
    $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "int", 0, "str", "TrayNotifyWnd", "int", 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], "int", 0, "str", "SysPager", "int", 0);FindWindowEx(hWnd,NULL,_T("TrayNotifyWnd"), NULL);
        If @error Then Return -1
    EndIf
    $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "int", 0, "str", "ToolbarWindow32", "int", 0);FindWindowEx(hWnd,NULL,_T("TrayNotifyWnd"), NULL);
    If @error Then Return -1

    Return $hWnd[0]
EndFunc   ;==>_FindTrayToolbarWindow

Try clicking right on the icon and then use send l for logoff or whatever letter you need to jump to the relevant section and then send enter :-)

#include
#include
Opt("WinTitleMatchMode", 2)
;~ $a = _SysTrayIconTitles ()
$a = _SysTrayIconProcesses()
_ArrayDisplay($a, "")
ConsoleWrite(_SysTrayIconIndex("g2mlauncher.exe") & @CRLF)
Global $title = "---No title---"
clickSysTray($title)

Func clickSysTray($title, $click = "right")
    Global $a = _SysTrayIconTitles()
    $p = MouseGetPos()
    For $i = 1 To UBound($a) - 1
        If $a[$i] = $title Then
            $pos = _SysTrayIconPos($i)
            MouseClick($click, $pos[0], $pos[1], 1, 1)
            ExitLoop
        EndIf
    Next
    MouseMove($p[0], $p[1], 1)
EndFunc   ;==>clickSysTray
Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Xenobiologist

No, I don't want to kill the process. We have 10 different licenses and I want a button to say "log into meeting room 1". I figured the easiest way to do this was to first log out of whatever meeting room you are currently in and then on into meeting room 1 (in this case).

M23

I get this in the console::

>Running:(3.3.6.1):C:\Program Files\AutoIt3\autoit3.exe "H:\My Documents\test.au3"    
#32768

Which, for inexperienced me, says that is the class we are looking for, though maybe I'm wrong?

Cheers guys!

Link to comment
Share on other sites

  • Moderators

3mustgetbeers,

Which, for inexperienced me, says that is the class we are looking for

Looks that way to me as well! :idiot:

OK, let us check that we get a menu handle returned and a valid count of the items in it: ;)

Func GetPopUpText()

    Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
    Local $hWnd = $aPopUp_List[1][0]
    Local $sClass = $aPopUp_List[1][1]
    If $sClass = "#32768" Then
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        ConsoleWrite("Menu handle = " & $hMenu & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            ConsoleWrite("Menu item count = " & $iCount & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            Local $aPopUp_Text[1] = [0]
            For $j = 0 To $iCount - 1
                If Not _GUICtrlMenu_GetItemType($hMenu, $j, True) = $MFT_SEPARATOR Then
                    $aPopUp_Text[0] += 1
                    ReDim $aPopUp_Text[$aPopUp_Text[0] + 1]
                    $aPopUp_Text[$aPopUp_Text[0]] = _GUICtrlMenu_GetItemText($hMenu, $j)
                EndIf
            Next
        EndIf
    EndIf

    Return $aPopUp_Text

EndFunc

Let me know what you get. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

3mustgetbeers,

Thanks!

You mean it works now? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I was saying thanks for stickin with it! :)

I'm not sure if this is correct, but the menu handle seems to change each time:

Menu handle = 6490887

Menu item count = 17

Menu handle = 11274795

Menu item count = 17

Menu handle = 18745761

Menu item count = 17

That is the console after I ran the script 3 times, each time I get a "Non-standard Pop-up Menu" error?

Link to comment
Share on other sites

  • Moderators

3mustgetbeers,

Hmmm. :)

Let us check the type of item and whether we actually read the text:

Func GetPopUpText()

    Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
    Local $hWnd = $aPopUp_List[1][0]
    Local $sClass = $aPopUp_List[1][1]
    If $sClass = "#32768" Then
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            Local $aPopUp_Text[1] = [0]
            For $j = 0 To $iCount - 1
                ConsoleWrite(_GUICtrlMenu_GetItemType($hMenu, $j, True) & @CRLF)
                If Not _GUICtrlMenu_GetItemType($hMenu, $j, True) = $MFT_SEPARATOR Then
                    $aPopUp_Text[0] += 1
                    ReDim $aPopUp_Text[$aPopUp_Text[0] + 1]
                    $aPopUp_Text[$aPopUp_Text[0]] = _GUICtrlMenu_GetItemText($hMenu, $j)
                    ConsoleWrite("Item " & $i & " = " & _GUICtrlMenu_GetItemText($hMenu, $j) & @CRLF)
                EndIf
            Next
        EndIf
    EndIf

    Return $aPopUp_Text

EndFunc

Of interest, 0 = text menu item and 2048 = separator bar. I will be interested to see what we get for the logos! ;)

M23

P.S. Just seen your last post. It is quite normal for the handle to be different on each run. Windows allocates these handles to make sure that everything on the system has a unique ID - the fact that the handle changes between runs is why we often need to use such convoluted syntax to identify the items (things like CLASS and INSTANCE for example). :idiot:

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ok.

First, the extral consolewrite line you have:

ConsoleWrite("Item " & $i & " = " & _GUICtrlMenu_GetItemText($hMenu, $j) & @CRLF)

Gives me an error - $i used before declaration. I swapped this for a $j (an estimate as j was used earlier - though I might be wrong???)

But it gives this in the console:

256

256

256

256

2048

256

256

256

256

2048

256

2048

256

256

256

2048

256

256

The 2nd '256' from the bottom reads Log Out in the systray, and the 2048s line up with seperators.

Google image returned this for what you see when you right click on the tray icon:

*Note* there are now 18 instances - as I am logged in. 17 before because I wasn't (the log out option is simply removed)

Edited by 3mustgetbeers
Link to comment
Share on other sites

  • Moderators

3mustgetbeers,

Oh dear - exactly what I was afraid of! ;)

256 = $MFT_OWNERDRAW - Item is owner drawn. That means we cannot read it as it not "text" as such - it is actually an image like the logos, which you will notice have the same type.

I am afraid that we have hit a real brick wall here. There are only 2 threads on the forum that deal with $MFT_OWNERDRAW - one uses it to draw menu items and the other (asking how to read such items!) is unanswered. :idiot:

But let us do some lateral thinking. If I understand you correctly, you want to click on the "Log Out" item - if it is there. Are there any other items that might or might not be on the menu? I was thinking we might be able to locate the lower "flower" image using PixelGetColor and so determine if the "Log Out" item is present or not. :idiot:

Worth a try? :)

M23

Edit: Another thought - wil there only ever be "Log Out" and "Exit" under the final separator? :D

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

hmmm. Doesn't sound to good :)

However, I have just read through this thread again and Xenobiologist points out another option - send. If I right click and send 'L' then it logs off, if I'm not logged in it does nothing, maybe using key strokes is the way forward on this?

Unless you have something else in mind? In chich case yes, there is either 'Log out' & 'Exit' below the bottom seperator , unless I'm not logged in, in which case its just Exit.

Link to comment
Share on other sites

  • Moderators

3mustgetbeers,

I would go with Xeno's option - it is far simpler! :)

But as a favour, could you run this and see if it distinguishes between the 2 states: :idiot:

#include <WindowsConstants.au3>
#Include <GuiMenu.au3>
#Include <GuiToolBar.au3>

Global $hSysTray_Handle, $iSystray_ButtonNumber
Global $sToolTipTitle = "GoToMeeting "

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Is GoToMeeting Running?")
    Exit
Else
    Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
    Sleep(500)
EndIf

GetPopUpFormat()

Func GetPopUpFormat()

    Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
    Local $hWnd = $aPopUp_List[1][0]
    Local $sClass = $aPopUp_List[1][1]
    If $sClass = "#32768" Then
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            Local $aPopUp_Type[1] = [0]
            For $j = 0 To $iCount - 1
                $aPopUp_Type[0] += 1
                ReDim $aPopUp_Text[$aPopUp_Text[0] + 1]
                $aPopUp_Type[$aPopUp_Text[0]] = _GUICtrlMenu_GetItemType($hMenu, $j, True)
                ConsoleWrite("Item " & $j & " = " & _GUICtrlMenu_GetItemText($hMenu, $j) & @CRLF)
            Next
        EndIf
    EndIf
    
    If $aPopUp_Type[$aPopUp_Type[0] - 1] = 2048 Then
        MsgBox(0, "Response", "Not Logged In")
    Else
        Send("{UP}")
        Sleep(100)
        Send("{ENTER}")
        MsgBox(0, "Response", "You are now Logged Out")
    EndIf
    
EndFunc

Func Get_Systray_Index($sToolTipTitle)

    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf

    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf

    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) = 1 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc

If you are logged in then you should get:

256
2048
256
256

at the end of the list and be logged out - if you are not logged in you should get:

256
256
2048
256

and be told so.

No problem if you cannot make it work - it is just to try out my "lateral thinking" idea. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 weeks later...

M23,

Sorry its been so long - not been very well, bleedin flu ;)

Ok, Tried that but get an error. I was running it at work, so not sure of the exact error, but can let you know that the console says on Monday some time. I'm pretty much sorted with the script now, and it does what I want; however, I don't mind troubleshooting this with you if you want for whatever reason - whether it will help you, me, others or just for fun. Or even if because your stubborn, like me, and refuse to be beaten :idiot:

Pretty sure the error is just syntax, and for someone of your calibre will be sorted in a few key strokes :)

THanks again,

3mgb

Link to comment
Share on other sites

  • Moderators

3mustgetbeers,

Whenever you can let me see what the error was I would be grateful - like you I am one of the stubborn ones! ;)

As you say, it might come in handy one day for someone else. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ok,

Ran your code::

#include <WindowsConstants.au3>
#Include <GuiMenu.au3>
#Include <GuiToolBar.au3>

Global $hSysTray_Handle, $iSystray_ButtonNumber
Global $sToolTipTitle = "GoToMeeting "

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Is GoToMeeting Running?")
    Exit
Else
    Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
    Sleep(500)
EndIf

GetPopUpFormat()

Func GetPopUpFormat()

    Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
    Local $hWnd = $aPopUp_List[1][0]
    Local $sClass = $aPopUp_List[1][1]
    If $sClass = "#32768" Then
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            Local $aPopUp_Type[1] = [0]
            For $j = 0 To $iCount - 1
                $aPopUp_Type[0] += 1
                ReDim $aPopUp_Text[$aPopUp_Text[0] + 1]
                $aPopUp_Type[$aPopUp_Text[0]] = _GUICtrlMenu_GetItemType($hMenu, $j, True)
                ConsoleWrite("Item " & $j & " = " & _GUICtrlMenu_GetItemText($hMenu, $j) & @CRLF)
            Next
        EndIf
    EndIf

    If $aPopUp_Type[$aPopUp_Type[0] - 1] = 2048 Then
        MsgBox(0, "Response", "Not Logged In")
    Else
        Send("{UP}")
        Sleep(100)
        Send("{ENTER}")
        MsgBox(0, "Response", "You are now Logged Out")
    EndIf

EndFunc

Func Get_Systray_Index($sToolTipTitle)

    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf

    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf

    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) = 1 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc

It right-clicks the tray icon, but dosen't appear to do much more?

Console has this:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "H:\My Documents\Scripts\New\Test1.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams    
+>09:51:22 Starting AutoIt3Wrapper v.2.0.1.24    Environment(Language:0409  Keyboard:00000809  OS:WIN_XP/Service Pack 2  CPU:X64 OS:X86)
>Running AU3Check (1.54.19.0)  from:C:\Program Files\AutoIt3
H:\My Documents\Scripts\New\Test1.au3(33,52) : WARNING: $aPopUp_Text: possibly used before declaration.
                ReDim $aPopUp_Text[$aPopUp_Text[0] +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
H:\My Documents\Scripts\New\Test1.au3 - 0 error(s), 1 warning(s)
->09:51:22 AU3Check ended.rc:1
>Running:(3.3.6.1):C:\Program Files\AutoIt3\autoit3.exe "H:\My Documents\Scripts\New\Test1.au3"    
H:\My Documents\Scripts\New\Test1.au3 (33) : ==> Variable used without being declared.:
ReDim $aPopUp_Text[$aPopUp_Text[0] + 1]
ReDim ^ ERROR
->09:51:24 AutoIT3.exe ended.rc:1
>Exit code: 1    Time: 4.079
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...