Newbie in WinBatch: Need guidance on script

Started by panky, October 01, 2013, 04:21:18 AM

Previous topic - Next topic

panky

Hi all,

This is my first post on this as I am newbie on WinBatch automation though with technical background.

I am trying to send keys (enter) to one of running applications after a "print complete dialog box" appears on screen. I am able to identify the parent/Child with following scripts but not able locate the print completion box as "enter" key only has to send as soon it  only appears on screen. I do not want to use time delay here since it interrupts my application to print, if printing/dialog box has not completed.

The title of "dialog box" is "Attended Print" though I am not able to catch that. Tried lot of options available in tutorials though finally gave up. Please help me to direct me on correct path. Below is what I have tried.

Apologies for including all my hit and trials:

state=WinState("~Arbortext")
;message("state is", %state%)
If WinState("~Arbortext") == @HIDDEN Then WinShow("~Arbortext")
If WinState("~Arbortext") == @ICON Then WinShow("~Arbortext")
If WinState("~Arbortext") == @FALSE Then WinShow("~Arbortext")
If WinState("~Arbortext") == @NORMAL Then WinShow("~Arbortext")

winActivate("~Arbortext")
;sendkeysto("~Arbortext", "^n")
timedelay(1)

;parents=WinItemize()
;children=WinItemChild("~Arbortext")
;ret = WinWaitChild("~Arbortext", children, -1)
;Message("child window",%ret%)

WinWaitExist("~Arbortext", -1)

;TimeDelay(1)
;IntControl (43, 1, 0, 0, 0)
SendKeysto("~Arbortext","~")
;Else
;  Message("Notice","Child window Not found")
;EndIf

Exit

Any help appreciated!

 


Deana


I have a few questions.

Is the title of the dialog that contains the Enter button: 'Attended Print'?

If so have you tried:
Code (winbatch) Select

title = '~Attended Print~' ; case sensitive window title
WinWaitExist( title )
SendKeysTo( title, '~')


Some application can be non responsive, so IntControl (43, p1, 0, 0, 0) can be used to tell the SendKey functions to just send the key even if the application doesn't respond that it is ready. That code would look like this:

Code (winbatch) Select

title = '~Attended Print~' ; case sensitive window title
WinWaitExist( title )
p1 = IntControl(43,0,0,0,0); This controls whether SendKey, SendKeysTo and SendKeysChild attempts to wait until the active application is ready to accept input before sending each keystroke. Do Not Wait.
SendKeysTo( title, '~')
IntControl(43,p1,0,0,0)



Deana F.
Technical Support
Wilson WindowWare Inc.

panky

Thanks Deana. Right the title of this dialog box is indeed "Attended Print"! I shall try your suggestion tomorrow once I get to the office. I was indeed earlier was trying to catch the title earlier (what I have posted is all changed now :-().

I shall try your code tomorrow at work and get back in case any doubts. Shall I also try " roboscripter" as suggested by koawmfot or that will work. Though roboscripter is again going to be a new for me but why not try for getting results?

Thanks anyway and much appreciated!

Deana

Quote from: panky on October 02, 2013, 05:04:25 AM
Thanks Deana. Right the title of this dialog box is indeed "Attended Print"! I shall try your suggestion tomorrow once I get to the office. I was indeed earlier was trying to catch the title earlier (what I have posted is all changed now :-().

I shall try your code tomorrow at work and get back in case any doubts. Shall I also try " roboscripter" as suggested by koawmfot or that will work. Though roboscripter is again going to be a new for me but why not try for getting results?

Thanks anyway and much appreciated!

Yes I do recommend familiarizing yourself with RoboScripter, it can help create these window automation scripts. RoboScripter is a little utility, sort of in the macro recorder genre, that was designed to make Control Manager scripts much easier to write. This article consists of a quick look at RoboScripter. http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+Tutorials+A~look~at~RoboScripter.txt
Deana F.
Technical Support
Wilson WindowWare Inc.

panky

Hello again Deana,

I tried using "RoboScripter" as suggested and can see that the title of dialog box is not being captured and not even ID. Below is what is I am getting with using WinWaitExist:


;RoboScripter
; Made with
;   RoboScripter ver: 45
;   CtlMgr ver: 44039
AddExtender("wwctl44i.dll")

;Title: <untitled>
;ID: 0
;Class: 3B2DialogBox
;Level: 1

; Default cWndByWndSpec seems OK here
ControlHandle=cWndByWndSpec("3B2DialogBox","APP",0)
; ControlHandle=cWndByWndSpecName(Error: No Window Title Available)
; ControlHandle=DllHwnd('Error: No Window Title Available')
WinWaitExist("", -1 )  ;Wait for window to exist ;TODO Check title and timeout value



I am not sure whether ControlImageCRC will work for me, which is actually getting the below from RoboScripter


;Title: Attended Print
;ID: 3244
;Class: MDIClient
;Level: 2

; Default cWndByWndSpec seems OK here
window1=cWndByWndSpec("3B2Frame10.0.1062U","APP",1,3244)
; window1=cWndByWndSpecName("Arbortext Advanced Print Publisher Unicode - [C:/Users/Pankaj.Chaturvedi/Desktop/temp/TJFE_A_844206.3d - changed]","APP",1,3244)
; window1=DllHwnd('Arbortext Advanced Print Publisher Unicode - [C:/Users/Pankaj.Chaturvedi/Desktop/temp/TJFE_A_844206.3d - changed]')
ControlHandle=cWndByID(window1,3244)
; or ControlHandle=cWndByName(window1,`Attended Print~`)
; or ControlHandle=cWndByClass(window1,`MDIClient`)
; or ControlHandle=cWndBySeq(window1,1)
CRCResult=cGetControlImageCRC(ControlHandle)        ; Get CRC of the selected control's image

; Sample code for auto-learn mode for cGetControlImageCRC       TODO  FIX SAMPLE CODE !!

        ; Auto-learn code for cGetControlImageCRC
        ; Decide on an ini file name.
        ; Consider using full path to ini file
CRCinifile="ZZZControlCRC.ini"                                ; TODO - decide on ini file name
        ; Select a unique name for the ini section
        ; for this control
CRCiniSect="UniqueName"                                       ; TODO - select unique section name for this control
        ; See if CRC has already been defined in the ini file
CRCstate=IniReadPvt(CRCiniSect,CRCresult,"unknown",CRCinifile)
        ;If defined, use it, otherwise prompt user
if CRCstate=="unknown"
    CRClist="normal disabled green check unchecked whatever"  ; TODO - name the various control states to be detected
    CRCstate=AskItemList("What state is the control? ",CRClist," ",@sorted,@single)
    IniWritePvt(CRCiniSect,CRCresult,CRCstate,CRCinifile)
Endif

Message("Control Image  State",CRCstate)           ; TODO - Remove Message Stmt



I even trying to use other available macros but I am very sad that I am not able to get the title name. Will try again and report back tomorrow. Thanks for looking.

Deana

Based on the RoboScripter output it looks as thought the Attended Print control is a MDIClient window. Unfortunately, the Control manager Extender doesn't contain any specific functions for that control type. However you can list the child windows using code like this:

Code (winbatch) Select
AddExtender("wwctl44i.dll")

partialwinname  = 'Arbortext Advanced Print Publisher Unicode -'

ret = WinWaitExist(partialwinname, 10)
if ret == 0
  Pause( 'Notice', 'Unable to locate parent window: ': partialwinname )
  exit
endif

window1=DllHwnd( partialwinname )
;ControlHandle=cWndByName(window1,`Attended Print~`); MDIClient window
ControlHandle=cWndByClass(window1,`MDIClient`); MDIClient window

id = cWinIdConvert(ControlHandle)
childwindows = WinItemChild( id )
AskItemList('Child windows of the MDIClient' , childwindows, @tab, @unsorted, @single )
exit


Does your 'print complete' box show up as a child window? You could  use WinWaitChild to wait for that specific child window to appear. The above code should help. What is the exact window title of the print complete box?
Deana F.
Technical Support
Wilson WindowWare Inc.

panky

The complete title of print window is "Attended Print" (case sensitive). I shall try to use your suggestion and let's see. Unfortunately it is my first WinBatch script though I guess with little more effort and guidance I shall reach somewhere. RoboScripter looks interesting and I can the possible use it in my other applications.

Thanks for help!

Panky

panky

Please don't get confused with
Code (WinBatch) Select

;Title: Attended Print
;ID: 3244
;Class: MDIClient
;Level: 2


Its (Attended Print) just the name I have given for testing and in actual the application is "Arbortext Advanced Print Publisher Unicode" (case sensitive) with 
Code (WinBatch) Select

;C:/Users/Pankaj.Chaturvedi/Desktop/temp/TJFE_A_844206.3d - changed is file open on window (which I am printing). Hence we get

window1=cWndByWndSpecName("Arbortext Advanced Print Publisher Unicode - [C:/Users/Pankaj.Chaturvedi/Desktop/temp/TJFE_A_844206.3d - changed]","APP",1,3244)

;"Attented Print" is the title of the dialog box, which is anticipated and requires enter keystroke (which I need to automate) once printing of file is done.
;I have indeed attempted getting child windows, even before posting on forum but simple was unable to get the dialog box title from that.
;[C:/Users/Pankaj.Chaturvedi/Desktop/temp/TJFE_A_844206.3d - changed] appears in list as a child window of "~Arbortext" with no further information.

; I thought of may trying to child of the child may worth and dialog box may be treated as grand child of "~Arbortext" but that was too failed.

;Only after using RoboScriter I can find that "~Arboetext" is a dubious applications and hides the dialog box information to WinBatch (tried other dialog box too)
;And got same result
;Class: 3B2Diaogbox with no mention of unique title
; The only thing at this point I guess to use the Id of Dialog box, which is appearing as '0' (infact for dialog box) but taht would be bad programming.



Throw some directives to me! :-(

Best,
Panky

Deana

This code is based off the RoboScripter code you posted. It will wait up to 20 seconds for the attended print window to appear.

Code (winbatch) Select
AddExtender("wwctl44i.dll")

partialwinname  = 'Arbortext Advanced Print Publisher Unicode -'

ret = WinWaitExist(partialwinname, 10)
if ret == 0
  Pause( 'Notice', 'Unable to locate parent window: ': partialwinname )
  exit
endif

;Title: Attended Print
;ID: 3244
;Class: MDIClient
;Level: 2
attempts = 1
While attempts <= 20
   window1=cWndByWndSpec("3B2Frame10.0.1062U","APP",1,3244)
   If window1 != 0 then break
   attempts = attempts+1
   If attempts == 10
      Pause('Notice','Unable to locate Attended Print Window')
      Exit
   Endif
   Timedelay(1)
EndWhile


; window1=cWndByWndSpecName("Arbortext Advanced Print Publisher Unicode - [C:/Users/Pankaj.Chaturvedi/Desktop/temp/TJFE_A_844206.3d - changed]","APP",1,3244)
; window1=DllHwnd('Arbortext Advanced Print Publisher Unicode - [C:/Users/Pankaj.Chaturvedi/Desktop/temp/TJFE_A_844206.3d - changed]')
; ControlHandle=cWndByID(window1,3244)
ControlHandle=cWndByName(window1,'Attended Print~')

;Add code here to deal with 'Attended Print~' control.

exit
Deana F.
Technical Support
Wilson WindowWare Inc.

panky

Thanks Deane for continuous help. TimeDelay is not going to help me here! I have did the time delay in my earlier script for 15 seconds but since I am not certain bout the time which "APP" will take to print a document and varies the only think I thought of capturing the dialog box with title "Attended Print" and send key strokes to it. Just for tough testing I am printing a large document with 312 pages and which takes about 150 seconds to print. Code which you have and I tested earlier interrupts   the printing. Time delay is success for documents which takes less than mentioned delay time.

Just for the more brevity I am attaching the screen shot of the dialog box in from and parent window (Arbortext Advanced Print Publisher) window on back. As I said earlier that Roboscripter shows the window as "<Untitled>" with an id of "0" so I am assuming there is no way latching on it! Code what get for the "Attended Print" dialog box with Roboscripter as as follows:

Code (winbatch) Select

;RoboScripter
; Made with
;   RoboScripter ver: 45
;   CtlMgr ver: 44039
AddExtender("wwctl44i.dll")

;Title: <untitled>
;ID: 0
;Class: 3B2DialogBox
;Level: 1

; Default cWndByWndSpec seems OK here
ControlHandle=cWndByWndSpec("3B2DialogBox","APP",0)
; ControlHandle=cWndByWndSpecName(Error: No Window Title Available)
; ControlHandle=DllHwnd('Error: No Window Title Available')
WinWaitExist("", -1 )  ;Wait for window to exist ;TODO Check title and timeout value
SendKeys("~")




Thanks!

Pankaj

Deana

A while loop can be used to wait an unspecified amount of time.  There is more than one way to identify a window. A window can be identified by its title, window id or window handle.  The RoboScripter code that you posted uses cWndByWndSpec to return the window handle.  I recommend creating a while loop that loops every second until that function returns a non zero value.
Code (winbatch) Select

Handle = 0
While Handle==0
    Handle=cWndByWndSpec("3B2DialogBox","APP",0)
    TimeDelay(1)
EndWhile
Pause('Notice','Window is now active')
Deana F.
Technical Support
Wilson WindowWare Inc.

panky

That does the trick. Though it cannot latch on the precise dialog box title, but nevertheless it makes things happening for me with few tweaking in script.

Thanks for help Deana, you have been great support in making my kick start on WinBatch.

Have a nice day ahead

Pankaj