georgegalily Posted November 21, 2016 Share Posted November 21, 2016 Hi every body, I designed a program that store setting in an INI file for example recent files are stored in recent files section to be recalled, but when I click the sub menu from menue caannot get the name. I used several methods around but hopless. INI file attached and This is the script: #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> creategui() Do $idMsg = GUIGetMsg() $FIRE=GUIGetCursorInfo () If $FIRE[2] <> 0 Then Local $sMenutext = GUICtrlRead($FIRE[4], $GUI_READ_EXTENDED) ; return the text of the menu item MsgBox($MB_SYSTEMMODAL, "Text of the menuitem", "Text:" & $sMenutext) $idMsg = 0 EndIf Until $idMsg = $GUI_EVENT_CLOSE Func creategui() GUICreate("MenuFileMAIN", 100, 100) Global $idFileMenu = GUICtrlCreateMenu("FILE") Global $idFileMenuRECENT = GUICtrlCreateMenu("RECENT_FILES", $idFileMenu) $sFilePath = @ScriptDir & "\MYFILES\SETFILES.INI" ;PATH TO SETTING FILE INI Local $aArray = IniReadSectionNames($sFilePath) Local $keyy If Not @error Then ; Enumerate through the array displaying the KEY(RECENT_FILES) names. For $i = 1 To 10 $keyy = IniRead($sFilePath, "RECENT_FILES", $i, "") Local $idRecentFilesMenu = GUICtrlCreateMenuItem($keyy, $idFileMenuRECENT) If IniRead($sFilePath, "RECENT_FILES", $i + 1, "") = "" Then ExitLoop Next Local $GUI_EVENT_CLOSE = GUICtrlCreateMenuItem("close", $idFileMenu) GUISetState(@SW_SHOW) EndIf EndFunc ;==>createallgui This is the contents of ini file: [RECENT_FILES] 1=C:\111\MYFILES\1.TXT 2=C:\111\MYFILES\2.TXT 3=C:\111\MYFILES\3.TXT 4=C:\111\MYFILES\4.TXT 5=C:\111\MYFILES\5.TXT 6= 7= 8= 9= 10= Thanx very much for help. SETFILES.INI Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 21, 2016 Moderators Share Posted November 21, 2016 georgegalily, Welcome to the AutoIt forums. I would do it this way: expandcollapse popup#include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global $aSubMenuCID[11] creategui() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case 0 ; Do nothing Case Else For $i = 1 To 10 If $aSubMenuCID[$i] = $nMsg Then MsgBox($MB_SYSTEMMODAL, "Text of the menuitem", "Text: " & GUICtrlRead($nMsg, 1)) ExitLoop EndIf Next EndSwitch WEnd Func creategui() Local $keyy GUICreate("MenuFileMAIN", 100, 100) $idFileMenu = GUICtrlCreateMenu("FILE") $idFileMenuRECENT = GUICtrlCreateMenu("RECENT_FILES", $idFileMenu) $sFilePath = @ScriptDir & "\MYFILES\SETFILES.INI" ;PATH TO SETTING FILE INI ;Local $aArray = IniReadSectionNames($sFilePath) If Not @error Then ; Enumerate through the array displaying the KEY(RECENT_FILES) names. For $i = 1 To 10 $keyy = "File " & $i ; IniRead($sFilePath, "RECENT_FILES", $i, "") $aSubMenuCID[$i] = GUICtrlCreateMenuItem($keyy, $idFileMenuRECENT) ;If IniRead($sFilePath, "RECENT_FILES", $i + 1, "") = "" Then ExitLoop Next Local $GUI_EVENT_CLOSE = GUICtrlCreateMenuItem("close", $idFileMenu) GUISetState(@SW_SHOW) EndIf EndFunc ;==>creategui You will need to reactivate the ini file lines - I changed them just for testing. Please ask if you have any questions. M23 georgegalily 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...
georgegalily Posted November 21, 2016 Author Share Posted November 21, 2016 I'm so "greatly appreciated," for the excellent reply, I modified it to my ini and it worked like charm. But I have llittle equastion why to but "1" in this: GUICtrlRead($nMsg, 1) I read the help theres only extended events not numbers. Thnk you so much again Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 21, 2016 Moderators Share Posted November 21, 2016 georgegalily, You are quite right, I should have used the $GUI_READ_EXTENDED constant rather then a magic number - but old habits die hard when coding a small snippet! And as you can see from the Help file, we do give the magic number equivalent for the 2 constants: advanced : [optional] returns extended information of a control. $GUI_READ_DEFAULT (0) = (Default) Returns a value with state or data of a control. $GUI_READ_EXTENDED (1) = Returns extended information of a control (see Remarks). Constants are defined in GUIConstantsEx.au3. I will try and do better in future, promise. And if guinness is reading: mea maxima culpa! 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...
georgegalily Posted November 21, 2016 Author Share Posted November 21, 2016 Oh this is great hint(remark), You saved my day. Thanx much. 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