Jump to content

Cannot get menu text


Recommended Posts

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

  • Moderators

georgegalily,

Welcome to the AutoIt forums.

I would do it this way:

#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

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...