InunoTaishou Posted September 26, 2014 Share Posted September 26, 2014 (edited) I'm wanting to change a couple of variables for a GUISetFont (the size, font name and weight) using menuitems but I'm creating menu items using for loops, so each item doesn't have a name. Can I still change a variable using menu items that are not declared but created using for loops? Modify these variables Local $size = 13, $weight = 400, $attribute = "", $fontname = "" Menus Local $text_menu = GUIctrlCreateMenu("&Text Properties") Local $font_menu = GUICtrlCreateMenu("Font", $text_menu, 1) Local $size_menu = GUICtrlCreateMenu("Text Size",$text_menu, 1) Local $weight_menu = GUICtrlCreateMenu("Weight",$text_menu, 2) And filling $font_menu, $size_menu, and $weight_menu using for loops For $i = 0 To UBound($fonts) - 1 Local $_font = GUICtrlCreateMenuItem($fonts[$i],$font_menu) Next Local $_size[0] For $i = 10 To 20 ; Local $_size = GUICtrlCreateMenuItem($i,$size_menu) _ArrayAdd($_size, GUICtrlCreateMenuItem($i,$size_menu)) Next For $i = 400 To 1500 Step +100 Local $_weight = GUICtrlCreateMenuItem($i,$weight_menu) Next/code] The loop [code]While 1 Switch GUIGetMsg() Case $GUI_Event_Close _Exit() Case $font_menu $fontname = $font_menu GUICtrlSetFont($notes,$size,$weight,$attribute,$fontname) Case $size_menu $size = $size_menu GUICtrlSetFont($notes,$size,$weight,$attribute,$fontname) Case $weight_menu $weight = $weight_menu GUICtrlSetFont($notes,$size,$weight,$attribute,$fontname) EndSwitch WEnd And the code (excluding functions) expandcollapse popup#include <ButtonConstants.au3> #include <GuiButton.au3> #include <GuiMenu.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <GUIListView.au3> #include <GUIConstants.au3> #include <StaticConstants.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <GUIComboBox.au3> #include <Constants.au3> #include <File.au3> #include <Array.au3> #include <Misc.au3> #include <Date.au3> #include <EditConstants.au3> ; AutoIt Options and Default Hot Keys AutoitSetOption("WinTitleMatchMode",2) AutoitSetOption("SendKeyDelay",0) AutoitSetOption("GUIResizeMode", 1) HotKeySet("{PRINTSCREEN}","Reset_Flag") HotKeySet("{F1}","Help") Hotkeyset ("{Esc}", "CloseProc") ; Variables Local $string[] = ["Select", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "Delete", "End", "Home", "Insert", "PgUp", "PgDwn"] local $hidden = False Local $flag = 0, $help_flag = 0, $num = 20 Local $size = 13, $weight = 400, $attribute = "", $fontname = "" Local $DLL = "user32.dll", $path = @DocumentsCommonDir & "\", $iniFile = "Hot Key Settings.ini", $logPath = @DocumentsCommonDir & "\Logs\" Local $iniData = "Password=" & @LF & "lsusb=" & @LF & "Reboot=" & @LF & "Tail-f=" & @LF & "DVR Login=" & @LF & "Bill Acceptor Script=" Local $fonts = _FileLIstToArray(@WindowsDir & "\Fonts\") ; The GUI GuiCreate("Hotkeys",500,300,-1,-1,BitOr($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX)) Local $text_menu = GUIctrlCreateMenu("&Text Properties") Local $font_menu = GUICtrlCreateMenu("Font", $text_menu, 1) Local $size_menu = GUICtrlCreateMenu("Text Size",$text_menu, 1) Local $weight_menu = GUICtrlCreateMenu("Weight",$text_menu, 2) GUICtrlCreateMenuItem("",$text_menu,3) GUICtrlCreateLabel("Password Key:",5,5,75,15) GUICtrlSetResizing(-1,802) GUICtrlCreateLabel("lsusb Key:",5,30,75,15) GUICtrlSetResizing(-1,802) GUICtrlCreateLabel("Reboot Key:",5,55,75,15) GUICtrlSetResizing(-1,802) GUICtrlCreateLabel("Tail-f Key:",5,80,75,15) GUICtrlSetResizing(-1,802) GUICtrlCreateLabel("DVR login:",5,105,75,15) GUICtrlSetResizing(-1,802) GUICtrlCreateLabel("Bill Acceptor:",5,130,75,15) GUICtrlSetResizing(-1,802) $notes = GUICtrlCreateEdit("",160,5,330,245) GUICtrlSetResizing(-1,$GUI_DOCKLEFT) GUICtrlSetFont($notes,$size,$weight,$attribute,$fontname) ; Give Menu Items Options For $i = 0 To UBound($fonts) - 1 Local $_font = GUICtrlCreateMenuItem($fonts[$i],$font_menu) Next Local $_size[0] For $i = 10 To 20 ; Local $_size = GUICtrlCreateMenuItem($i,$size_menu) _ArrayAdd($_size, GUICtrlCreateMenuItem($i,$size_menu)) Next For $i = 400 To 1500 Step +100 Local $_weight = GUICtrlCreateMenuItem($i,$weight_menu) Next ; Fill drop down boxes with available hot keys $pw = GUICtrlCreateCombo("Select",80,5,75,15,$CBS_DROPDOWNLIST) GUICtrlSetResizing(-1,802) For $i = 0 To UBound($string) - 1 GuiCtrlSetData($pw,$string[$i]) Next $lsUsb = GUICtrlCreateCombo("Select",80,30,75,15,$CBS_DROPDOWNLIST) GUICtrlSetResizing(-1,802) For $i = 0 To UBound($string) - 1 GuiCtrlSetData($lsUsb,$string[$i]) Next $reboot = GUICtrlCreateCombo("Select",80,55,75,15,$CBS_DROPDOWNLIST) GUICtrlSetResizing(-1,802) For $i = 0 To UBound($string) - 1 GuiCtrlSetData($reboot,$string[$i]) Next $tail = GUICtrlCreateCombo("Select",80,80,75,15,$CBS_DROPDOWNLIST) GUICtrlSetResizing(-1,802) For $i = 0 To UBound($string) - 1 GuiCtrlSetData($tail,$string[$i]) Next $login = GUICtrlCreateCombo("Select",80,105,75,15,$CBS_DROPDOWNLIST) GUICtrlSetResizing(-1,802) For $i = 0 To UBound($string) - 1 GuiCtrlSetData($login,$string[$i]) Next $bill_acceptor = GUICtrlCreateCombo("Select",80,130,75,15,$CBS_DROPDOWNLIST) GUICtrlSetResizing(-1,802) For $i = 0 To UBound($string) - 1 GuiCtrlSetData($bill_acceptor,$string[$i]) Next If FileExists($path & $iniFile) Then ; Create and load saved settings If IniRead($path & $iniFile,"Hot Keys", "Password","") <> "" Then GuiCtrlSetData($pw,IniRead($path & $iniFile,"Hot Keys","Password","")) If iniRead($path & $iniFile, "Hot Keys", "lsusb","") <> "" Then GuiCtrlSetData($lsUsb,IniRead($path & $iniFile,"Hot Keys","lsusb","")) If iniRead($path & $iniFile, "Hot Keys", "Reboot","") <> "" Then GuiCtrlSetData($reboot,IniRead($path & $iniFile,"Hot Keys","Reboot","")) If iniRead($path & $iniFile, "Hot Keys", "Tail-f","") <> "" Then GuiCtrlSetData($tail,IniRead($path & $iniFile,"Hot Keys","Tail-f","")) If iniRead($path & $iniFile, "Hot Keys", "DVR Login","") <> "" Then GuiCtrlSetData($login,IniRead($path & $iniFile,"Hot Keys","DVR Login","")) If iniRead($path & $iniFile, "Hot Keys", "Bill Acceptor Script","") <> "" Then GuiCtrlSetData($bill_acceptor,IniRead($path & $iniFile,"Hot Keys","Bill Acceptor Script","")) Else IniWrite($path & $iniFile, "Hot Keys", "", "") IniWriteSection($path & $iniFile, "Hot Keys", $iniData) EndIf GUISetState(@SW_Show) While 1 ; The Main Loop If GUICtrlRead($pw) <> "Select" Then HotKeySet("{" & GUICtrlRead($pw) & "}", "PW") EndIf If GUICtrlRead($lsUsb) <> "Select" Then HotKeySet("{" & GUICtrlRead($lsUsb) & "}", "lsUsb") EndIf If GUICtrlRead($reboot) <> "Select" Then HotKeySet("{" & GUICtrlRead($reboot) & "}", "reboot") EndIf If GUICtrlRead($tail) <> "Select" Then HotKeySet("{" & GUICtrlRead($tail) & "}", "tail") EndIf If GUICtrlRead($login) <> "Select" Then HotKeySet("{" & GUICtrlRead($login) & "}", "Login") EndIf If GUICtrlRead($bill_acceptor) <> "Select" Then HotKeySet("{" & GUICtrlRead($bill_acceptor) & "}", "bill_acceptor") EndIf Switch GUIGetMsg() Case $GUI_Event_Close _Exit() Case $font_menu $fontname = $font_menu GUICtrlSetFont($notes,$size,$weight,$attribute,$fontname) Case $size_menu $size = $size_menu GUICtrlSetFont($notes,$size,$weight,$attribute,$fontname) Case $weight_menu $weight = $weight_menu GUICtrlSetFont($notes,$size,$weight,$attribute,$fontname) EndSwitch WEnd Edited September 26, 2014 by InunoTaishou Link to comment Share on other sites More sharing options...
Radiance Posted September 30, 2014 Share Posted September 30, 2014 I'm having a bit of trouble understanding what you basically want to do. You create a menu and based on which MenuItem you click, you want to change variables accordingly? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 30, 2014 Moderators Share Posted September 30, 2014 InunoTaishou,If you do not want to store the menuitem ControlIDs you can use dummy controls and the Switch - Case # To # construct like this: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $mFileMenu = GUICtrlCreateMenu("File") $mExit = GUICtrlCreateMenuItem("Exit", $mFileMenu) $mListMenu = GUICtrlCreateMenu("List") ; Get the ControlID of the first menuitem that will be cretaed in the list $cList_Start = GUICtrlCreateDummy() + 1 ; Now create the list For $i = 400 To 1500 Step 100 GUICtrlCreateMenuItem($i, $mListMenu) Next ; And then get the ControlId of the final item in the list $cList_End = GUICtrlCreateDummy() - 1 $mHelpMenu = GUICtrlCreateMenu("Help") $mHelp = GUICtrlCreateMenuItem("Help", $mHelpMenu) GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE, $mExit Exit Case $cList_Start To $cList_End ; Does the ControlID fall inside the list? $iValue = GUICtrlRead($iMsg, 1) ; Use the advanced parameter to get the text of the actioned menuitem MsgBox($MB_SYSTEMMODAL, "Selected", $iValue) ; And here it is Case $mHelp MsgBox($MB_SYSTEMMODAL, "Really?", "I thought it is obvious!") EndSwitch WEndThis depends on a little trick - controls created in immediate succession usually have consecutive ControlIDs. To be correct, you should save the returned ControlIDs (probably within an array) but as long as you have not deleted any controls prior to creating the menu, the above trick should work. 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...
InunoTaishou Posted September 30, 2014 Author Share Posted September 30, 2014 (edited) InunoTaishou,If you do not want to store the menuitem ControlIDs you can use dummy controls and the Switch - Case # To # construct like this: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $mFileMenu = GUICtrlCreateMenu("File") $mExit = GUICtrlCreateMenuItem("Exit", $mFileMenu) $mListMenu = GUICtrlCreateMenu("List") ; Get the ControlID of the first menuitem that will be cretaed in the list $cList_Start = GUICtrlCreateDummy() + 1 ; Now create the list For $i = 400 To 1500 Step 100 GUICtrlCreateMenuItem($i, $mListMenu) Next ; And then get the ControlId of the final item in the list $cList_End = GUICtrlCreateDummy() - 1 $mHelpMenu = GUICtrlCreateMenu("Help") $mHelp = GUICtrlCreateMenuItem("Help", $mHelpMenu) GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE, $mExit Exit Case $cList_Start To $cList_End ; Does the ControlID fall inside the list? $iValue = GUICtrlRead($iMsg, 1) ; Use the advanced parameter to get the text of the actioned menuitem MsgBox($MB_SYSTEMMODAL, "Selected", $iValue) ; And here it is Case $mHelp MsgBox($MB_SYSTEMMODAL, "Really?", "I thought it is obvious!") EndSwitch WEndThis depends on a little trick - controls created in immediate succession usually have consecutive ControlIDs. To be correct, you should save the returned ControlIDs (probably within an array) but as long as you have not deleted any controls prior to creating the menu, the above trick should work. M23You're a [...] genius.... I was thinking I was gonna have to create 90 variables and 90 cases for each variable lol.... Edited October 1, 2014 by Melba23 Profanity removed Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 1, 2014 Moderators Share Posted October 1, 2014 InunoTaishou,Delighted I could help - but please mind the language. 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...
spudw2k Posted October 1, 2014 Share Posted October 1, 2014 Neat trick! Thaks for sharing Melbs Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF 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