Jump to content

If Then Else GUI Delete Problem


Ilounah
 Share

Go to solution Solved by mistersquirrle,

Recommended Posts

Good Day, I'm trying to Cover button 0 and X with a GUI if items are already sent (Black fonts gray background) to the counter so no one can void there product, and unlock (Gui Delete) if the item was not yet sent (Green font items) unsent orders can be deleted.

The problem is why my code is deleting Gui Delete even the condition is exist.

Sorry for my Bad english, I attached video how it works.

 

#include <MsgBoxConstants.au3>
#include <GuiConstants.au3>

Opt("PixelCoordMode", 2)

While 1
Local $color = "0x6EC89B" ; the color you are looking for (green)
Local $result = PixelSearch(0, 137, 1, 465, 0xE8E9F1, 0)
If Not @error And IsArray($result) Then
$hGui = GUICreate("Disabled", 180, 60, 350, 907, $DS_MODALFRAME)
GUISetState()
WinSetOnTop($hGui, "", 1)
WinActivate($hGui)
Do
    Sleep(1000) ; wait 1 second before checking again
Until Not $result
Else
   GUIDelete()
 EndIf
WEnd

 

 

Edited by Ilounah
My Boss ask me to remove :( attached video
Link to comment
Share on other sites

Hi @Ilounah,

even if you achieve your expected behavior, it's not robust and totally insecure 😔 .

What if someone moves the browser window (or resize the window)? Your GUI overlay will be on the wrong position. What exactly do you want? Is it your website? Can you do such validation by JavaScript (or even better in the backend)?

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

  • Solution

Probably main problem is this:

Do
    Sleep(1000) ; wait 1 second before checking again
Until Not $result

$result is an array, not really something that you can do good checking against to determine true/false by itself. Also, you are NOT doing any checks to see if the color is still there.

Also this part:

Local $color = "0x6EC89B" ; the color you are looking for (green)
Local $result = PixelSearch(0, 137, 1, 465, 0xE8E9F1, 0)

You're searching a different color than $color, because you're not using $color for the call. Also the 0 at the end of the function means that the color must match exactly, it may be a good idea to allow some variance.

Next up this part: 

Opt("PixelCoordMode", 2)
;
WinActivate($hGui)

PixelCoordMode 2 means relative to the client, however you're changing what the client is with WinActivate, so your PixelSearch will now be searching the wrong coordinates. Also deleting the GUI and re-making it isn't the best idea. Check out my modifications (still set up to test on my computer, so your color and search location are different):

#include <GuiConstants.au3>

OnAutoItExitRegister('__Exit')

AutoItSetOption("PixelCoordMode", 1) ; 1 = Screen coords, 2 = relative to Client
AutoItSetOption("WinWaitDelay", 50)

Global $hGui = Null, $hTimer
Global $iColor = "0x5379BD" ; the color you are looking for (green)
Global $iState, $iColorShadeVariation = 10
Global $aResult, $aWinPos, $aGuiPos[2] = [350, 907], $aSearchPos[4] = [2797, 791, 2798, 792]
$hGui = GUICreate("Disabled", 180, 60, $aGuiPos[0], $aGuiPos[1], $WS_DISABLED, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) ; $WS_DISABLED to prevent moving/resizing, $WS_EX_TOOLWINDOW so that it doesn't create an icon in the taskbar
GUISetState(@SW_HIDE, $hGui) ; Make sure the GUI is initially hidden
GUISetState(@SW_DISABLE, $hGui) ; Make sure the GUI is disabled, so it can't be messed with

While 1
    Sleep(10) ; Small sleep to avoid thrashing the CPU
    $aResult = PixelSearch($aSearchPos[0], $aSearchPos[1], $aSearchPos[2], $aSearchPos[3], $iColor, $iColorShadeVariation)
    If Not @error And IsArray($aResult) Then ; PixelSearch was successful
;~      ConsoleWrite('Success: ' & $aResult[0] & ', ' & $aResult[1] & @CRLF)
        GUISetState(@SW_SHOW, $hGui) ; Show our 'Disabled' GUI
        WinMove($hGui, '', $aGuiPos[0], $aGuiPos[1], Default, Default, 0) ; Move to the correct position
        WinSetOnTop($hGui, "", 1) ; Make sure it's set ontop
;~      WinActivate($hGui) ; We have no need to activate the window
        Do
            ; With the window disabled it can't be moved, so this below code isn't needed (or shouldn't be) to keep it in place
;~          $aWinPos = WinGetPos($hGui)
;~          If $aWinPos[0] <> $aGuiPos[0] Or $aWinPos[1] <> $aGuiPos[1] Then
;~              WinMove($hGui, '', $aGuiPos[0], $aGuiPos[1], Default, Default, 0)
;~          EndIf
            Sleep(10) ; Small wait to check again to avoid thrashing the CPU, but not so long that it's a hinderance
            $aResult = PixelSearch($aSearchPos[0], $aSearchPos[1], $aSearchPos[2], $aSearchPos[3], $iColor, $iColorShadeVariation)
        Until @error Or Not IsArray($aResult) ; Go until the PixelSearch fails
        GUISetState(@SW_HIDE, $hGui) ; Hide the GUI
    Else ; PixelSearch failed, we did not find the color you were looking for
;~      ConsoleWrite('Not found' & @CRLF)
        $iState = WinGetState($hGui) ; Get the GUI state
        If BitAND($iState, $WIN_STATE_VISIBLE) Then ; If it's visible...
            GUISetState(@SW_HIDE, $hGui) ; Hide it
        EndIf
    EndIf
WEnd

Func __Exit()
    GUIDelete($hGui)
EndFunc   ;==>__Exit

 

Edit: Also completely agree with @SOLVE-SMART, it looks like you're zoomed to 110%, and you'll likely have the incorrect coordinates with a different zoom level, browser, theme, screen resolution, window size, etc. This is definitely not the best way to do what you want to do.

Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

Thank you Guy's, It works now, this is just a temporary solution and I have 10 employees and they were not so High skill on computer.
 

If Not BitAND(WinGetState("[CLASS:MozillaWindowClass]"), 32) Then ;If winsow is minimized
        WinSetState("[CLASS:MozillaWindowClass]", "", @SW_MAXIMIZE)
   EndIf

Im adding this one so if they will try to restore down or change sa size.

And I wish they dont change the Zoom Scale 😅

Link to comment
Share on other sites

5 minutes ago, Ilounah said:

And I wish they dont change the Zoom Scale 😅

🤣🤞

Hope is always good! I wish you the best result with your employees.

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

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...