Jump to content
Sign in to follow this  
Sam137

Help in activating the window

Recommended Posts

Sam137

I could not activate a window, while i run the script one window is coming but that window is not at focus, i cannot get the title of the window also. Its not that all the times only a particular window comes up.

I need to:

At one point in the code i need to set focus to the window which comes up(dont know the title)

Share this post


Link to post
Share on other sites
bogQ

and what do you know?

win class, or win text? anything?

where is your code? where is infro from autoit win info tool?

picture of a problem? anything?

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.

 

Share this post


Link to post
Share on other sites
Sam137

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         Sam Charles

 Script Function:
    This script compares the old reports(other than the ones changed in the current release) in the new and the old environemnts and 
    writes onto a error files if it encounters one.

#ce ----------------------------------------------------------------------------

;HDM executable directory path and the RAD to Run:

$hdmexePath = InputBox("HDM Executable Directory", "Enter path to your executable directory", "C:\", "")

;Validating the HDM path 
if StringRight($hdmexePath,1) <> "\" Then
    $hdmPath = $hdmexePath & "\"
Else
    $hdmPath = $hdmexePath 
endIf
    
#include <Excel.au3>
    
;Report's List location
$RepList = "C:\Sam's Personal\Reports List.xlsx"
$oExcel = _ExcelBookOpen($RepList)

        If @error = 1 Then
            MsgBox(0, "Error!", "Unable to Create the Excel Object")
            Exit
        ElseIf @error = 2 Then
            MsgBox(0, "Error!", "File does not exist!")
            Exit
        EndIf

_ExcelSheetActivate($oExcel, "Report List")

$row = 0
$col = 0


; define return codes here as constants
$INVALID_PARAM_CNT      = 1
;$INVALID_PATH          = 2
$PATH_DOESNT_EXIST      = 2  ;4
$REPORT_NOT_FOUND       = 4  ;8
$RAD_NOT_FOUND          = 8  ;16
$INVALID_REPORT_TYPE    = 16 ;32
$REPORT_ENGINE_ERROR    = 32
;$REPVIEWER_LAUNCH_ERROR    = 64




Dim $errorCode = 0
; Invoking the wfront.exe from the current executable directory

    
;Calculating the current day password

$DayPart = @MDAY
$MonthPart = @MON
$Code1 = StringLeft((Mod(Mod(Number($DayPart/10) + $MonthPart, 10),10)),1)
$Code2 = StringLeft((Mod(Mod(Number($MonthPart/10) + $DayPart,10),10)),1)

if $Code1 > $Code2 then
    $Code3 = 9 - $Code1
else
    $Code3 = 9 - $Code2
endif

$CurrPwd = $Code3*100 + $Code2*10 + $Code1

;Entering the Username and Password

if StringLen($CurrPwd) = 2 Then
    $CurrPwd = 0 & $CurrPwd
ElseIf StringLen($CurrPwd) = 1 Then
    $CurrPwd = 0 & 0 & $CurrPwd
EndIf
    $FirstDigit = StringLeft($CurrPwd,1)
    $SecDigit = StringMid($CurrPwd,2,1)
    $ThirdDigit = StringRight($CurrPwd,1)
    
    
        ; identify all the window titles here
        Dim $hdmloginwin = "Health Data Management Front Login"
        Dim $hdmfrontwin = "Health Data Management Front Menu"
        Dim $hdmreportwin = "Health Data Management  Reporter"
        Dim $hdmradwin = "Report Access Definitions"
        Dim $listingsWin = "Current Listings"
        Dim $summariesWin = "Current Summaries"
            
    
        If FileExists($hdmPath) Then        ; at this point, we have to assume RAD/REP/REPORT are found, until proven otherwise
            
            Opt("WinWaitDelay", 500)  ; delay by 500 milliseconds
            ;MsgBox(0, "Debug", "Getting Ready to launch front")

            ; change working directory
            FileChangeDir($hdmPath)
            Run($hdmPath & "wfront.exe")              ; launch HDM Front
            WinWaitActive($hdmloginwin)   ;("Health Data Management Front Login")
            Send("CODE3")
            Send("{TAB}") 
            Send($FirstDigit & " " & $SecDigit & " " & $ThirdDigit)
            Send("{enter}")

                    While WinExists($hdmfrontwin) AND NOT WinActive($hdmfrontwin) ;Then
                        Sleep(100)
                        WinActivate($hdmfrontwin)
                        ;MsgBox(0, "Sam debug", "in loop waiting for winactive front")
                    WEnd 
        
            ControlFocus($hdmfrontwin, "", "TTBXToolbar2")
            WinActivate($hdmfrontwin)


            ;THIS GETS THE Reporter WINDOW 
            ;MsgBox(0, "gf debug", "after activate hdm front before send p and r")
            Sleep(100)
            Send("{ALTDOWN}p{ALTUP}er")

            ;wait for reporter menu, then launch RAD list
                    While NOT WinExists($hdmreportwin)
                        Sleep(100)
                    WEnd
                    ;MsgBox(0, "Sam debug", "waited for reporter win")
        
                    If WinExists($hdmreportwin) Then
                        Sleep(100)
                        WinActivate($hdmreportwin)
                    EndIf  
        
                    WinActivate($hdmreportwin)
                    Sleep(200)
                    ;Send("{ALTDOWN}t{ALTUP}a")     
                    ;MsgBox(0, "gf debug", "selecting RAD")
        
        
            ;MsgBox(0, "Sam debug", "waiting for reporter")

            ; after selecting RAD, wait until Reporter window is up again
                While NOT WinExists($hdmreportwin)
                    Sleep(100)
                WEnd
            
                While NOT WinActive($hdmreportwin)  ;("Health Data Management  Reporter")
                    Sleep(100)
                    WinActivate($hdmreportwin)
                WEND

                ;MsgBox(0, "gf debug", "found reporter window")
                
                
            WinSetState($hdmfrontwin,"",@SW_MINIMIZE)
            WinSetState("Microsoft Excel - Reports List.xlsx","",@SW_MINIMIZE)
            
            Dim $yLoc = 7
            
    For $row = 2 to 225
        $repName = _ExcelReadCell($oExcel, $row, 1)
        $repType = _ExcelReadCell($oExcel, $row, 2)
        $radName = _ExcelReadCell($oExcel, $row, 3)
        
        
            ; select report type and report here
            Dim $windownm = ""
            Switch ($repType)
            Case "Listing"
                Send("{ALTDOWN}r{ALTUP}l")
                While NOT WinActive($listingsWin)
                    Sleep(100)
                    WinActivate($listingsWin)
                WEnd
                $windownm = $listingsWin   ;"Current Listings"

            Case "Summary"
                Send("{ALTDOWN}r{ALTUP}s")
                While NOT WinActive($summariesWin)
                    Sleep(100)
                    WinActivate($summariesWin)
                WEnd
                $windownm = $summariesWin   ;"Current Summaries"
                
            Case Else
                $errorCode = BitOR($errorCode, $INVALID_REPORT_TYPE)
                ; don't exit quite yet - close windows first
                closeReporter()
                Exit $errorCode
            EndSwitch

            While NOT WinActive("Current")
                Sleep(100)
                ;If NOT WinActive("Current") Then WinActivate("Current")
            WEND

            ;MsgBox(0, "Debug", "Report Name we are looking for:" & $repName)


            Dim $foundReport = 0
            Dim $prevRep = ""
            Dim $currRepTitle = ""
            Dim $xLoc = 191
            
            
            
            
            if ($errorCode == 0) Then
                ; this is where we would start while loop, while report title we're searching has not been found
                ; position window and click first report
                sleep(500)
                WinMove($windownm, "", 100, 100)
                ;MouseClick("left",191,$yLoc)       ; increment mouse click location to do next report (+15), if using mouse
                ControlClick($windownm,"","TElTreeView1","left",1,$xLoc,$yLoc)
                Sleep(100)
            
                ;Searching for the Report       
                While ($foundReport == 0)
                        Send("{ALTDOWN}r{ALTUP}e")
                        
                        While NOT WinExists("Properties") 
                        Sleep(100)
                            If NOT WinActive("Properties") Then WinActivate("Properties")
                        WEND
                        Sleep(100)

                        ; get report title based on type
                        $currRepTitle = _getReportTitle($repType)

                        ;MsgBox(0,"debug", "report title is now" & $currRepTitle)
                        ;MsgBox(0, "Debug", "Current report title says: " & $currRepTitle)  
                        ;MsgBox(0, "Debug", "Previous report title says: " & $prevRep)  
                        ;MsgBox(0, "Inexcel", $repName) 
                        ;MsgBox(0, "In sys", $currRepTitle) 
                            If ( StringUpper(StringStripWS($currRepTitle,2)) == StringUpper(StringStripWS($repName,2)) ) Then       
                                ; strip all trailing white space from report titles and make case insensitive
                                $foundReport = 1
                                ;MsgBox(0, "Debug", "Found already!")
                                ExitLoop
                            EndIf
                        
                            If ($prevRep == $currRepTitle) Then     ; this means we've reached the end of the list
                                MsgBox(0, "Debug", $repName & "report not found")
                                If ControlCommand("Properties", "Cancel", "TAdvGlowButton2", "IsEnabled", "") Then
                                    ControlClick("Properties", "Cancel", "TAdvGlowButton2") 
                                EndIf
                                ExitLoop
                            EndIf
                        $prevRep = $currRepTitle
                
                        While NOT ( ControlCommand("Properties", "Cancel", "TElPopupButton2", "IsEnabled", "") Or ControlCommand("Properties", "Cancel", "TAdvGlowButton2", "IsEnabled", "") )
                            Sleep(100)
                            WinActivate("Properties")
                        WEnd
                        
                        If ControlCommand("Properties", "Cancel", "TElPopupButton2", "IsEnabled", "") Then
                            ControlClick("Properties", "Cancel", "TElPopupButton2")
                        EndIf
                        
                        If ControlCommand("Properties", "Cancel", "TAdvGlowButton2", "IsEnabled", "") Then
                            ControlClick("Properties", "Cancel", "TAdvGlowButton2") 
                        EndIf
                        Sleep(200)
                        
                        If WinExists("Edit Warning") Then
                            While WinExists("Edit Warning")
                                  WinActivate("Edit Warning")
                                  ControlClick("Edit Warning", "&Yes", "TButton2")
                            WEnd
                        EndIf
                        Sleep(200)          ; GF added 4/11/2007, to wait for window to catch up
                        Send ("{DOWN}")   ; send down arrow and go to next report
                WEnd            ; end of while loop to iterate thru list of reports
            
                        If ($foundReport) Then
                            ;MsgBox(0, "Debug", "Found the report: " & $repName)
                            ; let's execute the report we do find
                            _execReport($repType)
                        Endif 
            EndIf
    $yLoc += 15
    Next
Else
    MsgBox(0, "Debug", "HDM PATH does not exist")
    $errorCode = BitOR($errorCode, $PATH_DOESNT_EXIST)
EndIf

_ExcelBookClose($oExcel)

; end of main code












; functions start here
Func closeReporter()
    ; exit out of Reporter menu (note 2 spaces between "Management" and "Reporter")
    While NOT WinActive($hdmreportwin)  ;("Health Data Management Reporter")
        Sleep(100)
        WinActivate($hdmreportwin)
    WEND
    ;If Not WinActive("Health Data Management  Reporter") Then WinActivate("Health Data Management  Reporter")
    ;WinWaitActive("Health Data Management  Reporter")
    ;Send("!F")Send("x")
    Send("{ALTDOWN}f{ALTUP}x")
    Sleep(200)

    ; exit Front
    ;If Not WinActive("Health Data Management Front Menu") Then WinActivate("Health Data Management Front Menu")
    ;WinWaitActive("Health Data Management Front Menu")
    ;Send ("!P")    Send ("x")
    
    While NOT WinActive($hdmfrontwin)
        Sleep(100)
        WinActivate($hdmfrontwin)
    WEND
    Send("{ALTDOWN}p{ALTUP}x")
    Sleep(200)
EndFunc




Func _getReportTitle($rType)
    
    While NOT WinExists("Properties")
        Sleep(100)
    WEnd

    While NOT WinActive("Properties")
        Sleep(100)
        WinActivate("Properties")
    WEnd

    Switch ($rType)
    Case "Listing"
        $rTitle = ControlGetText("Properties for Listing", "", "TElPanel56")
    Case "Summary"
        $rTitle = ControlGetText("Properties for Summary", "", "TElPanel41")
    EndSwitch
    Sleep(100)
    Return $rTitle
EndFunc



Func _execReport($rType)
    $Norecords = false
    ; send command to build
    Send("{ALTDOWN}b")
    Sleep(200)
    
    ; check if any error messages come up and close all of them before executing
    If WinExists("HDM Report Engine") Then
        Sleep(100)
        While NOT WinActive("HDM Report Engine")
            Sleep(100)
            WinActivate("HDM Report Engine")
        WEnd
        ControlClick("HDM Report Engine", "OK", "TButton1")
        Sleep(100)
    EndIf
    
    

    While NOT WinExists("Report Complete")
        while WinExists("Record Filter (Initialization)")
            Sleep(200)
            
            If NOT WinActive("Record Filter (Initialization)") Then 
                WinActivate("Record Filter (Initialization)")
                Sleep(200)
            EndIf
        
            While WinActive("Record Filter (Initialization)")   ; this is for when a filter prompt appears
                ; specify default values
                ControlClick("Record Filter (Initialization)", "OK", "TElPopupButton5")
                Sleep(100)
                ; if reporter engine error window comes up - close it
                    If WinExists("HDM Report Engine") Then
                        Sleep(100)
                        While NOT WinActive("HDM Report Engine")
                            Sleep(100)
                            WinActivate("HDM Report Engine")
                        WEnd
                        While NOT ControlCommand("HDM Report Engine", "OK", "TButton1", "IsEnabled", "")
                        Sleep(100)
                        WEnd
                        ControlClick("HDM Report Engine", "OK", "TButton1")
                        Sleep(100)
                    EndIf
            WEnd
        WEnd        
            
        While WinExists("Classification Key (Occ Filter)")
            Sleep(200)
            If NOT WinActive("Classification Key (Occ Filter)") Then 
                    WinActivate("Classification Key (Occ Filter)")
                    Sleep(200)
            EndIf
                
                While WinActive("Classification Key (Occ Filter)")  ; this is for when a filter prompt appears
                ; specify default values
                ControlClick("Classification Key (Occ Filter)", "OK", "TElPopupButton5")
                Sleep(100)
                ; if reporter engine error window comes up - close it
                    If WinExists("HDM Report Engine") Then
                        Sleep(100)
                        While NOT WinActive("HDM Report Engine")
                            Sleep(100)
                            WinActivate("HDM Report Engine")
                        WEnd
                        While NOT ControlCommand("HDM Report Engine", "OK", "TButton1", "IsEnabled", "")
                        Sleep(100)
                        WEnd
                        ControlClick("HDM Report Engine", "OK", "TButton1")
                        Sleep(100)
                    EndIf
                WEnd
                Sleep(200)
        WEnd
            
            If WinActive("Properties") Then 
                ;MsgBox(0, "gf debug", " norecords")
                $Norecords=true
                ExitLoop
            EndIf   
        Sleep(200)  
    WEnd
        
    
    If NOT WinActive("Report Complete") Then
        WinActivate("Report Complete")
        sleep(100)
    EndIf   
    ;MsgBox(0,"Debug", "I am here")
    ControlClick("Report Complete", "Yes, now", "TAdvGlowButton2")
    ; check if any error messages come up and close all of them before executing
    If WinExists("HDM Report Engine") Then
        Sleep(100)
        While NOT WinActive("HDM Report Engine")
            Sleep(100)
            WinActivate("HDM Report Engine")
        WEnd
        ControlClick("HDM Report Engine", "OK", "TButton1")
        Sleep(100)
    EndIf
    Sleep(2000)
    
    If NOT WinActive("Report Viewer") Then 
            WinActivate("Report Viewer")            
    EndIf
        Sleep(500)
            Send("{ALTDOWN}f{ALTUP}s")  
            sleep(1000)
            ControlSetText("Save As","","Edit1","C:\Sam's Personal\" & $repName)
            sleep(200)
            ControlCommand("Save As","","ComboBox2","SelectString","Excel(*.xls)")
            ;ControlClick("Save As", "", "[CLASS:ComboBox; INSTANCE:2]","left",1,121,9)
            ;Send("{TAB}")
            ;sleep(1000)
            ;Send ("{DOWN}")
            ;sleep(1000)
            ;Send("{DOWN}")
            ;sleep(1000)
            ;Send("{ENTER}")
            sleep(1000)
            ControlClick("Save As", "", "[CLASS:Button; INSTANCE:2]","left",1,33,10)
        
            While NOT WinActive("Report Viewer")  ;Closing Report Viewer Window
                Sleep(100)
                WinActivate("Report Viewer")
            WEND    
            Sleep(1000)
                Send("{ALTDOWN}f{ALTUP}x")
                Sleep(200)
            While NOT WinActive("Properties")
                Sleep(100)
                WinActivate("Properties")
            WEnd
                ControlClick("Properties", "Cancel", "TAdvGlowButton2") 
                If WinExists("Edit Warning") Then
                    While WinExists("Edit Warning")
                      WinActivate("Edit Warning")
                      ControlClick("Edit Warning", "&Yes", "TButton2")
                    WEnd
                EndIf
                Sleep(200)      
            
            
            While NOT WinActive($summariesWin)
                    Sleep(100)
                    WinActivate($summariesWin)
            WEnd
                    Send("{ALTDOWN}f{ALTUP}x")
                    Sleep(200)
            
                
            
EndFunc

Share this post


Link to post
Share on other sites
bogQ

ok can i get info from autoit win tool on that specific win that you need to activate

*tab named Summary on autoit win info tool, copy paste all the data

and picture if you have one from that specific win that you need to activate

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.

 

Share this post


Link to post
Share on other sites
Sam137

Here is is the Summary on the Window Info tool of that window which is not focussed.

>>>> Window <<<<

Title: Record Filter (Initialization)

Class: TfrmRdlPopup

Position: 392, 370

Size: 496, 284

Style: 0x16C40000

ExStyle: 0x00010100

Handle: 0x00120F6A

>>>> Control <<<<

Class:

Instance:

ClassnameNN:

Name:

Advanced (Class):

ID:

Text:

Position:

Size:

ControlClick Coords:

Style:

ExStyle:

Handle:

>>>> Mouse <<<<

Position: 447, 383

Cursor ID: 0

Color: 0xD7A350

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

Use this question/answer pair automatically

Use this question/answer pair as default

Use to answer all remaining questions automatically

Use answer as default to all questions

Normal

Use

Copy

Cancel

Less Options

OK

>>>> Hidden Text <<<<

Share this post


Link to post
Share on other sites
Sam137

there are 2 possibilities - One time i can get "Record Filter (Initialization)" another time i can get "Classification Key (Occ Filter)" window

Share this post


Link to post
Share on other sites
bogQ

if they dont have identical title and dont have identical unique class TfrmRdlPopup you can get new win name from comparing data from WinList returning array.

if they dont have identical title and have identical unique class TfrmRdlPopup, use claass instead of title

for notepad is WinWait("[CLASS:Notepad]") (you can use [class: on almost any command instead of 'title' parametar) for you its probably WinWait("[CLASS:TfrmRdlPopup]") :mellow:

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.

 

Share this post


Link to post
Share on other sites
Sam137

I tried all the things which you had said. Even if i code winactivate or winwaitactive its not setting the focus. I dont have any other window active at that point, wondering where is the focus.

Share this post


Link to post
Share on other sites
bogQ

do you have link to download that program?

telling that you cant activate something with winactivate is realy strange program behavior.

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.

 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.