Em4gdn1m

combo and checkbox

8 posts in this topic

Hey everyone, I'm curious if there is a way to incorporate a checkbox with a combo GUICtrl?

so for instance I have a GUI that has a bunch of checkboxes that allow me to open certain programs as needed.  (this is just some parsing of my code, sorry, noob here and not sure what the preferred method of displaying code is, please enlighten me)


    $L0742 = GUICtrlCreateCheckbox("L07 4.2", 110, 320, 100)
    $L07502 = GUICtrlCreateCheckbox("L07 5.0.2", 110, 350, 100)
    $GenComm = GUICtrlCreateCheckbox("GenComm", 110, 380, 100)
    $Templates = GUICtrlCreateCheckbox("Templates", 110, 410, 100)
    $MCT = GUICtrlCreateCheckbox("MCT", 110, 440, 100)
    $Desktop_Shortcuts = GUICtrlCreateCheckbox("Desktop Shortcuts by Tester", 110, 470, 200)

 

...

Case $msg = $RunBtn
            RunPrograms()

 

...

Func RunPrograms()

    if GUICtrlRead($L0742) = $GUI_CHECKED then Run("C:\Program Files\Varian\Paxscan\L07 Rel4.2\viva\viva.exe", "")
    if GUICtrlRead($L07502) = $GUI_CHECKED then Run("C:\Program Files\Varian\Paxscan\L07 Rel5\viva\viva.exe", "")
    if GUICtrlRead($GenComm) = $GUI_CHECKED then Run("\\Fpanelfs1\FPShared\Desktop_Shortcuts_by_Tester\Matt\CPI Generator\CPI Generator Windows 7 64 Bit\GenComm\GenComm.NET.exe", "")
    if GUICtrlRead($Templates) = $GUI_CHECKED then ShellExecute("\\Fpanelfs1\FPProjects\Documentation Controlled\Test_Templates")
    if GUICtrlRead($MCT) = $GUI_CHECKED then Run("\\Fpanelfs1\FPProjects\Documentation Controlled\Manufacturing Software\MCT\MCT.exe","")
    if GUICtrlRead($Desktop_Shortcuts) = $GUI_CHECKED then ShellExecute("\\Fpanelfs1\fpshared\Desktop_Shortcuts_by_Tester")
EndFunc

 

so i click some checkboxes, and hit a run button and the programs which are checked run, great.

BUT i want to add a bunch of options under one checkbox. A combo that will list a bunch of versions of a program that can be opened. something like this... but I want that program to be part of a checkbox

$ViVAComboBox = GUICtrlCreateCombo("L01 Rel 13", 110, 320, 100)

GUICtrlSetData($ViVAComboBox, "L04|L05|L07 Rel 4.2|L07 Rel 5.0.2|L09", "L07 Rel 4.2")

 

is this possible? is there another GUICtrl that does this better that i am not aware of?

 

 

Share this post


Link to post
Share on other sites



There isn't a control that combines a checkbox and a combobox, but you could put a checkbox next to one and disable the combo until that check box has been checked.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

that sounds like it could work. anything to get me started? still really noob at this stuff.

 

mainly how do i read what is in the combo box and run that specific program?

Edited by Em4gdn1m
clarification

Share this post


Link to post
Share on other sites

so basically I added

While 1

GUICtrlRead($ViVACheckBox)

if GUICtrlRead($ViVACheckBox) = $GUI_CHECKED then GUICtrlSetState($ViVAComboBox, $GUI_ENABLE)

if GUICtrlRead($ViVACheckBox) = $GUI_UNCHECKED then GUICtrlSetState($ViVAComboBox, $GUI_DISABLE)

WEnd

and then

if GUICtrlRead($ViVAComboBox) == "L07 Rel 4.2" then Run("The L07 Rel 4.2 destination here", "")
if GUICtrlRead($ViVAComboBox) == "L01 Rel 13" then Run("The L01 Rel 13 destination here", "")
...

but it's not caring if the combobox is enabled or not. it still just runs the program

and also, the constant checking of the state of the checkbox is kinda weird... id image there is some way to only check the state if the state changes?

Share this post


Link to post
Share on other sites

This might help clean up the code a bit and make it easier to add additional items later on to the combo box.

While 1
    Switch GUICtrlRead($ViVACheckBox)
        Case $GUI_CHECKED
            GUICtrlSetState($ViVAComboBox, $GUI_ENABLE)
        Case Else
            GUICtrlSetState($ViVAComboBox, $GUI_DISABLE)
    EndSwitch
WEnd
Switch GUICtrlRead($ViVAComboBox)
    Case "L07 Rel 4.2"
        Run("The L07 Rel 4.2 destination here", "")
    Case "L01 Rel 13"
        Run("The L01 Rel 13 destination here", "")
    Case ...
EndSwitch

As to the combo being read regardless of whether it's enabled or not, that's normal. You have to code the script so that it checks whether it needs to read that combobox or not when you go to run your programs.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
While 1
    Switch GUICtrlRead($ViVACheckBox)
        Case $GUI_CHECKED
            GUICtrlSetState($ViVAComboBox, $GUI_ENABLE)
        Case Else
            GUICtrlSetState($ViVAComboBox, $GUI_DISABLE)
    EndSwitch
WEnd

This part seems to do nothing with the constant checking of the state, and likewise, nothing different than what I had, though definitely a lot prettier which I like. but there is this constant flashing of the combo box that began when i added my while statement, and didn't stop with yours.

11 minutes ago, BrewManNH said:

 

As to the combo being read regardless of whether it's enabled or not, that's normal. You have to code the script so that it checks whether it needs to read that combobox or not when you go to run your programs.

I tried  doing

if GUICtrlRead($ViVAComboBox) = $GUI_ENABLE & "L07 Rel 4.2" then Run("FILE", "")

;and 

if GUICtrlRead($ViVAComboBox) == $GUI_ENABLE & "L07 Rel 4.2" then Run("file", "")

but neither seemed to work. not sure what to try. I want it to only run if the ViVACheckbox is checked... so

if GUICtrlRead($ViVACheckBox)= $GUI_CHECKED then ;IDK NOW

 

Share this post


Link to post
Share on other sites

 

neither

If GUICtrlRead($ViVACheckBox) = $GUI_ENABLE then
    Switch GUICtrlRead($ViVAComboBox)
        Case "L01 Rel 13"
            Run("C:\Program Files\Speccy\Speccy64.exe", "")
        Case "L04"
            Run("The L01 Rel 13 destination here", "")
        Case "L05"
            Run("The L01 Rel 13 destination here", "")
        Case "L07 Rel 4.2"
            Run("The L01 Rel 13 destination here", "")
        Case "L07 Rel 5.0.2"
            Run("The L01 Rel 13 destination here", "")
        Case "L09"
            Run("The L01 Rel 13 destination here", "")
    EndSwitch
EndIf

nor

If GUICtrlRead($ViVAComboBox) = $GUI_ENABLE then
...

works at opening a program at all

Share this post


Link to post
Share on other sites

actually...

If GUICtrlRead($ViVACheckBox) = $GUI_CHECKED then
        Switch GUICtrlRead($ViVAComboBox)
            Case "L01 Rel 13"
                Run("C:\Program Files\Speccy\Speccy64.exe", "")
            Case "L04"
                Run("The L01 Rel 13 destination here", "")
            Case "L05"
                Run("The L01 Rel 13 destination here", "")
            Case "L07 Rel 4.2"
                Run("The L01 Rel 13 destination here", "")
            Case "L07 Rel 5.0.2"
                Run("The L01 Rel 13 destination here", "")
            Case "L09"
                Run("The L01 Rel 13 destination here", "")
        EndSwitch
    EndIf

worked, now it's just the constant checking of the checkbox. any ideas on that?

Share this post


Link to post
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

  • Similar Content

    • IAMK
      By IAMK
      Hello,
       
      I have a script which uses a GUI with two buttons. It gets shown and hidden., and pressing the buttons (including their hotkeys) highlights the button, making you able to press enter the next time.
      However, I don't want that.
       
      I've tried using WinActivate() to make enter do things on another program, but the enter is still tied to the AutoIT GUI (which still has the button highlighted).
       
      Here's the important part of my code:
      $MY_GUI = GUICreate("Check.exe", 400, 300, ((@DesktopWidth / 2) - 200), -500) WinSetOnTop($MY_GUI, "", 1) ;Keeps the window on the top. $Button1 = GUICtrlCreateButton("Pass (Ctrl+P)", 40, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button2 = GUICtrlCreateButton("Fail (Ctrl+F)", 240, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $GUIText = GUICtrlCreateLabel("", 20, 10, 360, 230) GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif") GUICtrlSetData($GUIText, Execute($stepMessage[$step])) $showGUI = "True" GUISetState(@SW_SHOW) While($showGUI = "True") $buttonPressed = GUIGetMsg() Switch $buttonPressed Case $Button1 ;Pass $pass = "True" $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) Case $Button2 ;Fail $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) While($message = "") $message = InputBox("Check.exe", "Please enter the reason the step failed." & @CRLF, "", "", 300, 200, ((@DesktopWidth / 2) - 150), -400) WEnd Return $message EndSwitch WEnd Local $pass = "False" ;Whether "Pass" or "Fail" was pressed. Local $failLog = xxxfunc($pass) ;Returns a message to log if the step failed. ##THIS CALLS THE CODE SNIPPET ABOVE## FileWrite($file, _Now() & ": Step " & $step & getStatus($pass) & "and took " & Ceiling(TimerDiff($timer) / 1000) & " seconds." & @CRLF) If($failLog <> "") Then FileWrite($file, "Logged comment: " & $failLog & @CRLF) EndIf WinActivate("[TITLE:ProgramName]") ;Hotkeys: HotKeySet("^{p}", "pressPass") HotKeySet("^{f}", "pressFail") Func pressPass() $buttonPressed = $Button1 EndFunc Func pressFail() $buttonPressed = $Button2 EndFunc  
      The GUI's button/hotkey pressing works correctly.
      The same WinActivate code works in another script of mine.
      Together, WinActivate is not take "Active" away from the GUI's last-pressed button. How do I fix this?
       
      Thank you in advance.
    • P3rsp3ctiv3
      By P3rsp3ctiv3
      Hello how can I send a {Enter} into the edit window ($cmd)? I tried it first with:
      GUICtrlSetData($cmd, "Line 1" + "{ENTER}")
      but it doesn´t work. Can someone help me please?
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> $Admin = GUICreate("Admin", 234, 168, 192, 229, $GUI_SS_DEFAULT_GUI, BitOR($WS_EX_OVERLAPPEDWINDOW,$WS_EX_TRANSPARENT,$WS_EX_WINDOWEDGE)) GUISetBkColor(0xB4B4B4) $exit = GUICtrlCreateButton("Close", 160, 136, 65, 25) $cmd = GUICtrlCreateEdit("",0, 0, 225, 137, $ES_AUTOVSCROLL + $WS_VSCROLL) GUICtrlSetData(-1, "") GUICtrlSetFont(-1, 10, 400, 0, "Candara") GUICtrlSetBkColor(-1, 0xE3E3E3) $cmd_clear = GUICtrlCreateButton("Clear", 9, 136, 65, 25) GUISetState(@SW_SHOW) HotKeySet("{f1}", CMD_1) HotKeySet("{f2}", CMD_2) While 1 $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE Exit Case $exit GUIDelete($Admin) Exit EndSwitch WEnd Func CMD_1(); GUICtrlSetData($cmd, "Line 1" & "{ENTER}") GUICtrlSetData($cmd, "Line 2" & "{ENTER}") EndFunc Func CMD_2(); GUICtrlSetData($cmd, "Line 3" & "{ENTER}") GUICtrlSetData($cmd, "Line 4" & "{ENTER}") EndFunc
    • nacerbaaziz
      By nacerbaaziz
      hello
      please i need to link a progress bar with a time can you help me?
      e.g
      i want to set a progress bar for 10 sec
      am waiting for your answers
      thank you.
    • AdminC
      By AdminC
      #RequireAdmin
      #include <SendMessage.au3>
      #include <WinAPI.au3>
      #include <WindowsConstants.au3>
      #include <GDIPlus.au3>
      #include <GUIConstantsEx.au3>
      #include <WinAPIGdi.au3>
      #include <Array.au3>
      #include <WinAPIDiag.au3>
      $Imglocation = @ScriptDir&"\Image\testimg.bmp"
      _GDIPlus_Startup()
      Local $Bitmap = _GDIPlus_BitmapCreateFromFile($Imglocation)
      Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap)
      Local $imgSize = _WinAPI_GetBitmapDimension($hBitmap)
      Local $imgBits = DllStructCreate('dword[' & ($imgSize.X * $imgSize.Y) & ']')
      _WinAPI_GetBitmapBits($hBitmap, DllStructGetSize($imgBits), DllStructGetPtr($imgBits))
      _WinAPI_DisplayStruct($imgBits)
      MsgBox(0, "", DllStructGetData($imgBits, 1, 1)) 
      _GDIPlus_Shutdown()
      DllstructGetData can't get data color B, G, R value. Who's know that? teach me plz
       
    • fatpig
      By fatpig
      Dear AutoIT Community.
      I am currently working on a program that will display lots of images in a scroll down GUI.
      I create the GUI based on the number of images, which works fine.
      But all images I place using GuiCtrlCreatePic above a threshold of around 32000 pixels (cant say exactly) are placed at negative locations and finally will reach 0 again
      and will then populate on top of the images placed there before.
      For $i = 1 To $Images[0] ; Get picture dimensions $hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $Images[$i]) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) ; Resize & place images in GUI $Pic[$i] = GUICtrlCreatePic($ImgRep & $Images[$i], $Spacer, Round($yPos, 0), $MaxImgWidth, $MaxImgWidth * ($iY / $iX)) $yPos = $yPos + $MaxImgWidth * ($iY / $iX) + $Spacer $log = $log & "|" & $yPos $currentlut = $Images[1] Next I have found a limit at 32767 pixels for some GUI elements when googling around.
      Can someone tell me how to circumvent that?
      thanks!
      cheers
      Felix