Jump to content

Interacting W/ Sub Windows


Recommended Posts

I glanced through the last 10 pages of posts real quick, but didn't see anything pertaining to this as of yet; but I can't imagine I'm the only one who's had this problem.

I'm trying to have AutoIT v3 recognize sub windows and menus w/in another program; such as the File -> Open window in any program. This apparently is not a window itself, just a smaller portion of the already running program. I run into problems when using

Send("^o")
WinWaitActive("Open")

Hopefully these lines of code would hit alt-O to launch the File -> Open window and then wait for the window to load before continuing on with the code; but it does not.

The code speeds along before the window can load, creating some problems. I could always plug in a solid wait time, but I'd have to imagine what the longest possible wait would be; hence making the code extremely un-efficient, etc, etc, etc.

Suggestions? Many thanks,

Eric

Link to comment
Share on other sites

  • Developers

try this to see if that works for you...:

Opt("WinTitleMatchMode", 2)
Run("notepad.exe")
WinWaitActive("- Notepad")
Send("^o")
WinWaitActive("Open")
msgbox(0,'open','now')

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

No, with that added command the msgbox definately opens prior to the Open sub-window opening. I think the problem is a little deeper than that; when the WinWaitActive command is searching for a string in the title, it's looking at the title as seen in the Task Bar, when minimzed. The 'Open' sub-window never makes an appearance there, so I'm having difficulty getting the commands to recognize it as a window.

Thanks,

Eric

Link to comment
Share on other sites

Will I ever run into any problems interacting with that window after it is detected, but before it is visible? I do not want the code to get ahead of the program:: I am running a very heavy-duty program, so there are wait-times for processing and such.

Thanks,

Eric

Link to comment
Share on other sites

Haven't tried it out, but was looking through the AutoIt Help file, and I noticed this option:

WinSearchChildren - Allows the window search routines to search child windows as well as top-level windows.

0 = Only search top-level windows (default)

1 = Search top-level and child windows

Opt("WinSearchChildren", 1)
Send("^o")
WinWaitActive("Open")
Link to comment
Share on other sites

A window exists and can be detected before it becomes visible...

@Valik:

I'm running into some serious problems with AutoIT detecting and assuming that a window is activated before it actually is. I've watched AutoIT Window Spy as I run the program, and the new window's title appears before the window, by a significant amount. :D

I'd rather not 'hardcode' in wait times, ie I don't want to toss in a Sleep () or Opt ("WinWaitDelay", ""). Is there a way to monitor the 'Edit1' field for the blinking cursor?

Thanks

Link to comment
Share on other sites

Why don't you just send whatever it is you need to send directly to the controls through the Control functions? They will work regardless of whether the window has appeared yet or not.

Keep in mind, if AutoIt says it is created and active, Windows also says it is, irrelevant what you see or think.

Could this be related to the way the open dialog searches CD drives (And I would assume mounted drives of other types as well)? I know that when I open an Open Dialog when I have CD's in the drives, Windows sometimes has to spin them up and read them before I can use the dialog.

Link to comment
Share on other sites

@Valik: Actually, I'm running into a problem where on certain machines, the File -> Open window registers as active, the code enters the path/file, hits enter, and waits for the file to open... ... then the open window appears too late to use the path/file previously sent. It shouldn't be accessing the CD/DVD drive; only a shared network drive.... but even that shouldn't really matter to load the 'Open' window.

I agree the Control functions should work, infact they do work on my PC, which is why I find this problem especially frustrating. I'm trying to generate my own version of the WinWaitActive function (at Larry's suggestion) with WinGetState and some relational operators.

If you have any other suggestions, I'm all ears;: I'll let you know how my "customized" WinWaitActive function works out.

Link to comment
Share on other sites

You could try a loop of winstate.

Opt("WinTitleMatchMode", 3)
while WinGetState("Open", "")<>15
sleep(100)
wend
Opt("WinTitleMatchMode", 1)

...edit...actually thinking about your situation,

Opt("WinSearchChildren", 1)
Send("^o")
WinWaitActive("Open")
while winexists("Open")
ControlSend ( "Open", "", "Edit1", "^ac:\test.txt{enter}")
wend
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Guest RPC@24018

This works very well for me in v3.

ForceFocus('Notepad','')

WinMenuSelectItem('Notepad','','&File','&Open')

ForceFocus('Open','File &name:')

Send('SomeFile.txt')

Send('{Enter}')

Exit

Func ForceFocus($Caption,$ScreenText)

Dim $Caption, $ScreenText

While 1

WinActivate($Caption,$ScreenText)

If WinActive($Caption,$ScreenText) Then ExitLoop

Wend

Return

EndFunc

In v2

Something like this should work

$Caption = 'Notepad'

$ScreenText = ''

Gosub ForceFocus

Send('^o')

$Caption = 'Open'

$ScreenText = 'File &name:'

Gosub ForceFocus

Send('SomeFile.txt')

Send('{Enter}')

Exit

:ForceFocus

WinActivate($Caption,$ScreenText)

If WinActive($Caption,$ScreenText) Then

Return

Else

Goto ForceFocus

EndIf

... I can't believe I'm forgetting v2 syntax already.

Sorry about that. But I hope this helps.

Link to comment
Share on other sites

Hi I am having the same problems with one of my scripts.

I have tried the suggested solutions but nothing seems to work 100% :D

Any further help would be appreciated.

I usely solve this with

Run("notepad")
MyWinWaitActivate("Untitled","")

Func MyWinWaitActivate ($title,$text )
    WinWait ( $title, $text )
    if NOT WinActive ( $title, $text ) then WinActivate ( $title, $text )
   WinWaitActive ( $title, $text)
    Return 
EndFunc ; MyWinWaitActivate

I hope that hep :huh2:

Link to comment
Share on other sites

Alright, here's a little function that I threw together that seems to work great for waiting while the processor works, things load, and for a given window entitled $WINDOW to become active...

; Function to check CPU activity and mouse icon for use
Func _Busy( $WINDOW )
    Do
        Do
            TrayTip ( "", "Waiting for " & $WINDOW, 1 )
            Sleep ( 100 )
            $CPU = StatusbarGetText ( "Windows Task Manager","",2 )
            $CPU = StringTrimRight ( $CPU, 1) ; remove the %
            $CPU = StringRight ( $CPU, 3 ) ; get the possible 3 digits
            $CPU = Int ( StringReplace ( $CPU,":","" ) ) ; remove colon and convert to int.
            TrayTip ( "CLEAR", "", 0 )
        Until  $CPU < 15
        Do
            TrayTip ( "", "Waiting for " & $WINDOW, 1 )
            Sleep ( 100 )
            TrayTip ( "CLEAR", "", 0 )
        Until  MouseGetCursor ( ) <> 15
        WinActivate ( $WINDOW )
        TrayTip ( "", "Waiting for " & $WINDOW, 1 )
        $STATE = WinGetState ( $WINDOW )
        TrayTip ( "CLEAR", "", 0 )
    Until ( BitAND ( $STATE, 15 ) = 15 or BitAND ( $STATE, 13 ) = 13 or BitAND ( $STATE, 47 ) = 47 )
EndFunc ; --> _Busy
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...