Capturing only an active window

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Capturing only an active window

Post by Phil Pendlebury » Sun Jan 21, 2007 11:48 am

I read in another thread that you said it is sometimes useful not to capture the whole screen.
Sometimes it is useful to have the ScreenCapture only capture a portion of the screen - like a specific window. This is good when we know the image will only appear within those bounds.
I can't find any way to do this (this is test code btw, it's not part of the finished script, it's just to let me see if and how it works):

Code: Select all

WaitWindowOpen>Export Audio Mixdown
SetFocus>Export Audio Mixdown
GetScreenRes>srx,sry
ScreenCapture>0,0,srx,sry,C:\Documents and Settings\Phil\My Documents\Download\export.bmp
SetFocus>Export Audio Mixdown
let>monoclear=0
let>monoticked=0
FindImagePos>C:\Documents and Settings\Phil\My Documents\Download\monoempty.bmp,C:\Documents and Settings\Phil\My Documents\Download\export.bmp,20,1,monx,mony,monoclear
FindImagePos>C:\Documents and Settings\Phil\My Documents\Download\monoticked.bmp,C:\Documents and Settings\Phil\My Documents\Download\export.bmp,20,1,monx,mony,monoticked

IF>monoclear>0
  msg>Mono Box is cleared%CRLF%Clear %monoclear% Ticked %monoticked%
ENDIF

IF>monoticked>0
  msg>Mono Box is ticked%CRLF%Clear %monoclear% Ticked %monoticked%
ENDIF
Obviously captures the whole screen and then does the checks. It works fine and seems accurate but it takes quite a long time.

I know I could speed it up with some IFs and ELSEs to avoid having to do both "needle" checks but ideally I would only capture the window "Export Audio Mixdown" and use that as the haystack image. It is quite a small window and so this would save a lot of time I am sure.

I can't use a screen area as the window can be moved and so on.

Have I misunderstood your quote? I have searched the documentation but it basically just asks for coordinates.
Phil Pendlebury - Linktree

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sun Jan 21, 2007 5:51 pm

The trick is to use GetActiveWindow to get the coordinates of the window and then pass them to ScreenCapture to just capture that area. Note that GetActiveWindow returns width and height, but ScreenCapture works with coordinates so you have to calculate the x,y of the lower right corner.

SetFocus>mywindow
GetActiveWindow>mywindow,x,y,w,h
Let>x2=x+w
Let>y2=y+h
ScreenCapture>x,y,x2,y2,c:\mypic.bmp

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Mon Jan 22, 2007 9:33 am

Me_again wrote:The trick is to use GetActiveWindow to get the coordinates of the window and then pass them to ScreenCapture to just capture that area. Note that GetActiveWindow returns width and height, but ScreenCapture works with coordinates so you have to calculate the x,y of the lower right corner.

SetFocus>mywindow
GetActiveWindow>mywindow,x,y,w,h
Let>x2=x+w
Let>y2=y+h
ScreenCapture>x,y,x2,y2,c:\mypic.bmp
Thank you very much for your response. very helpful indeed. :-)
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Mon Jan 22, 2007 2:19 pm

May also be worth pointing out that in order to get the mouse position using this method one has to do (example - note the line I have commented):

Code: Select all

WaitWindowOpen>Cubase 4
SetFocus>Export Audio Mixdown
Wait>0.5
GetActiveWindow>Export Audio Mixdown,mx,my,mw,mh
Let>mx2=mx+mw
Let>my2=my+mh
ScreenCapture>mx,my,mx2,my2,C:\Documents and Settings\Phil\My Documents\Download\export.bmp

FindImagePos>C:\Documents and Settings\Phil\My Documents\Download\monoticked.bmp,C:\Documents and Settings\Phil\My Documents\Download\export.bmp,50,1,monx,mony,monoticked
FindImagePos>C:\Documents and Settings\Phil\My Documents\Download\monoempty.bmp,C:\Documents and Settings\Phil\My Documents\Download\export.bmp,50,1,monx,mony,monoempty

// Set mouse coordintaes correctly as we are not using full screen 
let>monx2=monx_0+mx
let>mony2=mony_0+my

Wait>1

IF>monoempty>0
  //msg>Mono Box appears to be empty
  Wait>1
  Let>status=Cleared
  MouseMove>monx2,mony2
  Wait>0.2
  Lclick
  Let>newstatus=Ticked
  Wait>1
  GOTO>End
ENDIF

IF>monoticked>0
  //msg>Mono Box appears to be ticked
  Wait>1
  Let>status=Ticked
  MouseMove>monx2,mony2
  Wait>0.2
  Lclick
  Let>newstatus=Cleared
  Wait>1
  GOTO>End
ENDIF

Label>End
msg>Mono Box was %status% and has been %newstatus%


Phil Pendlebury - Linktree

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts