Jump to content

Support variable number of buttons


Recommended Posts

I had some problems already to create the topic title. I'll try to be more clear with the post.

The idea is to create a GUI with some buttons, but not a defined number of buttons (in my case each button represents an action that can be done on a file and allowed actions vary in function of file itself).

So in this GUI I can have 2 or 3 or more of these buttons and I need to detect if they are clicked. The problem is that in the Switch selection of the While loop I don't have a defined number of items and so I cannot do something like this:

Case $Button1, $Button2, $Button3

So I tried the following solution, but the problem is that it works only sometimes (I think it works fine only when a button is clicked and $mCount is exactly that button):

Func _MoreMatches($mMatches, $mFileName)
    Local $mEmptyDestination = "Empty-Destination"

    Local $mGUI, $mType, $mAdditional, $mCancel, $mButtons[$mMatches[0][0] + 1] = [0], $mCount = 0, $mRead = -1
    If Not IsArray($mMatches) Then Return SetError(1, 1, 0) ; Exit Function If Not An Array.
    $mGUI = GUICreate('Pattern Ambiguity', 280, 115 + 23 * $mMatches[0][0], -1, -1, -1, $WS_EX_TOOLWINDOW)

    GUICtrlCreateGroup('Loaded item:', 8, 6, 264, 40)
    GUICtrlCreateLabel($mFileName, 26, 24, 230, 20)
    GUICtrlSetTip($mFileName, 'This item fits with several patterns.')
    GUICtrlCreateGroup("", -99, -99, 1, 1)

    GUICtrlCreateGroup('Select what pattern to apply:', 8, 52, 264, 22 + 23 * $mMatches[0][0])

    For $A = 1 To $mMatches[0][0]
        $mType = StringRight($mMatches[$A][0], 2)
        $mAdditional = StringTrimRight($mMatches[$A][0], 2)
        $mButtons[$A] = GUICtrlCreateButton(" " & $mAdditional, 25, 46 + ($A * 23), 230, 22)
        $mButtons[0] += 1
    Next
    GUICtrlCreateGroup("", -99, -99, 1, 1)

    $mCancel = GUICtrlCreateButton('Cancel', 140 - 45, 82 + 23 * $mMatches[0][0], 90, 24)
    GUISetState(@SW_SHOW)

    While 1
        If $mCount = $mButtons[0] Then $mCount = 0
        $mCount += 1
        Sleep(50)

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $mCancel
                $mRead = -1
                ExitLoop

            Case $mButtons[$mCount]
                $Global_Action = StringRight($mMatches[$mCount][0], 2) ; Set Action For This File/Folder.
                $mRead = $mMatches[$mCount][1]
                ExitLoop

        EndSwitch
    WEnd
    GUIDelete($mGUI)

    If $mRead = -1 Or $mRead = $mEmptyDestination Then Return SetError(1, 1, -1)
    Return $mRead
EndFunc   ;==>_MoreMatches
Edited by Lupo73

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Link to comment
Share on other sites

  • Moderators

Lupo73,

Why not create all the buttons each time and just hide the ones that are not valid for that particular file? Then you can have a universal Switch structure within your While...WEnd loop and the unwanted buttons will never fire because they are not visible to be clicked. :)

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

 

Link to comment
Share on other sites

Maybe something like this >>

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
_Main()

Func _Main()
    Local $aPatterns[5] = [4, "Pattern 1", "Pattern 2", "Pattern 3", "Pattern 4"], $aButtons[$aPatterns[0] + 1] = [0], $hMsg
    GUICreate("_Main()", 150, 255)
    For $i = 1 To $aPatterns[0]
        $aButtons[$i] = GUICtrlCreateButton($aPatterns[$i], 10, 30 * $i)
        $aButtons[0] += 1
    Next
    Local $iCancel = GUICtrlCreateButton("Cancel", 10, 30 * $i)
    GUISetState(@SW_SHOW)

    While 1
        $hMsg = GUIGetMsg()
        Switch $hMsg
            Case -3, $iCancel
                ExitLoop ; Exit While Loop!
            Case Else
                If $hMsg >= $aButtons[1] And $hMsg <= $aButtons[$aButtons[0]] Then
                    For $i = 1 To $aButtons[0]
                        If $hMsg = $aButtons[$i] Then
                            MsgBox(0, "You Chose >>", GUICtrlRead($aButtons[$i]))
                            ExitLoop 2 ; Exit For Loop & While Loop!
                        EndIf
                    Next
                    ExitLoop ; Exit While Loop!
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>_Main
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thanks! This solution works fine :)

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

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