Jump to content
ReconX

I'm trying to update a string when an InputBox is updated. I'm stuck.

Recommended Posts

I am writing a little program to help me inventory my Blu-ray collection in Plex. What it does is, when I type in a name and year, it creates a dummy .mkv file for Plex to pick up. I've created a ComboBox to help me determine which directory to store the files in that is pre-determined in the Settings tab. When I select DVD from the ComboBox on the main tab, it is supposed to read the File Directory chosen by the user in the settings tab. I've set a test Label in the Test tab, but cannot get it to update. 

I hope I am explaining this to where someone will understand what I am trying to accomplish. Let me know if further information is needed. Thanks!

 

#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPI.au3>

; Here is the array
Global $aArray[4] = ["DVD", "Blu-ray", "4K", "3D"]
Global $fileDIR = "C:\"
$hTitle = "Add Movie to Inventory"

; And here we get the elements into a list
$sList = ""
For $i = 0 To UBound($aArray) - 1
    $sList &= "|" & $aArray[$i]
Next

Example()

Func Example()
    $hGUI = GUICreate($hTitle, 460) ; will create a dialog box that when displayed is centered

    $hTab = GUICtrlCreateTab(10, 10, 441, 380)

    GUICtrlCreateTabItem("Inventory Movie")
    GUICtrlCreateGroup("This tool creates dummy .mkv files, and puts them in the same directory as this script.", 20, 40, 420, 98) ;Start Group
    Opt("GUICoordMode", 0)
    $inputText1 = GUICtrlCreateLabel("Movie Name:", 10, 25, 75, 20)
    $inputName = GUICtrlCreateInput("", 90, -2, 289, 20)
    $tmdbSearch = GUICtrlCreateButton("+", 292, 0, 20, 20)
    $inputText2 = GUICtrlCreateLabel("Movie Year:", -382, 26, 75, 20)
    $inputYear = GUICtrlCreateInput("", 90, -2, 311, 20)
    $submit = GUICtrlCreateButton("Create", 90, 24, 221, 20)
    $hCombo = GUICtrlCreateCombo("", -90, -1, 80, 20, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
    GUICtrlSetData($hCombo, $sList, "DVD")
    Opt("GUICoordMode", 1) ; GUI coords
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group

    GUICtrlCreateTabItem("Settings")
    GUICtrlCreateGroup("Directories", 20, 40, 420, 135) ;Start Group
    Opt("GUICoordMode", 0)
    GUIStartGroup()
    $inputText1 = GUICtrlCreateLabel("DVD:", 10, 25, 75, 20)
    $inputText2 = GUICtrlCreateLabel("Blu-ray:", -1, 26, 75, 20)
    $inputText3 = GUICtrlCreateLabel("4K:", -1, 26, 75, 20)
    $inputText4 = GUICtrlCreateLabel("3D:", -1, 26, 75, 20)
    GUIStartGroup()
    $hDVD = GUICtrlCreateInput("1234", 50, -80, 350, 20)
    $hBLU = GUICtrlCreateInput("", -1, 26, 350, 20)
    $h4K = GUICtrlCreateInput("", -1, 26, 350, 20)
    $h3D = GUICtrlCreateInput("", -1, 26, 350, 20)
    GUIStartGroup()
    $bDVD = GUICtrlCreateButton("...", 331, -77, 18, 18)
    $bBLU = GUICtrlCreateButton("...", -1, 26, 18, 18)
    $b4K = GUICtrlCreateButton("...", -1, 26, 18, 18)
    $b3D = GUICtrlCreateButton("...", -1, 26, 18, 18)


    Opt("GUICoordMode", 1) ; GUI coords
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    GUICtrlSetState($hDVD, $GUI_DISABLE)
    GUICtrlSetState($hBLU, $GUI_DISABLE)
    GUICtrlSetState($h4K, $GUI_DISABLE)
    GUICtrlSetState($h3D, $GUI_DISABLE)

    GUICtrlCreateTabItem("TEST")
    GUICtrlCreateLabel($fileDIR , 30, 80, 50, 20)
    $TESTING = GUICtrlRead($hDVD)
    GUICtrlCreateLabel($TESTING, 30, 200, 50, 20)

    GUICtrlCreateTabItem("") ; end tabitem definition

    GUISetState(@SW_SHOW)

    $guiRead = GUICtrlRead($hCombo)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $submit
                $movieName = GUICtrlRead($inputName)
                $movieYear = GUICtrlRead($inputYear)
                If FileExists($movieName & " (" & $movieYear & ").mkv") Then
                    MsgBox($MB_SYSTEMMODAL, "Movie Exists!!!!", "This Movie Already Exists!!!!", 10)
                    GUICtrlSetData($inputName, "")
                    GUICtrlSetData($inputYear, "")
                    _WinAPI_SetFocus(ControlGetHandle("", "", $inputName))
                Else
                    FileWrite($movieName & " (" & $movieYear & ").mkv", "PLACEHOLDER")
                    GUICtrlSetData($inputName, "")
                    GUICtrlSetData($inputYear, "")
                    _WinAPI_SetFocus(ControlGetHandle("", "", $inputName))
                EndIf
            Case $tmdbSearch
                $movieName = GUICtrlRead($inputName)
                ShellExecute("https://www.themoviedb.org/search?query=" & $movieName)
                WinActivate($hGUI)
                _WinAPI_SetFocus(ControlGetHandle("", "", $inputYear))
;~          Case $test
;~              ; Create a constant variable in Local scope of the message to display in FileSelectFolder.
;~              Local $sMessage = "Select a folder"
;~              ; Display an open dialog to select a file.
;~              Local $sFileSelectFolder = FileSelectFolder($sMessage, "")
;~              If @error Then
;~                  ; Display the error message.
;~                  MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
;~              Else
;~                  ; Display the selected folder.
;~                  MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
;~              EndIf
;~              GUICtrlSetData($hDVD, $sFileSelectFolder)
            Case $bDVD
                Local $sDVDFolder = FileSelectFolder("Select a folder...", "%CSIDL_DRIVES%")
                If @error Then
                    MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
                Else
                    GUICtrlSetData($hDVD, $sDVDFolder)
                EndIf
            Case $hCombo
                If $guiRead = $aArray[0] Then
                    GUICtrlSetData($fileDIR, $guiRead)
;~                  $fileDIR = GUICtrlRead($hDVD)
                Else
                    ExitLoop
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites

To clarify "if" you select DVD in the ComboBox, you want it to read the corresponding input box labeled DVD? "If" that is the case you can move this

$guiRead = GUICtrlRead($hCombo)

into your

Case $hCombo

and use some "If" statements
If $guiRead == "DVD" then
GuiCtrlread($hDVD)
endif

Share this post


Link to post
Share on other sites

Yes, so if I select DVD in the ComboBox, I want it to read the input box labeled DVD and set it to $fileDIR. The same will go for Blu-ray if I were to select it in the ComboBox, it would read the Input Box labeled Blu-ray and set that to $fileDIR.

I've set a variable of $fileDIR which will be the directory selected through the ComboBox. So, if the directory listed in the input box labeled DVD is, "C:\DVD", and the ComboBox has DVD selected, I would want;

FileWrite($fileDIR & "\" & $movieName & " (" & $movieYear & ").mkv", "PLACEHOLDER")

to read, "C:\DVD\Moviename (2020).mkv". 

I'm quite new to AutoIt, so please excuse my coding and explanations. :D

Edited by ReconX

Share this post


Link to post
Share on other sites

I think that's how you would detect an update on a combo box

#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

AutoItSetOption("MustDeclareVars", 1)

Local $GUIHandle = GUICreate("Test", 200, 100) ; will create a dialog box that when displayed is centered
Local $comboBox = GUICtrlCreateCombo("", 5, 5, 80, 20)
GUICtrlSetData($comboBox, "Luke|use|the|force", "use")
Local $label = GUICtrlCreateLabel("", 5, 30, 150, 20)

GUIRegisterMsg($WM_COMMAND, "My_WM_COMMAND")
GUISetState(@SW_SHOW, $GUIHandle)

Local $comboBoxChangedFlag = True
Local $close = False
While Not $close
   Local $event = GUIGetMsg($GUI_EVENT_SINGLE)
   Switch $event
      Case $GUI_EVENT_CLOSE
         $close = True
      Case Else
         ; Do nothing
   EndSwitch

   If $comboBoxChangedFlag Then
      GUICtrlSetData($label, GUICtrlRead($comboBox))
      $comboBoxChangedFlag = False
   EndIf
WEnd

 Func My_WM_COMMAND($hWnd, $imsg, $iwParam, $ilParam)
   Local $windowHandle = $ilParam
   Local $controlId = _WinAPI_LoWord($iwParam)
   Local $eventId = _WinAPI_HiWord($iwParam)
   If $windowHandle <> 0 Then
      Switch $controlId
         Case $comboBox
            Switch $eventId
               Case $CBN_SELCHANGE
                  $comboBoxChangedFlag = True
               Case Else
                  ; Do nothing.
            Endswitch
         Case Else
            ; Do nothing.
      Endswitch
   EndIf

   Return $GUI_RUNDEFMSG
EndFunc

Found it in a post from @Melba23 at this https://www.autoitscript.com/forum/topic/104923-wm_command/

Share this post


Link to post
Share on other sites

boom221 & ReconX,

You only need a WM_COMMAND handler when dealing with edit controls which do not fire a GUIGetMsg-detectable event when the content is changed - which is why one was needed in the thread to which you linked. When dealing with a combo you can simply use the GUIGetMsg loop to detect changes:

#include <GUIConstantsEx.au3>

AutoItSetOption("MustDeclareVars", 1)

Local $GUIHandle = GUICreate("Test", 200, 100) ; will create a dialog box that when displayed is centered
Local $comboBox = GUICtrlCreateCombo("", 5, 5, 80, 20)
GUICtrlSetData($comboBox, "Luke|use|the|force", "use")
Local $label = GUICtrlCreateLabel("", 5, 30, 150, 20)

GUISetState(@SW_SHOW, $GUIHandle)

Local $close = False
While Not $close
    Local $event = GUIGetMsg()
    Switch $event
        Case $GUI_EVENT_CLOSE
            $close = True
        Case $comboBox
            GUICtrlSetData($label, GUICtrlRead($comboBox))
    EndSwitch
WEnd

Rather simpler and definitely more elegant!

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...