Jump to content

Can you trigger a Case?


Recommended Posts

Hello,

I have a Case that has about 20 lines of code. When the GUI starts, I need this code to run once. I could copy the code before the While statement, but I think this is sloppy. Is there a way to trigger this case just once by code and not clicking something on the GUI?

Here is an example. Let's say I want to change to color to red when the GUI starts and not have to click the dropdown list. I tried ControlClick, but when you do that, it makes the dropdown list expand and not actually select the option to change color.

 

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>

$Form1 = GUICreate("Form3", 210, 159, 301, 164)
$Combo1 = GUICtrlCreateCombo("", 16, 16, 145, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Do Nothing|Change Color", "Do Nothing")
$Label1 = GUICtrlCreateLabel("Label1", 24, 56, 36, 17)
$Label2 = GUICtrlCreateLabel("Label2", 24, 88, 36, 17)
$Label3 = GUICtrlCreateLabel("Label3", 24, 128, 36, 17)
$Label4 = GUICtrlCreateLabel("Label4", 112, 56, 36, 17)
$Label5 = GUICtrlCreateLabel("Label5", 112, 88, 36, 17)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Combo1
            $cRead = GUICtrlRead($Combo1)
            If $cRead = "Change Color" Then
                GUICtrlSetColor($Label1, 0xff0000)
                GUICtrlSetColor($Label2, 0xff0000)
                GUICtrlSetColor($Label3, 0xff0000)
                GUICtrlSetColor($Label4, 0xff0000)
                GUICtrlSetColor($Label5, 0xff0000)
            EndIf
    EndSwitch
WEnd

I also want to point out that I know it can be done using functions, but this gui is a secondary gui and it is already in a function. I don't want to make the variables Global or have to pass them from function to function.

Thanks for any advice you guys might have!

 

Edited by abberration
Link to comment
Share on other sites

I don't see why you wouldn't just set the GuiCtrlSetColor prior to the GUISetState...but something like this maybe?

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>

$bOnce = True
$Form1 = GUICreate("Form3", 210, 159, 301, 164)
$Combo1 = GUICtrlCreateCombo("", 16, 16, 145, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Do Nothing|Change Color", "Do Nothing")
$Label1 = GUICtrlCreateLabel("Label1", 24, 56, 36, 17)
$Label2 = GUICtrlCreateLabel("Label2", 24, 88, 36, 17)
$Label3 = GUICtrlCreateLabel("Label3", 24, 128, 36, 17)
$Label4 = GUICtrlCreateLabel("Label4", 112, 56, 36, 17)
$Label5 = GUICtrlCreateLabel("Label5", 112, 88, 36, 17)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $Combo1 Or $bOnce
            $cRead = GUICtrlRead($Combo1)
            If $cRead = "Change Color" Or $bOnce Then
                GUICtrlSetColor($Label1, 0xff0000)
                GUICtrlSetColor($Label2, 0xff0000)
                GUICtrlSetColor($Label3, 0xff0000)
                GUICtrlSetColor($Label4, 0xff0000)
                GUICtrlSetColor($Label5, 0xff0000)
                $bOnce = False
            EndIf
    EndSelect
WEnd

 

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...