Sign in to follow this  
Followers 0
R4ytj3

Help with loading a GUIMenu from a other file.

5 posts in this topic

#1 ·  Posted (edited)

Hello,

I have some trouble with loading a menu from a other file.

My menu is getting pretty big and a couple of .exe files have they same menu, but it using a lot of space, so i thought it would be easier if i could put the menu in a seperated file.

I saw the _GUICtrlMenu_LoadMenu in the help file, but i can't get it to work.

Can someone help me. If you need more info, just let me know :D

Greetz

R4ytj3

Edited by R4ytj3

Share this post


Link to post
Share on other sites



Hello,

I have some trouble with loading a menu from a other file.

My menu is getting pretty big and a couple of .exe files have they same menu, but it using a lot of space, so i thought it would be easier if i could put the menu in a seperated file.

I saw the _GUICtrlMenu_LoadMenu in the help file, but i can't get it to work.

Can someone help me. If you need more info, just let me know :D

Greetz

R4ytj3

Welcome to AutoIt forums :D

I don't know how to use _GUICtrlMenu_LoadMenu, but my first approach would be to use an ini file. I think it would be a lot easier assuming that you write the exe's. Is that something you have considered?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Welcome to AutoIt forums :D

I don't know how to use _GUICtrlMenu_LoadMenu, but my first approach would be to use an ini file. I think it would be a lot easier assuming that you write the exe's. Is that something you have considered?

First i want to say thanks, for the welcome and your answer.

Normally i don't use a menu. So no i don't know how to use a .ini for a menu.

And yes i'm considering it now :D hehe

Share this post


Link to post
Share on other sites

First i want to say thanks, for the welcome and your answer.

Normally i don't use a menu. So no i don't know how to use a .ini for a menu.

And yes i'm considering it now :D hehe

Well here's an example. I thought it would be easy but I had to think about it. I have used OnEvent mode because I seemed the simplest way to do it.

First here's the example script

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

GUICreate("My GUI"); will create a dialog box that when displayed is centered
$var = IniReadSection("menu.ini", "menu")
If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    Createmenus($var)
EndIf

GUISetState(@SW_SHOW); will display an empty dialog box
GUISetOnEvent($GUI_EVENT_CLOSE,"quitit")

; Run the GUI until the dialog is closed
While 1
    Sleep(30)
WEnd
GUIDelete()


Func Createmenus($smen)
    If Not IsArray($smen) Then Return 0
    If $smen[0][0] = 0 Then Return 0
    Local $menusTitles[$smen[0][0]]
    Local $n, $p, $mlist
    Local $menu
    For $n = 1 To $smen[0][0] 
        $menusTitles[$n-1] = GUICtrlCreateMenu($smen[$n][0])
        $mlist = StringSplit($smen[$n][1], "|")
        For $p = 1 To $mlist[0]
            $mfn = StringSplit($mlist[$p], ",")
            GUICtrlCreateMenuItem($mfn[1], $menustitles[$n-1])
            GUICtrlSetOnEvent(-1, $mfn[2])
        Next
    Next
    
    Return $menusTitles;haven't actually used this, seemed like a good idea at the time.
    
    
EndFunc  ;==>Createmenus

#cs
    File = Open,startnew|Exit,quitit
    Help=Help,ShowHelp|version,MyAbout
#ce
Func startnew()
    MsgBox(0, 'menu selected', 'Open')
EndFunc  ;==>startnew

Func Showhelp()
    MsgBox(0, 'menu selected', 'Help')
EndFunc  ;==>Showhelp

Func MyAbout()
    MsgBox(0, 'menu selected', 'Version')
EndFunc  ;==>ShowHelp

Func quitit()
;MsgBox(0, 'menu selected', 'Exit')
    Exit
EndFunc  ;==>quitit

then heres the ini file it uses for the information on menus. Save it in the same folder as the script with the name "menu.ini"

[Menu]
File = Open,startnew|Exit,quitit
Help=Help,ShowHelp|version,MyAbout

The ini allows you to define a list of menus and the list of menuitems. Each menu item has the function name it uses.

Since this was just done to show the idea I don't pretend this is a fully developed idea, and it would be easy to make it go wrong but it works and shows how you could build a menu from a text file.

It's only useful I expect when you have more than one script which needs to have the same menu structure, or at least some common menu structures.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks a lot for the help, didn't really understand your script but i made my own based on yours :D.

Now i only have to figure out how to get 2 submenu's in 1 menu hehe.

Thanks :D

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