Find Location of recorded Screenshot & Draw a Flashing Rectangle around it

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
ocnuybear
Pro Scripter
Posts: 100
Joined: Sun Jul 15, 2018 5:14 pm

Find Location of recorded Screenshot & Draw a Flashing Rectangle around it

Post by ocnuybear » Sat Jul 28, 2018 11:41 am

I hope this script will be useful to someone that needs to identify an area that was found and will highlight it with a flashing rectangle.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  BorderStyle = bsNone
  DefaultMonitor = dmDesktop
end
EndDialog>Dialog1
Dialog>Dialog2
object Dialog2: TForm
  BorderStyle = bsNone
  DefaultMonitor = dmDesktop
end
EndDialog>Dialog2
Dialog>Dialog3
object Dialog3: TForm
  BorderStyle = bsNone
  DefaultMonitor = dmDesktop
end
EndDialog>Dialog3
Dialog>Dialog4
object Dialog4: TForm
  BorderStyle = bsNone
  DefaultMonitor = dmDesktop
end
EndDialog>Dialog4
//Code to retrieve size of Bitmap
Let>ImageFile=C:\Users\John\Documents\Macro Scheduler 14\capture2.bmp
Dialog>ImageSizeDialog
object ImageSizeDialog: TForm
  object MSImage1: tMSImage
    AutoSize = True
  end
end
EndDialog>ImageSizeDialog
SetDialogProperty>ImageSizeDialog,MSImage1,LoadImage,Imagefile
GetDialogProperty>ImageSizeDialog,MSImage1,Width,Xpixels
GetDialogProperty>ImageSizeDialog,MSImage1,Height,Ypixels
FindImagePos>%ImageFile%,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
IF>NumFound=0
  Input>Image was not found
  Exit>0
ENDIF
SetRoundMode>0
Let>Thickness=20
Let>X1=%xpixels%/2
Let>X1={%XArr_0%-Round(%X1%)}
Let>Y1=%ypixels%/2
Let>Y1={%YArr_0%-Round(%Y1%)}
Let>X2=X1+xpixels
Let>Y2=y1+ypixels
//Code to draw Rectangles
IF>{(%X1%>%X2%)OR(%Y1%>%Y2%)}
  Input>Impossible Dimension
  Exit>0
ENDIF
Let>Dialog1_wt={%X2%-%X1%+%Thickness%}
Let>Dialog1_wt={Abs(%Dialog1_wt%)}
Let>Dialog2_ht={%Y2%-%Y1%+%Thickness%}
Let>Y1Offset=Y1-Thickness
Let>X1Offset=X1-Thickness
//Draw four compressed dialogs, one for each side of the rectangle
GoSub>DialogProperty,Dialog1,X1Offset,Y1Offset,%Thickness%,Dialog1_wt
GoSub>DialogProperty,Dialog2,X2,Y1Offset,Dialog2_ht,%Thickness%
GoSub>DialogProperty,Dialog3,X1,Y2,%Thickness%,Dialog1_wt
GoSub>DialogProperty,Dialog4,X1Offset,Y1,Dialog2_ht,%Thickness%
Let>x=0
//Make Rectangle flash red & blue
While>x<10
  Let>x=x+1
  Show>Dialog1
  Show>Dialog2
  Show>Dialog3
  Show>Dialog4
  Wait>0.1
  SetDialogProperty>Dialog1,,Color,255
  SetDialogProperty>Dialog2,,Color,255
  SetDialogProperty>Dialog3,,Color,255
  SetDialogProperty>Dialog4,,Color,255
  Wait>0.1
  SetDialogProperty>Dialog1,,Color,16711680
  SetDialogProperty>Dialog2,,Color,16711680
  SetDialogProperty>Dialog3,,Color,16711680
  SetDialogProperty>Dialog4,,Color,16711680
EndWhile
SRT>DialogProperty
  AddDialogHandler>%DialogProperty_var_1%,,OnClose,Exit
  SetDialogProperty>%DialogProperty_var_1%,,Position,poDesigned
  SetDialogProperty>%DialogProperty_var_1%,,Left,%DialogProperty_var_2%
  SetDialogProperty>%DialogProperty_var_1%,,Top,%DialogProperty_var_3%
  SetDialogProperty>%DialogProperty_var_1%,,clientheight,%DialogProperty_var_4%
  SetDialogProperty>%DialogProperty_var_1%,,clientwidth,%DialogProperty_var_5%
END>DialogProperty

Last edited by ocnuybear on Wed Sep 05, 2018 6:20 pm, edited 3 times in total.

ocnuybear
Pro Scripter
Posts: 100
Joined: Sun Jul 15, 2018 5:14 pm

Re: Find Location of recorded Screenshot & Draw a Flashing Rectangle around it

Post by ocnuybear » Wed Sep 05, 2018 6:06 pm

I have updated the original code with a new & much better script, the old script used VBscript to calculate the image size, but now i'm using MS directly with less code. The image found will now be surrounded by a flashing rectangle.

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