Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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")

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")

This does not work, i.e the reliance netconnect window does not come to focus. The MessageBos Prints 0x002C01DC.
This link says that WinActivate 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?

share|improve this question
I'd only like to mention that 2C01DC is the handle. – Colyn1337 Oct 11 '13 at 17:46
up vote 3 down vote accepted

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)
_GUICtrlToolbar_ClickIndex(ControlGetHandle('[CLASS:Shell_TrayWnd]','','ToolbarWindow321'), $index, "left",False,2)
WinActivate("Reliance Netconnect")
WinWaitActive("Reliance Netconnect")
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_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
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .