Jump to content

how to draw rectangle round PixelSearch area


Recommended Posts

I am having to manually adjust the coordinates used for a PixelSearch by experimentation and have been wondering if there is some way I can display a rectangle round the area I am searching so I can speed up my manual process which I have to do if the app window is moved for any reason.

My most recent reason for the move was getting a new bigger screen. :)

I have done some searching but not found anything suitable that would only be active when I have set the TestCmd variable to 1 to indicate I am testing the Cmd segment of my script which is an automation of a game to do some resource farming.

Hope someone can help me.

Link to comment
Share on other sites

I setup a function to do the screen capture and the control overlay passing the same coordinates as are being used for the pixel search.

The control overlay is showing on the window where I want it in that I can see the title text but there is nothing in the part of the control where I expected the bitmap to appear.

Is it possible to set the background of the rectangle that would contain the bitmap to transparent so the actual window would show through?

I would not need a bitmap then.

 

The bitmap captured did not contain the area of the window I expected by that I mean not the same as where the control is seen. 

I have managed to manually find the correct offset from the parameter values past to the function and can see in the captured bitmap the part of the window I want to search and see in the control.

It appears to me that the screen capture is using different coordinates (screen?) to the control coordinates (window?) but I am not sure about that and what coordinates the pixel search function is using.

Can you help me with that? 

Link to comment
Share on other sites

Ok, changed the script but still a problem with correlation between coordinates of search, capture and control.

The function I am using is coded like this:

Func MarkSearchArea($X1,$Y1,$X2,$Y2)
      $sBMP_Path = @ScriptDir & "\Rect.bmp"
      _DebugOut($sBMP_Path & " " & $X1 & " " & $Y1 & " " & $X2 & " " & $Y2)
      _ScreenCapture_CaptureWnd($sBMP_Path,$WinHandle, $X1-200, $Y1-100, $X2+200, $Y2+100, False)
      $hBitmap_GUI = GUICreate("Search Area", $X2-$X1+1,$Y2-$Y1+10,$X1,$Y1-11,$SS_SIMPLE)
      GUISetState(@SW_SHOW,$hBitmap_GUI)
      $hPic = GUICtrlCreatePic($sBMP_Path,0,0,$X2-$X1+1,$Y2-$Y1+1,$SS_WHITEFRAME)
      GUISetState()
EndFunc

I am passing the same coordinate values to this function as those being used for the PixelSearch

The bitmap shows the area I want is towards the right of the area and below it.

How do I line these things up?

Link to comment
Share on other sites

Well, some progress at least. I can now see the saved screen capture in the control client area. I added GUISetBkColor(0xE0FFFF) before the createpic.

I am still playing with the difference between GUI, Capture and Search coordinates but at least I can see what is being captured whilst inside the running script..

Link to comment
Share on other sites

Maybe in this example some thoughts to consider

and this is what i use in uiawrappers (see examples section)

; Draw rectangle on screen.
Func _UIA_DrawRect($tLeft, $tRight, $tTop, $tBottom, $color = 0xFF, $PenWidth = 4)
    Local $hDC, $hPen, $obj_orig, $x1, $x2, $y1, $y2
    $x1 = $tLeft
    $x2 = $tRight
    $y1 = $tTop
    $y2 = $tBottom
    $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
    $hPen = _WinAPI_CreatePen($PS_SOLID, $PenWidth, $color)
    $obj_orig = _WinAPI_SelectObject($hDC, $hPen)

    _WinAPI_DrawLine($hDC, $x1, $y1, $x2, $y1) ; horizontal to right
    _WinAPI_DrawLine($hDC, $x2, $y1, $x2, $y2) ; vertical down on right
    _WinAPI_DrawLine($hDC, $x2, $y2, $x1, $y2) ; horizontal to left right
    _WinAPI_DrawLine($hDC, $x1, $y2, $x1, $y1) ; vertical up on left

    ; clear resources
    _WinAPI_SelectObject($hDC, $obj_orig)
    _WinAPI_DeleteObject($hPen)
    _WinAPI_ReleaseDC(0, $hDC)
EndFunc   ;==>_UIA_DrawRect

 

Link to comment
Share on other sites

I have resolved one issue which was to do with my understanding of which coordinate system a function was using.

Simply that I needed to read the documentation fully.

Now I have done that and as a side effect of my investigation I now have a mouse locator that I can call and it shows me the mouse location wher I want to see it. Now I can adjust the locations I want things to be clicked and the work on that part is ongoing with no further need for responses to this chat line.

I will mention before closing that I did find an anomaly which is a surprise.

My debug log showed my window being 1536 by 949 but when I took a screenshot via Alt Printscreen the BMP it produced was, according to  my paint.net, 2284 by 1414. 

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

×
×
  • Create New...