Jump to content

How to make sure that menu is activated?


Recommended Posts

Hello everyone,

While running script I've came accross little problem. Menu called this way:

WinMenuSelectItem("Impromptu", "", "&File", "Save &As...")

seems not to be activated each time (it is called several times in loop).

Script is going further, and some of the results are not saved.

My question is - what to do to make sure that menu is activated?

I've tried with WinWait etc. but with no success so far...

Link to comment
Share on other sites

Hello everyone,

While running script I've came accross little problem. Menu called this way:

WinMenuSelectItem("Impromptu", "", "&File", "Save &As...")

seems not to be activated each time (it is called several times in loop).

Script is going further, and some of the results are not saved.

My question is - what to do to make sure that menu is activated?

I've tried with WinWait etc. but with no success so far...

Any ideas, anyone?

Link to comment
Share on other sites

  • Moderators

Any ideas, anyone?

Well if your opening a menu, I'm sure it's not for the heck of it, do a check right afterwards to see what your trying to do is actually done, if it's a window maybe If WinExists(Windowname) Then etc... If it's an .exe then If ProcessExists(.exeName) if it's a File, If FileExists() etc... Simple error checking is all.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Well if your opening a menu, I'm sure it's not for the heck of it, do a check right afterwards to see what your trying to do is actually done, if it's a window maybe If WinExists(Windowname) Then etc... If it's an .exe then If ProcessExists(.exeName) if it's a File, If FileExists() etc... Simple error checking is all.

Well, either it is not that simple or I am doing something wrong...

in the first case:

If Not WinExists("Save As") Then WinWaitActive("Save As","")

script hungs waiting for a window (if I open menu "Save As" manually it will continue till next loop)

in the second case:

If Not WinExists("Save As") Then WinMenuSelectItem("Impromptu", "", "&File", "Save &As...")

script sometimes opens window "Save As" twice

really confusing...

Edited by 3telnick
Link to comment
Share on other sites

  • Moderators

Well, either it is not that simple or I am doing something wrong...

in the first case:

If Not WinExists("Save As") Then WinWaitActive("Save As","")

script hungs waiting for a window (if I open menu "Save As" manually it will continue till next loop)

in the second case:

If Not WinExists("Save As") Then WinMenuSelectItem("Impromptu", "", "&File", "Save &As...")

script sometimes opens window "Save As" twice

really confusing...

What window are you trying to use this on, you also may want to look at Opt("WinSearchChildren", 1) (and what Opt('WinTitleMatchMode', Number Here Are You Using?).) Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

What window are you trying to use this on, you also may want to look at Opt("WinSearchChildren", 1) (and what Opt('WinTitleMatchMode', Number Here Are You Using?).)

After calling "Save As" menu I got typical "windows like" "Save as" window.

According to the options you've mentioned - I am not setting them so values are default.

Link to comment
Share on other sites

  • Moderators

After calling "Save As" menu I got typical "windows like" "Save as" window.

According to the options you've mentioned - I am not setting them so values are default.

Well try
Opt("WinSearchChildren", 1)
Opt("WinTextMatchMode", 2)
At the top of your script and see if that helps. Also, how did you get the menu id's? The repeat windows is probably part of your code... I suggest showing that (your script) if you need real help.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Well try

Opt("WinSearchChildren", 1)
Opt("WinTextMatchMode", 2)
At the top of your script and see if that helps. Also, how did you get the menu id's? The repeat windows is probably part of your code... I suggest showing that (your script) if you need real help.
Options added and with no changes...

Menu id is derived from its name in the program I am running...

Here is the beginning of the loop:

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

;only for those starting with "#"

If StringLeft($file,1)="#" Then

;run report

WinWaitActive("Impromptu","")

WinMenuSelectItem("Impromptu", "", "&Report", "&Prompt..." )

;check "Prompts" window

WinWait("Prompts","")

If Not WinActive("Prompts","") Then WinWaitActive("Prompts", "")

WinWaitActive("Prompts","")

;send params

Send(StringRight($file,4) & "{ENTER}")

;wait till done

WinWaitNotActive("Impromptu","Press ESC to cancel")

;check "Impromptu" window

WinWait("Impromptu","")

If Not WinActive("Impromptu","") Then WinWaitActive("Impromptu","")

WinWaitActive("Impromptu","")

;save report

WinMenuSelectItem("Impromptu", "", "&File", "Save &As...")

If Not WinExists("Save As") Then WinWait("Save As")

Send($file & "\{ENTER}")

The last line seems to be sending to the non existing window or script hungs on the last but one line...

Edited by 3telnick
Link to comment
Share on other sites

if I change line concerning saving report activity to the code below:

WinMenuSelectItem("Impromptu", "", "&File", "Save &As...")

If Not WinExists("Save As","&Save") Then

MsgBox (0,"saving...",$file, 1)

sleep (2000)

WinMenuSelectItem("Impromptu", "", "&File", "Save &As...")

EndIf

it do not activate menu at all - seems to be totally out of control...

Quite strange, because menu which runs report works...

Edited by 3telnick
Link to comment
Share on other sites

Something is wrong with that "Save As" window. I've just tried two sequences of code:

1. Hungs on WinWait command...

WinMenuSelectItem("Impromptu", "", "&File", "Save &As...")

WinWait("Save As","")

If Not WinActive("Save as","") Then WinWaitActive("Save as","")

WinWaitActive("Save as","")

Do

MsgBox(0,"","",1)

Until Not WinExists("Save as","")

2. Does loop forever with already opened "Save as" window in the background...

WinMenuSelectItem("Impromptu", "", "&File", "Save &As...")

Do

MsgBox(0,"","",1)

Until Not WinExists("Save as","")

Is there any other way to check if window exists? Or force to activate it?

I feel hopeless...

P.S.

It seems I'm tired... loop has wrong exit check

But o f course problem remains unsolved even if I delete "Not" from the loop

Edited by 3telnick
Link to comment
Share on other sites

Save as

or

Save As

?

Lar.

Save As, of course "Save As"...

But it is not the point (just my error after changing code for the 1001 time)...

The point is that window "Save As" sometimes just do not appear...

Now I'm trying quite eccentric idea to cope with that problem:

WinMenuSelectItem("Impromptu", "", "&File", "Save &As...")

While Not WinExists("Save As","")

Sleep (500)

If Not WinExists("Save As","") Then WinMenuSelectItem("Impromptu", "", "&File", "Save &As...")

WEnd

Works so far - but I need to check if delays on saving or opening files have any influence on it...

Link to comment
Share on other sites

Latest news: It do not work.

Sometimes script manages to open window "Save As" twice for the same report :)

I can try to lengthen delay in Sleep command, but it will not solve the problem for good.

P.S.

I give up for today... have no the faintest idea what can I do to improve it...

Edited by 3telnick
Link to comment
Share on other sites

Hello,

New day new strength. Ufortunately lengthening delay in Sleep section of the script, as it was easy to foreseen, didn't work properly. The only idea I have now is to change command which calls menu to the phisical mouse cliks :) Maybe that way i can make this script work the way I want :(

Link to comment
Share on other sites

You can believe it or not, but it doesn't work too :)

But I think I can narrow down problem....

I suspect that all because of previous command, that is:

WinWaitNotActive("Impromptu","Press ESC to cancel")

;check "Impromptu" window

WinWait("Impromptu","")

If Not WinActive("Impromptu","") Then WinWaitActive("Impromptu","")

WinWaitActive("Impromptu","")

;save report

WinMenuSelectItem("Impromptu", "", "&File", "Save &As...")

I've added delay after it and I'm under testing now...

Edited by 3telnick
Link to comment
Share on other sites

I've replaced:

WinWaitNotActive("Impromptu","Press ESC to cancel")

with

Do

Sleep(1000)

Until MouseGetCursor()<>15

As for me, window returns control too early while in fact is still generating report.

Now script is waiting till "hour glass" cursor disappears from the screen...

Will see if it works :)

Link to comment
Share on other sites

Generally speaking it is working now...

But there is a snag in it - when I'm connected via VNC (sort of remote console application) mouse movements are sent to the window even if i declare BlockInput and _MouseTrap within code. As a result, script can be stopped by accidental mouse movement (because it is checking mouse cursor state).

Any ideas how to deal with that?

Edited by 3telnick
Link to comment
Share on other sites

Hello again,

To make sure that report is really done I had to combine two things together:

1. wait till "hour glass" cursors disappears from the screen

2. additionaly wait till window is deactivated

But new problem raised - when testing sript with windows AT command it works.

When setting it to start early in the morning it hangs on the first active window.

Below begginig of the code with highlited line where it stops...

#include <Date.au3>

#include <Array.au3>

#include <Misc.au3>

Opt("WinSearchChildren", 1)

Opt("WinTitleMatchMode", 2)

Opt("WinTextMatchMode", 1)

Opt("TrayIconDebug", 1)

Opt("WinWaitDelay", 500)

;Opt("MouseCoordMode",2)

;Opt("TrayIconHide", 1)

Dim $myArray[1]

_ArrayAdd( $myArray,"SZOR.pdf")

$max= UBound($myArray)-1

;Generowanie PDF

TrayTip("", "Automatyczne generowanie PDF", 5)

FileChangeDir("C:\inetpub\ftproot\RepliGo")

$search = FileFindFirstFile("*.*")

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

;run Impromptu Administrator

Run("E:\Program Files\Cognos\cer4\bin\impadmin.exe", "e:\Program Files\Cognos\cer4\bin\", @SW_MAXIMIZE)

;check "Impromptu" window

WinWaitActive("Impromptu","")

If Not WinActive("Impromptu","") Then WinWaitActive("Impromptu","")

WinWaitActive("Impromptu","")

WinMenuSelectItem("Impromptu", "", "&File", "&Open..." )

WinWaitActive("Open","")

If Not WinActive("Open","") Then WinWaitActive("Open","")

WinWaitActive("Open","")

;open report template file

Send("E:\SAPLSW\Source\SZOR_EMIGO\SZOR_rewir.imr{ENTER}")

;check "Log on" window

WinWaitActive("Cognos Common Logon","")

If Not WinActive("Cognos Common Logon","") Then WinWaitActive("Cognos Common Logon","")

WinWaitActive("Cognos Common Logon","")

Send("user{TAB}pass{ENTER}")

WinWaitActive("Catalog Logon","")

If Not WinActive("Catalog Logon","") Then WinWaitActive("Catalog Logon","")

WinWaitActive("Catalog Logon","")

Send("{ENTER}")

;check "Prompts" window

WinWait("Prompts","")

If Not WinActive("Prompts","") Then WinWaitActive("Prompts", "")

WinWaitActive("Prompts", "")

Send("{ESC}")

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

;only for those starting with "#"

If StringLeft($file,1)="#" Then

;run report

WinWaitActive("Impromptu","")

If Not WinActive("Impromptu","") Then WinWaitActive("Impromptu","")

WinWaitActive("Impromptu","")

WinMenuSelectItem("Impromptu", "", "&Report", "&Prompt..." )

;check "Prompts" window

WinWait("Prompts","")

If Not WinActive("Prompts","") Then WinWaitActive("Prompts", "")

WinWaitActive("Prompts","")

;send params

Send(StringRight($file,4) & "{ENTER}")

Edited by 3telnick
Link to comment
Share on other sites

The problem is that next line just after highlited is never true.

The window is never active :(:D

Why, on earth, it differs when running during the day and early morning?

Shoud I force window to activate? Or mouse click on it? :)

Link to comment
Share on other sites

The window name, or process name, may not be what you think, depending on how the window is called.

To do a quick test, find the PID of the process.

$pid=Run(all_details_to_run)

You can then get the title of the process running that PID, and output it to see if it's a bit different than "Impromptu" (as you have put on the WinWaitActive).

Also, if you have been trying to hide this at any point, it seems that hidden windows cannot be "active" to autoit.

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Link to comment
Share on other sites

Thanks for help.

I guess I've just pin pointed real source of that strange (or maybe it is normal) window behaviour.

Console of the computer is automatically blocked after particular period of time.

If script runs whilest console is blocked it just hangs (because it cannot check wether window is active or not).

I'm 99,9% sure that it is the whole thing.

I switch off console blocking settings and tell you tomorrow if it'll work.

By the way, any ideas how to modify script to make it work properly with console blockage active?

Edited by 3telnick
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...