souldjer777 Posted November 5, 2012 Share Posted November 5, 2012 As painful as this has become... I've given up and I'm asking for help again... lol Smashing my head into the desk has become too obvious an answer. I have a gui that has a whole list of buttons where I need them to be clickable and initiate an action. My code is pretty simple - as am I - lol What should I have in my GuiSetState() portion of my program to make my buttons clickable? I've tried some "borrowed" Case For... Next statements in random Forum answers and just wound up nowhere. Sorry if this is the 100th time anyone has seen this. Thanks in Advance - Props to AutoIT - Program is freakin' sweet! Sites_links2.txt site1 site2 site3 site4 #include <File.au3> #include <GUIConstantsEx.au3> Global $sites_array1 $file_path1 = "sites_links2.txt" ; file contains site names one line at a time. Site1 first line, Site2 second line, Site3... If Not _FileReadToArray($file_path1, $sites_array1) Then MsgBox(4096, "Error", " Error reading log to Array error:" & @error) Exit EndIf MsgBox(0, "array", $sites_array1[0]) $test1 = $sites_array1[0] $varStartHeight=0 $varStartHeight += 5 Local $Button [ $test1 + 1 ] GUICreate("Test") For $x = 1 To UBound($sites_array1) - 1 $Button[$x] = GUICtrlCreateButton($sites_array1[$x], 30, $varStartHeight, 55, 27) $varStartHeight += 30 Next GUISetState() While 1 $msg=GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd "Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"Song Title: I guess you could sayArtist: Middle Class Rut Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 5, 2012 Moderators Share Posted November 5, 2012 souldjer777, I would do it like this: While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case Else For $i = 1 To UBound($sites_array1) - 1 If $msg = $Button[$i] Then MsgBox(0, "Pressed", GUICtrlRead($Button[$i])) ExitLoop EndIf Next EndSelect WEnd Please ask if you have any questions. M23 souldjer777 1 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...
careca Posted November 5, 2012 Share Posted November 5, 2012 (edited) While that works, sometimes there would be too many if's and endif's (I mean loops and conditions)and it got hard to keep track of them so if that happens to you, try this:Opt("GUIOnEventMode", 1) $Var = GUICtrlCreateButton("ButtonText", 96, 34, 75, 25) GUICtrlSetOnEvent($Var, "SomeFunction") Func SomeFunction() Sleep(100) EndFunc Edited November 5, 2012 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
souldjer777 Posted November 5, 2012 Author Share Posted November 5, 2012 Just wanted to say thanks - Melba23 ! Yes - you rock "Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"Song Title: I guess you could sayArtist: Middle Class Rut Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 6, 2012 Moderators Share Posted November 6, 2012 souldjer777,While I do not necessarily agree with careca's opinion that there could be "too many [...] loops and conditions", you might like to see why using OnEvent mode might be useful in this particular case: #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) ; Simulate reading file Global $sites_array1[4] = [4, "Link 1", "Link 2", "Link 3"] $test1 = $sites_array1[0] $varStartHeight = 0 $varStartHeight += 5 Local $Button[$test1 + 1] GUICreate("Test") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") For $x = 1 To UBound($sites_array1) - 1 $Button[$x] = GUICtrlCreateButton($sites_array1[$x], 30, $varStartHeight, 55, 27) GUICtrlSetOnEvent(-1, "_Pressed") $varStartHeight += 30 Next GUISetState() While 1 Sleep(10) WEnd Func _Pressed() MsgBox(0, "Pressed", GUICtrlRead(@GUI_CTRLID)) ; AutoIt tells you which button was pressed automatically EndFunc Func _Exit() Exit EndFuncIt is a personal choice which mode to use - there are advantages and disadvantages to both. Just do not mix them in the same script - big alarm bells should go off if you find that you need to and recasting the code to use just the one is probably a better idea. But you can use both if you take great care and only use one at a time - look in my ExtMsgBox UDF to see how it uses MessageLoop regardless of what mode the calling script is using, but then resets the original mode before returning. 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 November 6, 2012 Share Posted November 6, 2012 OnEventMode is useful if the GUI isn't of great importance to the application. 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...
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