Lupo73 Posted March 5, 2011 Share Posted March 5, 2011 (edited) 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, $Button3So 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):expandcollapse popupFunc _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 March 5, 2011 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 More sharing options...
Moderators Melba23 Posted March 5, 2011 Moderators Share Posted March 5, 2011 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
guinness Posted March 5, 2011 Share Posted March 5, 2011 (edited) 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 March 5, 2011 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Lupo73 Posted March 6, 2011 Author Share Posted March 6, 2011 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now