Sign in to follow this  
Followers 0
InunoTaishou

Changing Variables from items clicked in Menus

6 posts in this topic

#1 ·  Posted (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)

#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 by InunoTaishou

Share this post


Link to post
Share on other sites



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?

Share this post


Link to post
Share on other sites

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
WEnd
This 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._______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

#4 ·  Posted (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
WEnd
This 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

You're a [...] genius.... I was thinking I was gonna have to create 90 variables and 90 cases for each variable lol.... Edited by Melba23
Profanity removed

Share this post


Link to post
Share on other sites

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._______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
Sign in to follow this  
Followers 0