Jump to content

Get Window Focus in Autoit


Recommended Posts

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 help window comes 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 MessageBox 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?

Link to comment
Share on other sites

try this code if it helps

DIM $s=WinActivate("AutoIt Help")
MsgBox(0,"Check",$s)
$s=WinActivate("Reliance Netconnect")
MsgBox(0,"Check",$s)
If IsHWnd($s) Then
MsgBox(64,'It is a Handle','The title of the active window is'&@CRLF&WinGetTitle('[ACTIVE]',''))
Else
MsgBox(16,'Not a Handle','It is not a Handle')
EndIf

Its for debugging only

please give the results

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

I use this when i need to wait and to bring back window

Opt("WinTitleMatchMode", 2)

Opt("WinTextMatchMode", 2)

Func _WinWaitActivate($vWintitle, $vWinText, $timeout)

WinWait($vWintitle, $vWinText, $timeout)

If Not WinActive($vWintitle, $vWinText) Then WinActivate($vWintitle, $vWinText)

WinWaitActive($vWintitle, $vWinText, $timeout)

EndFunc ;==>_WinWaitActivate

Link to comment
Share on other sites

The window that is hidden to tray isnt minimized, its hidden to tray, so don`t try to wianctivate something that isnt there

searching forum for how to doubleclick tray icon can help

edit:

hidden to tray can refere to:

1. Main gui is deleted and will be recreated on double click on tray

2. Main gui is hidden and can be shown on double click on tray or using WinSetState from autoit

3. Main gui is hidden and can not be shown using WinSetState correctly, cos main program code is still w8ting for you to doubleclick on tray so that he can once more start to correctly render window.

Something tell me its nuber 3 cos of your handle that dont show main win.

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

try this code if it helps

DIM $s=WinActivate("AutoIt Help")
MsgBox(0,"Check",$s)
$s=WinActivate("Reliance Netconnect")
MsgBox(0,"Check",$s)
If IsHWnd($s) Then
MsgBox(64,'It is a Handle','The title of the active window is'&@CRLF&WinGetTitle('[ACTIVE]',''))
Else
MsgBox(16,'Not a Handle','It is not a Handle')
EndIf

Its for debugging only

please give the results

On trying your code I get - "The title of the window is"

This is all I get

Link to comment
Share on other sites

The window that is hidden to tray isnt minimized, its hidden to tray, so don`t try to wianctivate something that isnt there

searching forum for how to doubleclick tray icon can help

edit:

hidden to tray can refere to:

1. Main gui is deleted and will be recreated on double click on tray

2. Main gui is hidden and can be shown on double click on tray or using WinSetState from autoit

3. Main gui is hidden and can not be shown using WinSetState correctly, cos main program code is still w8ting for you to doubleclick on tray so that he can once more start to correctly render window.

Something tell me its nuber 3 cos of your handle that dont show main win.

You are right about the System Tray thing. "Reliance Netconnect" is always present in the system tray (maximized or minimized). But is present in the taskbar also if it has not been minimized. It should atleast show up when not minimized, right? OR is there some function to get focus from system tray?
Link to comment
Share on other sites

This is working for me (tested it on avast tray)

#Include <GuiToolBar.au3>
#include "SysTray_UDF.au3"
$iTitles = _SysTrayIconTitles ()
$iProcesses = _SysTrayIconProcesses ()
For $i = 0 To UBound($iTitles) - 1
If StringInStr($iProcesses[$i],'AvastUI.exe') Then
     _GUICtrlToolbar_ClickIndex(ControlGetHandle('[CLASS:Shell_TrayWnd]','','ToolbarWindow321'), $i+1, "left",False,2)
     ConsoleWrite(@CR &"+>Trying to activate "&$iProcesses[$i])
EndIf
ConsoleWrite(@CR & "#" & $i & "Title: " & $iTitles[$i] & ", process: " & $iProcesses[$i])
Next
ConsoleWrite(@CR)

edit:

if your getting (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
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

This is working for me (tested it on avast tray)

#Include <GuiToolBar.au3>
#include "SysTray_UDF.au3"
$iTitles = _SysTrayIconTitles ()
$iProcesses = _SysTrayIconProcesses ()
For $i = 0 To UBound($iTitles) - 1
If StringInStr($iProcesses[$i],'AvastUI.exe') Then
     _GUICtrlToolbar_ClickIndex(ControlGetHandle('[CLASS:Shell_TrayWnd]','','ToolbarWindow321'), $i+1, "left",False,2)
     ConsoleWrite(@CR &"+>Trying to activate "&$iProcesses[$i])
EndIf
ConsoleWrite(@CR & "#" & $i & "Title: " & $iTitles[$i] & ", process: " & $iProcesses[$i])
Next
ConsoleWrite(@CR)

edit:

if your getting (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

Thanks! it works. Is there a way to accept an answer in this forum? If it is there I can accept this answer.
Link to comment
Share on other sites

Not really but with 5 posts on forum, if i remember correctly, you can edit title of your main post and add in front of title (solved) or something.

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
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...