Rex Posted December 14, 2009 Share Posted December 14, 2009 (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 I'm still learning how to use AutoIT to do what i'm trying to do /Rex Edit: File change Edited December 14, 2009 by Rex Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 14, 2009 Moderators Share Posted December 14, 2009 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 EndFuncOnce 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 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...
Rex Posted December 14, 2009 Author Share Posted December 14, 2009 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. 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 that's why i attached my entire script, and the include that's not include is an empty au3 file - that u should know.. or maby not how could u 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 ) Cheers /Rex Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 14, 2009 Share Posted December 14, 2009 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: expandcollapse popup#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 Link to comment Share on other sites More sharing options...
Rex Posted December 14, 2009 Author Share Posted December 14, 2009 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: expandcollapse popup#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 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 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 Cheers /Rex Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 14, 2009 Share Posted December 14, 2009 ...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 Link to comment Share on other sites More sharing options...
Rex Posted December 14, 2009 Author Share Posted December 14, 2009 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 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 )Cheers/Rex Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted December 14, 2009 Share Posted December 14, 2009 You could try the tutorial for arrays on the wiki, it's quite good (atleast if you can understand it ) .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Rex Posted December 15, 2009 Author Share Posted December 15, 2009 You could try the tutorial for arrays on the wiki, it's quite good (atleast if you can understand it )Hi AdmiralI have read the wiki 4 times, and still don't get it but thx for the link Cheers/Rex Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 15, 2009 Share Posted December 15, 2009 Hi Admiral I have read the wiki 4 times, and still don't get it 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. 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 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