Jump to content

Focus on DataStage Window


Recommended Posts

Hi everybody.

I am a new member here.

I am developing a .bat process which must close a window that open everytime a DataStage utility finishes.

This utility opens a window with the following title: "DataStage".

I searched here and used the following code:

================================================

const $WinTitle = "DataStage"
 
  WinWaitActive($WinTitle)
   If WinGetHandle($WinTitle) <> "" Then
      WinActivate($WinTitle)
      Send("{ENTER}")
      WinWaitClose($WinTitle)
   EndIf

================================================

 
It works fine when the DataStage Window is the focus but If I am working with other things and click on other windows while it is running (changing the focus), this window stays opened and the 'Enter' is not sent.
 
Actually this code is inside a 'loop' (FOR command) - this utility is called many times and also this windows appears many times so, when the focus changes, it waits my manual intervention. Otherwise it runs fine until the end of the loops.
 
What is wrong with my code?
 
I really would like it get focused everytime the utility finishes, even when I am working with other things - like it was running in background.
 
Thank you very much, guys.
 
Best regards,
Joyce A. Recacho
Brazil / São Paulo - SP
 
 
 
 
Link to comment
Share on other sites

Using

_WinAPI_EnumWindows

will give you all the window handles and classes of all windows, you can specify if you want just opened windows or all.

I would use a while loop like so

While 1
; run infinitely
WEnd

That will create an infinite loop that you can put your code inside, or have a function call in the loop.

You seem to have a good grasp on this, so that should be enough to get you going in the right direction to making this completely automated. ;)

Please, feel free to ask more questions though. :D

EDIT: Also, welcome to the AutoIt forum! :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Hey Breathe, thank you very much for your help!!

I run this example above to see how it works. I first executed that .bat to open the 'DataStage Window' (which I want to close automatically)  and then the code above.

I found this 'Datastage window' at the result list but I don´t know exactly how could I use this _WinAPI_EnumWindows.

The result line that is interesting to me is like below:

Row  Col 0                Col1                                                                                  Col2             Col3                                            

[63]   0x007D095C    WindowsForms10.Windows.8.app.0.1639973_r18_ad1  DataStage   F&char 7 read-only objects were omitted   

 Col 4

7572

How can it focus on this window after DataStage utility finishes? - like it was in background, this way I can work in parallel with other tools.

Thank you very much!!

Best regards,

Joyce

Edited by joycerecacho
Link to comment
Share on other sites

Using the class in Col1 and checking to see if that class is a window on your computer at all time like:

Local $class = "WindowsForms10.Windows.8.app.0.1639973_r18_ad1" ;<<<<<<<<<<<<<<<<<<<< this is the class
Local $title = "DataStage"
Local $enum_Windows = _WinAPI_EnumWindows(False), $i, $ctrl_Focus

For $i = 0 To $enum_Windows[0][0] Step 1
    If $enum_Windows[$i][1] = $class Then
        $ctrl_Focus = ControlFocus($title, "", "[CLASS:" & $class & "]")
        If $ctrl_Focus = 1 Then
            MsgBox(0, "", "We got focus!")
        Else
            MsgBox(0, "", "Couldn't get focus")
        EndIf
    EndIf
Next

If the class or handle always changes, let me know. This can be put into a function like Detefon has shown with a while loop as described above. ;)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

or this...

that strange to talk in English with brazilian!  :geek:

Local $sTitle = "DataStage"

HotKeySet("^{END}", "_quit")

While Sleep(250)
    check()
WEnd

Func check()
    If WinExists($sTitle) Then
        WinActivate($sTitle)
        Send("{ENTER}")
        WinWaitClose($sTitle)
    EndIf
EndFunc   ;==>check

Func _quit()
    Exit
EndFunc   ;==>_quit

Visit my repository

Link to comment
Share on other sites

Hey Detefon, are you brazilian too? - hehe of course you are "Detefon, Ação Total"

Could I talk to you in portuguese to get the idea and then return here to post the solution in English?

Maybe through email, I dont know.

I think I didnt get the main idea cause It is not working yet. I mean, my .bat still stops waiting the 'Enter', the focus at the DataStage window.

Thank you guys ... I am testing here.

:D
 

Edited by joycerecacho
Link to comment
Share on other sites

Why not http://forum.autoitbrasil.com/

EDIT: We can use Google translate, but just don't make a habit of posting it in Portuguese, because this is an English forum. :)

Eu não teria um problema descobrir uma traduzido casal frases.

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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