Jump to content



Photo

Pixelsearch


  • Please log in to reply
5 replies to this topic

#1 SlimShady

SlimShady

    AutoIt lover

  • Active Members
  • PipPipPipPipPipPip
  • 2,383 posts

Posted 09 October 2004 - 01:03 PM

While I was making a Tetris clone (currently I named it MyTetris), I stumbled on a problem with PixelSearch.
After some tests I know more of the return values of PixelSearch and ControlGetPos.
  • Test1:
    I made a test script that shows the position and the size of a control using ControlGetPos with a titlebar
  • I added a button
  • I put the info of the control ControlGetPos found, in a message box

    Test2: same as Test1, now without a titlebar.
    Results:
    The info the function returned, matches with the size and positions I gave to the control.

    Test3:
    I made a test script that shows where it matches a certain color using PixelSearch
  • I added an empty label
  • gave the label a white background color
  • I put the info PixelSearch returned in a message box
  • with a title bar

    Test4:
    Same as Test3, now without a titlebar
    Results:
    PixelSearch returned different positions of the label/white color
I don't know if something is not working properly or maybe this is just the way Windows works.
Before I started testing I was disappointed that in my original script, the PixelSearch function didn't work well.
Because it was the first time I started using the function.

For your information, here's the PixelSearch test script.

Plain Text         
#include <GUIConstants.au3> AutoItSetOption("TrayIconHide", 1) AutoItSetOption("PixelCoordMode", 0) AutoItSetOption("ExpandVarStrings", 1) AutoItSetOption("WinTitleMatchMode", 4) ;Initialize variables Global $style1 Global $IniFile Global $GUIWidth Global $GUIHeight $GUIWidth = 250 $GUIHeight = 250 $IniFile = @ScriptDir & "\" & StringTrimRight(@ScriptName, 3) & "ini" ;Only a close button: ;$style1 = BitOR($WS_POPUP, $WS_CAPTION, $WS_SYSMENU) ;GUICreate("New GUI", $GUIWidth, $GUIHeight, -1, -1, $style1) ;GUI with title bar $Window = GUICreate("New GUI", $GUIWidth, $GUIHeight) ;GUI without titlebar ;$Window = GUICreate("New GUI", $GUIWidth, $GUIHeight, -1, -1, $WS_POPUP) If @error Then    MsgBox(16, "AutoIt Error", "Window could not be created!")    ConsoleWrite("---------- AutoIt Error ----------" & @LF)    ConsoleWrite('"Window could not be created!"')    Exit 1 EndIf $Quit_btn = GUICtrlCreateButton("Test", 0, 0, 70, 20) $Test_label = GUICtrlCreateLabel("", 100, 100, 100, 10)    GUICtrlSetBKColor(-1, 0xffffff) GUISetState() Global $Pressed = 0 While 1    $Msg = GUIGetMsg()    Select        Case $msg = $GUI_EVENT_CLOSE       GUIDelete()       Exit    Case $msg = $Quit_btn       If $Pressed = 0 Then          $Pressed = 1          GUICtrlSetData($Quit_btn, "Quit")          TestThis()       ElseIf $Pressed = 1 Then          GUIDelete()          Exit       EndIf    EndSelect WEnd Func TestThis()    $Col = PixelSearch(25, 25, 250, 150, 0xffffff)    If IsArray($Col) Then       $x = $Col[0]       $y = $Col[1]       MsgBox(0, "Test", "Matched the white color at:@CRLF@x: $x$ y: $y$")    Else       MsgBox(0, "Test", "White color is not found!")    EndIf EndFunc






#2 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 09 October 2004 - 02:16 PM

PixelSearch() returns Window coordinates. These are relative to the upper left corner of the window, titlebar or not. ControlGetPos() returns client coordinates. These always start in the upper left corner of the clieant area. This area is the area just inside the border and below the titlebar (If present).

#3 SlimShady

SlimShady

    AutoIt lover

  • Active Members
  • PipPipPipPipPipPip
  • 2,383 posts

Posted 09 October 2004 - 04:00 PM

I came to that conclusion. I'm using in my script a combination of ControlGetPos and PixelSearch.
So I had to adjust my script a little.
The difference between the two are:
3 pixels from the left and 22 from the top.

#4 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 09 October 2004 - 06:03 PM

I came to that conclusion. I'm using in my script a combination of ControlGetPos and PixelSearch.
So I had to adjust my script a little.
The difference between the two are:
3 pixels from the left and 22 from the top.

<{POST_SNAPBACK}>

I would strongly discourage you from hard-coding those values. It is best to calculate those values at run-time because a different Windows theme may change those sizes. I believe Larry explained how to calculate those numbers in a thread not that long ago.

#5 Jon

Jon

    Up all night to get lucky

  • Administrators
  • 9,529 posts

Posted 10 October 2004 - 11:45 AM

I would strongly discourage you from hard-coding those values.  It is best to calculate those values at run-time because a different Windows theme may change those sizes.  I believe Larry explained how to calculate those numbers in a thread not that long ago.

<{POST_SNAPBACK}>

As I think I said somewhere else I think I'm going to go through all the functions that use/get window positions and add a new mode that returns client area coords.

#6 SlimShady

SlimShady

    AutoIt lover

  • Active Members
  • PipPipPipPipPipPip
  • 2,383 posts

Posted 10 October 2004 - 12:40 PM

Allright. That's great.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users