Jump to content

[Solved]Close Multiple GUI


Recommended Posts

Hi All,

I'm using pixel search to get specific color from screen, and i'm using (GUICreate) to genrate Rectangle shape that recover founded pixel so it can find another one.

The issue that when using :

GUIDelete($GUI)

It doesn't close all created Gui.

Here is my full script:

inActivate('ArcMap')
Sleep(1000)
Global  $S_Coords = [359, 105, 1434,703]
Global $FoundPixs[0]
While 1
    If CheckArea($S_Coords[0], $S_Coords[1], $S_Coords[2],$S_Coords[3], 'ARCMAP Window') Then 
        _ArrayAdd($FoundPixs, $Pix[0] & ',' & $Pix[1])
        DrawRect()
        Sleep(200)
    Else 
        For $i = 0 to UBound($FoundPixs) -1;Clean Detected Gui 
          ;   WinClose("Dummy_Color")
            GUIDelete($GUI)
        Next    
            _ArrayDisplay( $FoundPixs, '$FoundPixs')
        ExitLoop 
    
        
    EndIf
WEnd 
While 1
    Sleep(4000)
Wend
Func DrawRect()

 Local $startX = $Pix[0] - 20;
    Local $startY = $Pix[1] - 20;
    Local $endX = $startX + 40;
    Local $endY = $startY+ 40;
Global $GUI = GUICreate("Dummy_Color",40,40,$startX, $startY,$WS_POPUP,-1)
GUISetBkColor(0x008000,$GUI)        
   ;GUISetBkColor(0x008000) 
        GUISetState(@SW_SHOW)   
EndFunc
 ;0x0000FF
                    ;Sleep(2000)

Func CheckArea($X1, $y1, $x2, $y2, $Direction)
Local  $Coords = [$X1, $y1, $x2, $y2]
Global  $Pix=PixelSearch( $Coords[0],$Coords[1],$Coords[2],$Coords[03],0xFF00C5,0)
If IsArray($Pix) Then
ToolTip("Found Pix 1 At:" & $Direction ,0, 0)
MouseMove($Pix[0], $Pix[1], 1)
;STP()
;print('Found Pix 1 At', $Direction)
Return True 
EndIf

 

Edited by abdulrahmanok
Link to comment
Share on other sites

  • Developers
6 minutes ago, abdulrahmanok said:

Here is my full script:

Don't think so....  it for sure won't run!

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Jos was pointing out that your example doesn't run on its own.  This is contrary to your statement, "Here is my full script:"

GUIDelete() must be used for each GUI handle created by GUICreate(), so if you have multiple GUIs, it makes sense that a single GUIDelete function only deletes the one whose handle you provide to the script.

If you can provide a working script--because what you posted doesn't execute / it is incomplete--or a script the reproduces the problem, we can better assist.

 

edit: from what I gather from the portion of code you posted, you are creating multiple guis and assigning the GUICreate() result (handle) to the global variable $GUI.  $GUI can only hold one "thing" (handle) at a time.  If you need to track multiple handles, you might be better suited using an array.

 

Edited by spudw2k
Link to comment
Share on other sites

@spudw2k Thanks for explaining 

Here is my Updated Ex:

#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <array.au3>
#include <WindowsConstants.au3>

Sleep(2000)
Global  $S_Coords = [0, 0, @DesktopWidth,@DesktopHeight]
Global $FoundPixs[0]
While 1
    If CheckArea($S_Coords[0], $S_Coords[1], $S_Coords[2],$S_Coords[3], 'ARCMAP Window') Then 
        _ArrayAdd($FoundPixs, $Pix[0] & ',' & $Pix[1])
        DrawRect()
        Sleep(200)
    Else 
        For $i = 0 to UBound($FoundPixs) -1;Clean Gui Detected
          ;   WinClose("Dummy_Color")
            GUIDelete($GUI)
        Next    
            _ArrayDisplay( $FoundPixs, '$FoundPixs')
        ExitLoop 
    
        
    EndIf
WEnd 
While 1
    Sleep(4000)
Wend
Func DrawRect()

 Local $startX = $Pix[0] - 20;
    Local $startY = $Pix[1] - 20;
    Local $endX = $startX + 40;
    Local $endY = $startY+ 40;
Global $GUI = GUICreate("Dummy_Color",40,40,$startX, $startY,$WS_POPUP,-1)
GUISetBkColor(0x008000,$GUI)        
   ;GUISetBkColor(0x008000) 
        GUISetState(@SW_SHOW)   
EndFunc
 ;0x0000FF
                    ;Sleep(2000)

Func CheckArea($X1, $y1, $x2, $y2, $Direction)
Local  $Coords = [$X1, $y1, $x2, $y2]
Global  $Pix=PixelSearch( $Coords[0],$Coords[1],$Coords[2],$Coords[03],0xED1C24,0)
If IsArray($Pix) Then
ToolTip("Found Pix 1 At:" & $Direction ,0, 0)
MouseMove($Pix[0], $Pix[1], 1)
;STP()
;print('Found Pix 1 At', $Direction)
Return True 
EndIf

EndFunc


Func STP()
MsgBox(0, 0, 0, 1)
EndFunc 


























;~ Raw(-165,0 );Raw 1
;~ Func Raw($X_Change,$Y_Change )
;~ $MainChangeX = $X_Change
;~ $MainChangeY = $Y_Change
;~ For $i = 1 To 3
;~ _WinAPI_DrawRect($StartCoords[0] + $X_Change, $StartCoords[1]+$Y_Change, _
;~ $StartCoords[2]+$X_Change, $StartCoords[3] +$Y_Change ,0xFC5A43 )
;~ Sleep(500)
;~ $X_Change = $X_Change + $X_Change
;~ $Y_Change = $Y_Change + $Y_Change
;~ print('$X_Change', $MainChangeX)
;~ print('$Y_Change', $MainChangeY)
;~ Next
;~ EndFunc 

Func Calc_Distance($x1, $y1, $x2, $y2) ;Pythagoras theorem for 2D
    Local $a, $b, $c
    If $x2 = $x1 And $y2 = $y1 Then
        Return 0
    Else
        $a = $y2 - $y1
        $b = $x2 - $x1
        Global $P_Found = Sqrt($a * $a + $b * $b)
        ;print($P_Found)

        Return $P_Found
    EndIf
EndFunc   ;==>Calc_Distance





Func _WinAPI_DrawRect($start_x, $start_y, $iWidth, $iHeight, $iColor)
    Global $hDC = _WinAPI_GetWindowDC(0)      ; DC of entire screen (desktop)
    Local $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, 1, $start_x)
    DllStructSetData($tRect, 2, $start_y)
    DllStructSetData($tRect, 3, $iWidth)
    DllStructSetData($tRect, 4, $iHeight)
    Global $hBrush = _WinAPI_CreateSolidBrush($iColor)

    _WinAPI_FrameRect($hDC, DllStructGetPtr($tRect), $hBrush)
    ; clear resources
    Sleep(500)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC(0, $hDC)
EndFunc   ;==>_WinAPI_DrawRect

After start script while below image shown it must work.

test.png

Edited by abdulrahmanok
some includes Added
Link to comment
Share on other sites

Better, but its still not something we can run as-is.

We don't have your <myfuncs.au3> include.  I assume all that is needed in it for this example if the print() function?

Also, it fails to run because <Array.au3> and <WindowsConstants.au3> are missing.  Perhaps they are inside <myfuncs> too?

 

Anyways, like I mentioned.  GUIDelete($GUI) is only deleting the most recently created GUI.  Perhaps you can do something like this?
1) Add an extra dimension to your FoundPixs array to hold the GUI Handles returned by GUICreate()
2) Reference the array (dimension) when calling GUIDelete()

Spoiler
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Sleep(4000)
Global $S_Coords = [0, 0, @DesktopWidth, @DesktopHeight]
Global $FoundPixs[0][2]
Const Enum $ePIXELLOCATION, $eGUIHANDLE
Global $Pix
Global $GUI
While 1
    If CheckArea($S_Coords[0], $S_Coords[1], $S_Coords[2], $S_Coords[3], 'ARCMAP Window') Then
        $sPixelLocation = $Pix[0] & ',' & $Pix[1]
        $hGUIHandle = DrawRect()
        _ArrayAdd($FoundPixs, $sPixelLocation & "|" & $hGUIHandle)
        Sleep(200)
    Else
        For $i = 0 To UBound($FoundPixs) - 1;Clean Gui Detected
            GUIDelete($FoundPixs[$i][$eGUIHANDLE])
        Next
        _ArrayDisplay($FoundPixs, '$FoundPixs')
        ExitLoop
    EndIf
WEnd

While 1
    Sleep(4000)
WEnd

Func DrawRect()

    Local $startX = $Pix[0] - 20;
    Local $startY = $Pix[1] - 20;
    Local $endX = $startX + 40;
    Local $endY = $startY + 40;
    $GUI = GUICreate("Dummy_Color", 40, 40, $startX, $startY, $WS_POPUP, -1)
    GUISetBkColor(0x008000, $GUI)
    GUISetState(@SW_SHOW)
    Return $GUI
EndFunc   ;==>DrawRect

Func CheckArea($X1, $y1, $x2, $y2, $Direction)
    Local $Coords = [$X1, $y1, $x2, $y2]
    $Pix = PixelSearch($Coords[0], $Coords[1], $Coords[2], $Coords[03], 0xED1C24, 0)
    If IsArray($Pix) Then
        ToolTip("Found Pix 1 At:" & $Direction, 0, 0)
        MouseMove($Pix[0], $Pix[1], 1)
        Return True
    EndIf
EndFunc   ;==>CheckArea

 

 

Edited by spudw2k
Link to comment
Share on other sites

  

25 minutes ago, spudw2k said:

Better, but its still not something we can run as-is.

  Reveal hidden contents
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Sleep(4000)
Global $S_Coords = [0, 0, @DesktopWidth, @DesktopHeight]
Global $FoundPixs[0][2]
Const Enum $ePIXELLOCATION, $eGUIHANDLE
Global $Pix
Global $GUI
While 1
    If CheckArea($S_Coords[0], $S_Coords[1], $S_Coords[2], $S_Coords[3], 'ARCMAP Window') Then
        $sPixelLocation = $Pix[0] & ',' & $Pix[1]
        $hGUIHandle = DrawRect()
        _ArrayAdd($FoundPixs, $sPixelLocation & "|" & $hGUIHandle)
        Sleep(200)
    Else
        For $i = 0 To UBound($FoundPixs) - 1;Clean Gui Detected
            GUIDelete($FoundPixs[$i][$eGUIHANDLE])
        Next
        _ArrayDisplay($FoundPixs, '$FoundPixs')
        ExitLoop
    EndIf
WEnd

While 1
    Sleep(4000)
WEnd

Func DrawRect()

    Local $startX = $Pix[0] - 20;
    Local $startY = $Pix[1] - 20;
    Local $endX = $startX + 40;
    Local $endY = $startY + 40;
    $GUI = GUICreate("Dummy_Color", 40, 40, $startX, $startY, $WS_POPUP, -1)
    GUISetBkColor(0x008000, $GUI)
    GUISetState(@SW_SHOW)
    Return $GUI
EndFunc   ;==>DrawRect

Func CheckArea($X1, $y1, $x2, $y2, $Direction)
    Local $Coords = [$X1, $y1, $x2, $y2]
    $Pix = PixelSearch($Coords[0], $Coords[1], $Coords[2], $Coords[03], 0xED1C24, 0)
    If IsArray($Pix) Then
        ToolTip("Found Pix 1 At:" & $Direction, 0, 0)
        MouseMove($Pix[0], $Pix[1], 1)
        Return True
    EndIf
EndFunc   ;==>CheckArea

 

 

I reliszed that later and edited it later :

some includes Added
 
And about your suggestions sorry but i dont know how to do that is there is any reference or guides for this? 
Edited by abdulrahmanok
Link to comment
Share on other sites

  • abdulrahmanok changed the title to [Solved]Close Multiple GUI

I used those just to make it more human readable friendly when accessing the sub-indexes of the $FoundPixs array.

$FoundPixs[index#][$ePIXELLOCATION] = the pixel coordinates
$FoundPixs[index#][$eGUIHANDLE] = the handle returned by the GUICreate() function

I never used the $ePIXELLOCATION constant later in the script, but I did use the $eGUIHANDLE constant in the GUIDelete() function.

Link to comment
Share on other sites

3 minutes ago, spudw2k said:

I used those just to make it more human readable friendly when accessing the sub-indexes of the $FoundPixs array.

$FoundPixs[index#][$ePIXELLOCATION] = the pixel coordinates
$FoundPixs[index#][$eGUIHANDLE] = the handle returned by the GUICreate() function

I never used the $ePIXELLOCATION constant later in the script, but I did use the $eGUIHANDLE constant in the GUIDelete() function.

Everything is clear now, I appreciate your help❤️

I'm Googling now for Enum and how it works because I think I  will use it too much in future 

Edited by abdulrahmanok
Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...