Get Window Focus in Autoit for Applications in System Tray
The problem was that "Reliance Netconnect" was a System tray Application i.e it resided in the system tray. You cannot use WinActivate to get their focus. they have to be redrawn. This worked for me
#Include <GuiToolBar.au3>
#include "SysTray_UDF.au3"
WinSetState("Reliance Netconnect" ,"",@SW_RESTORE)
DIM $index=_SysTrayIconIndex("Reliance Netconnect", 1)
;MsgBox(1,"index",$index)
_GUICtrlToolbar_ClickIndex(ControlGetHandle('[CLASS:Shell_TrayWnd]','','ToolbarWindow321'), $index, "left",False,2)
WinActivate("Reliance Netconnect")
WinWaitActive("Reliance Netconnect")
send("{ENTER}")
send("!c")
WinSetState("Reliance Netconnect" ,"",@SW_MINIMIZE)
You can download SYSTRAY_UDF from here . If you get previously declared as a 'Const' errors change SysTray_UDF.au3 first lines to :
;~ 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
Related videos on Youtube
Comments
-
Ashwin over 1 year
I have two windows open and not minimized (Autoit help and RelianceNetconnect). And the current focus is with a Notepad file. This is my Autoit script :
DIM $s=WinActivate("AutoIt Help") MsgBox(0,"Check",$s)
This works and the autoit jelp window come to focus. The Message Box prints this
0x00046ce
.
This is my second Autoit Script:DIM $s=WinActivate("Reliance Netconnect") MsgBox(0,"Check",$s)
This does not work, i.e the reliance netconnect window does not come to focus. The MessageBos Prints
0x002C01DC
.
This link says thatWinActivate
either returns the handle to the window requested if successful or returns 0 if failed.
In my second case it returns a non zero value. Then why is the window not getting focused?-
Colyn1337 over 10 yearsI'd only like to mention that 2C01DC is the handle.
-