Sign in to follow this  
Followers 0
Rex

Read menu item when using opt. on event

10 posts in this topic

#1 ·  Posted (edited)

Should be simple, but i cant find any way to do it.

I have a menu with xx menu items, but i cant finde any way to get my GUI to react on a menu item

I know the var of this $Menu_SenderAccount_Choose = GUICtrlCreateMenu("A&fsender"), the menu items under this should then could be added by a menu, and then created as new items, by reding an ini file. (any way it my hope that i can do that)

But current my problem is that i don't know how get info from the menu, when using onevent mode, i did try to put $MSG = GuiGetMsg() in my while loop but nothing happens ;)

when using If $Msg = $Menu_SenderAccount_Choose then.

I have added my entire script, and yes i know it could be slimmed down by using arrayers and so, but i don't get it with those arrayers - so i wrote <500 lines with read things and so, and to make my main script easyer to overlook i did split it up in includes :evil:

I'm still learning how to use AutoIT to do what i'm trying to do :evil:

/Rex

Edit: File change

Edited by Rex

Share this post


Link to post
Share on other sites



Rex,

Posting a script of that size is NOT the way to get help (and you did not even include all the #include files!!). :evil: Next time, please just post a small reproducer. :evil:

If I understand what I read of your script, you want to know how to read which menu item has been selected within a submenu which has a random number of items while using OnEvent mode. The way I would do it is like this:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "On_Exit")

$mMain = GUICtrlCreateMenu("Main")
; Create a start point for the following ControlIDs
$mStart = GUICtrlCreateDummy()
; Create all the items in the submenu in this block with NO other controls intervening - they all call the same function
$mItem_1 = GUICtrlCreateMenuItem("Item 1", $mMain)
GUICtrlSetOnEvent(-1, "Menu_Pressed")
$mItem_2 = GUICtrlCreateMenuItem("Item 2", $mMain)
GUICtrlSetOnEvent(-1, "Menu_Pressed")

GUISetState()

While 1
    Sleep(10)
WEnd

Func Menu_Pressed()
    ; Determine the index of the item by subtracting the CID of the Dummy from the one which fired the function
    $iIndex = @GUI_CTRLID - $mStart
    MsgBox(0, "", "You pressed Item " & $iIndex)
EndFunc

Func On_Exit()
    Exit
EndFunc

Once you have the index, you should be able to identify what the item reads without too much problem, particularly if it is loaded from a ini file.

I hope this helps. ;)

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

Rex,

Posting a script of that size is NOT the way to get help (and you did not even include all the #include files!!). :) Next time, please just post a small reproducer. ;)

If I understand what I read of your script, you want to know how to read which menu item has been selected within a submenu which has a random number of items while using OnEvent mode. The way I would do it is like this:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "On_Exit")

$mMain = GUICtrlCreateMenu("Main")
; Create a start point for the following ControlIDs
$mStart = GUICtrlCreateDummy()
; Create all the items in the submenu in this block with NO other controls intervening - they all call the same function
$mItem_1 = GUICtrlCreateMenuItem("Item 1", $mMain)
GUICtrlSetOnEvent(-1, "Menu_Pressed")
$mItem_2 = GUICtrlCreateMenuItem("Item 2", $mMain)
GUICtrlSetOnEvent(-1, "Menu_Pressed")

GUISetState()

While 1
    Sleep(10)
WEnd

Func Menu_Pressed()
    ; Determine the index of the item by subtracting the CID of the Dummy from the one which fired the function
    $iIndex = @GUI_CTRLID - $mStart
    MsgBox(0, "", "You pressed Item " & $iIndex)
EndFunc

Func On_Exit()
    Exit
EndFunc

Once you have the index, you should be able to identify what the item reads without too much problem, particularly if it is loaded from a ini file.

I hope this helps. :idea:

M23

Hi Melba

Im sorry but i wasn't sure how to express what i wanned in English, my prim lang is danish and i had no idea on how to slim down my script to include only the menu part :evil:

that's why i attached my entire script, and the include that's not include is an empty au3 file - that u should know.. :evil: or maby not how could u :D i just didn't think that long when i packed the script's, course i knew that the file didn't do anything ;).

I will look at your sample and report back :o)

Cheers

/Rex

Share this post


Link to post
Share on other sites

I didn't look at the attached script either, because I'm allergic to downloads from people I don't know. Coded a demo using an array that simulates what you get from IniReadSection(). Since that returns a 2D array, I just took advantage of it to keep both the menu item control IDs and their texts:

#include <GUIConstantsEx.au3>

Opt("GuiOnEventMode", 1)

; Array of menu items, as would be read using IniReadSection($sFile, "MenuItems") if the file was:
;
;  [MenuItems]
;  Item=Dis
;  Item=Dat
;  Item=De ott'r Thang
;
;  "Item" gets replaced with the control ID
Global $aMenuItems[4][2] = [[3, ""], ["Item", "Dis"], ["Item", "Dat"], ["Item", "De ott'r Thang"] ]

Global $hGUI = GUICreate("Menu Event Mode", 300, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$aMenuItems[0][0] = GUICtrlCreateMenu("AutoIt Menu")
For $n = 1 To UBound($aMenuItems) - 1
    $aMenuItems[$n][0] = GUICtrlCreateMenuItem($aMenuItems[$n][1], $aMenuItems[0][0])
    GUICtrlSetOnEvent(-1, "_MenuItemHit")
Next
GUISetState()

While 1
    Sleep(10)
WEnd

Func _MenuItemHit()
    Local $ctrlMenu = @GUI_CtrlId
    Local $hMenu = @GUI_CtrlHandle
    Local $iIndex, $sText
    For $iIndex = 1 To UBound($aMenuItems) - 1
        If $aMenuItems[$iIndex][0] = $ctrlMenu Then
            $sText = $aMenuItems[$iIndex][1]
            ExitLoop
        EndIf
        If $sText = "" Then $sText = "<Not Found>"
    Next
    ConsoleWrite("_MenuItemHit():  ID = " & $ctrlMenu & "; Handle = " & $hMenu & "; Text = " & $sText & @LF)
EndFunc

Func _Quit()
    Exit
EndFunc

@Rex: You've been here way too long to be whining about learning arrays. Get over the learning curve already!

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I didn't look at the attached script either, because I'm allergic to downloads from people I don't know. Coded a demo using an array that simulates what you get from IniReadSection(). Since that returns a 2D array, I just took advantage of it to keep both the menu item control IDs and their texts:

#include <GUIConstantsEx.au3>

Opt("GuiOnEventMode", 1)

; Array of menu items, as would be read using IniReadSection($sFile, "MenuItems") if the file was:
;
;  [MenuItems]
;  Item=Dis
;  Item=Dat
;  Item=De ott'r Thang
;
;  "Item" gets replaced with the control ID
Global $aMenuItems[4][2] = [[3, ""], ["Item", "Dis"], ["Item", "Dat"], ["Item", "De ott'r Thang"] ]

Global $hGUI = GUICreate("Menu Event Mode", 300, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$aMenuItems[0][0] = GUICtrlCreateMenu("AutoIt Menu")
For $n = 1 To UBound($aMenuItems) - 1
    $aMenuItems[$n][0] = GUICtrlCreateMenuItem($aMenuItems[$n][1], $aMenuItems[0][0])
    GUICtrlSetOnEvent(-1, "_MenuItemHit")
Next
GUISetState()

While 1
    Sleep(10)
WEnd

Func _MenuItemHit()
    Local $ctrlMenu = @GUI_CtrlId
    Local $hMenu = @GUI_CtrlHandle
    Local $iIndex, $sText
    For $iIndex = 1 To UBound($aMenuItems) - 1
        If $aMenuItems[$iIndex][0] = $ctrlMenu Then
            $sText = $aMenuItems[$iIndex][1]
            ExitLoop
        EndIf
        If $sText = "" Then $sText = "<Not Found>"
    Next
    ConsoleWrite("_MenuItemHit():  ID = " & $ctrlMenu & "; Handle = " & $hMenu & "; Text = " & $sText & @LF)
EndFunc

Func _Quit()
    Exit
EndFunc

@Rex: You've been here way too long to be whining about learning arrays. Get over the learning curve already!

;)

Hi PsaltyDS

I know that i should know how to make arrays, but as of my prim. lang is danish and all AutoIT is in english and most of it in tech english, and that good is my english not - but i keep trying and trying, and every time i see an sample i try to lern how it's done so i one day can do it my self.

And trust me if i knew arrays i didn't need to create a 250 line long read controles file :evil: i would just have done a $read[$I1] thing insted, but i'm an :) to learn things like that.

For the past 1½ year i have tryed to learn css and divs, ind i still don't get it :idea:

But you're right i shouldn't whine over it..

Thx for the sample, i hope that i learn a bit more with it too :evil:

Cheers

/Rex

Share this post


Link to post
Share on other sites

...but as of my prim. lang is danish and all AutoIT is in english and most of it in tech english, and that good is my english not...

You know about half the MVPs and some of the Devs on this site are not native English-speakers, right? Including some native Dutch, German, and probably Danish...

<2009-12-14 17:00:00GMT ERROR! WEAK EXCUSE REJECTED!>

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You know about half the MVPs and some of the Devs on this site are not native English-speakers, right? Including some native Dutch, German, and probably Danish...

<2009-12-14 17:00:00GMT ERROR! WEAK EXCUSE REJECTED!>

;)

I'm shure that you'r right, but maby i dont understandt the english language as good as they?? i don't know, maby i'm just a slow learner...

But any way i should had learned the arrays now, but i haven't :evil:

But i still try to learn, and i still consult the help text before asking help at the forum, i do the best that i can, and that somthing :evil:)

Cheers

/Rex

Share this post


Link to post
Share on other sites

You could try the tutorial for arrays on the wiki, it's quite good (atleast if you can understand it :evil:)

Hi Admiral

I have read the wiki 4 times, and still don't get it :evil: but thx for the link ;)

Cheers

/Rex

Share this post


Link to post
Share on other sites

Hi Admiral

I have read the wiki 4 times, and still don't get it :evil: but thx for the link ;)

Cheers

/Rex

So ask a question! What's the first part of it that doesn't make sense to you?

Ever make a grocery list for shopping? That's a one dimensional array (numbered from 0):

0 - Milk

1 - Bread

2 - Eggs

3 - Sugar

4 - Tea

In AutoIt that looks like this:

#include <Array.au3>

Global $aArray[5] = ["Milk", "Bread", "Eggs", "Sugar", "Tea"]
_ArrayDisplay($aArray, "1D Array")

What if you add another column for the quantity to buy? Now you have a two dimensional array!

#include <Array.au3>

Global $aArray[5][2] = [["Milk", "2 Liters"], ["Bread", "1 loaf"], ["Eggs", "1 Dozen"], ["Sugar", "2 Kg"], ["Tea", "1 Box"]]
_ArrayDisplay($aArray, "2D Array")

Just because it's unfamiliar doesn't have to make it hard.

:evil:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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