Jump to content

how to read guictrlcreatemenuitem


dirty
 Share

Recommended Posts

$FileMenu = GUICtrlCreateMenu ("&File")

$Open = GUICtrlCreateMenuItem ("Open",$FileMenu)

If there are more then 1 menu item, how to read one that was selected ? or how to use it as:

because each file opened is stored into this menu and by selecting one opened file or another from the drop down created by each entered item, nothing happens caz i dont know how to read it.

Link to comment
Share on other sites

  • Moderators

dirty,

Another canine-ingested Help file, I assume. :graduated:

GUICtrlRead ( controlID [, advanced] )

In 'advanced' mode the return value contains additional data of the control

Menu, MenuItem - The text of the control

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

Thanks i now learned how to use advanced parametes for guictrlread. thanks to u.

$FileMenu = GUICtrlCreateMenu ("&File")

$Recent = GUICtrlCreateMenu ("Recent Files", $FileMenu)

GUICtrlCreateMenuItem ("",$FileMenu)

GUICtrlCreateMenuItem has no variable assigned to it and is being created by openfiledialog, so how do i read it if it has no variable and there are many of them since i opened many files ?

Edited by dirty
Link to comment
Share on other sites

  • Moderators

dirty,

You can do it like this:

#include <GUIConstantsEx.au3>

; Create an array to hold the ControlIDs of the MenuItems
Global $aMenuItem[3]

$hGUI = GUICreate("Test", 500, 500)

; Create the menu
$mMenu = GUICtrlCreateMenu("File")
For $i = 0 To 2
    $aMenuItem[$i] = GUICtrlCreateMenuItem("Item " & $i, $mMenu)
Next

; Clicking this adds an item to the menu
$hButton = GUICtrlCreateButton("Add Menu Item", 10, 10, 80, 30)

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            ; Resize the array
            $iCount = UBound($aMenuItem)
            ReDim $aMenuItem[$iCount + 1]
            ; And add the new item ControlID
            $aMenuItem[$iCount] = GUICtrlCreateMenuItem("Item " & $iCount, $mMenu)
        Case Else
            ; Run through the array to see if we have a match
            For $i = 0 To UBound($aMenuItem) - 1
                If $iMsg = $aMenuItem[$i] Then
                    ; We do, so read the text of the menu item
                    $sText = GUICtrlRead($iMsg, 1)
                    ; And display it
                    ConsoleWrite($sText & @CRLF)
                    ; No point in looking any further
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd

As you can see, when you add an item to the menu you also add the ControlID to the array. ;)

All clear? :graduated:

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

:graduated: am lost.

Can you open my whole script and see how i can fix it to get this working ? your example does make enough since to me.

My other post with another issue with my script included is here

thanks for quick reply and a very detailed example

look into line 326 is where i try to read the value off if created menuitem in line 214

Edited by dirty
Link to comment
Share on other sites

  • Moderators

dirty,

Here is an untested version of your script using code similar to the example I posted above - look for the <<<<<<<<<<<< lines to see where I have changed it: :)

This :graduated:updowngraded editor is screwing up the AutoIt tags yet again so I have had to attach it as a file.

There are no syntax errors, but as I do not have any of your data I cannot really test it fully. Let me know when you have downloaded it and if it works. ;)

M23

P.S. You might want to look at using a Switch structure rather than all those If $GUIGETMSG...EndIf statements. And why are you using Assign to set values to variables - what is wrong with a simple = operator? ;)

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

dirty,

If you do run into difficulties understanding what I did and why, please ask so I can explain. :graduated:

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...