Jump to content

How to use dynamic menu?


Recommended Posts

Hello, how I can use dynamic menu? I create meny by reading elements from file, but how I bind action for every menu item?

I am used to bind action like this

Case $MenuItem1
 Code()

but if i create menu dynamically then I cant use it like that.

Also I have 2 static menus. I want make my code so that both dynamic and static menus would work.

Any ideas/suggestions?

Edit: Can I use array some how? Will it help?

Thanks

Edited by E1M1

edited

Link to comment
Share on other sites

For controls, place your dynamically-created control handles in an array an then use $MyControls[23] to refer to the 24-th element created, for instance. Of course you have to organize indexes rigorously to avoid getting lost about where that checkbox handle has been stored.

But how can you create more than one menu is a bit beyond me.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I don't get it. If you create elements yourself, you know how many you create!

Do you have simple example code of what you're doing?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

$Edit = GUICtrlCreateMenu("Edit")
$EditSettings = GUICtrlCreateMenu("Settings",$Edit)
$EditSettingSettings = GUICtrlCreateMenuItem('Settings', $EditSettings)
$EditSettingSequence= GUICtrlCreateMenuItem('Sequence', $EditSettings)
$EditBosses = GUICtrlCreateMenu("Bosses",$Edit)
$EditBuilds = GUICtrlCreateMenu("Builds",$Edit)
$builds = _FileListToArray($BuildsDir,"*.lua",1)
for $i = 1 To $builds[0]
    GUICtrlCreateMenuItem($builds[$i],$EditBuilds)
Next
$bosses = _FileListToArray($bossDir,"*.lua",1)
for $i = 1 To $bosses[0]
    GUICtrlCreateMenuItem($bosses[$i],$EditBosses)
Next

edited

Link to comment
Share on other sites

$Edit = GUICtrlCreateMenu("Edit")
$EditSettings = GUICtrlCreateMenu("Settings",$Edit)
$EditSettingSettings = GUICtrlCreateMenuItem('Settings', $EditSettings)
$EditSettingSequence= GUICtrlCreateMenuItem('Sequence', $EditSettings)
$EditBosses = GUICtrlCreateMenu("Bosses",$Edit)
$EditBuilds = GUICtrlCreateMenu("Builds",$Edit)
$builds = _FileListToArray($BuildsDir,"*.lua",1)
for $i = 1 To $builds[0]
    GUICtrlCreateMenuItem($builds[$i],$EditBuilds)
Next
$bosses = _FileListToArray($bossDir,"*.lua",1)
for $i = 1 To $bosses[0]
    GUICtrlCreateMenuItem($bosses[$i],$EditBosses)
Next

I think jchd was suggesting something like this.

$Edit = GUICtrlCreateMenu("Edit")
$EditSettings = GUICtrlCreateMenu("Settings",$Edit)
$EditSettingSettings = GUICtrlCreateMenuItem('Settings', $EditSettings)
$EditSettingSequence= GUICtrlCreateMenuItem('Sequence', $EditSettings)
$EditBosses = GUICtrlCreateMenu("Bosses",$Edit)
$EditBuilds = GUICtrlCreateMenu("Builds",$Edit)
$builds = _FileListToArray($BuildsDir,"*.lua",1)
Global $BuilMenuItems[$builds[0]],$BossesMenuItems[$bosses[0]]
for $i = 1 To $builds[0]
    $BuilMenuItems[$i - 1] = GUICtrlCreateMenuItem($builds[$i],$EditBuilds)
Next
$bosses = _FileListToArray($bossDir,"*.lua",1)
for $i = 1 To $bosses[0]
    $BossesMenuItems[$i - 1] = GUICtrlCreateMenuItem($bosses[$i],$EditBosses)
Next
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.
Link to comment
Share on other sites

Here's a way:

#include <GUIConstantsEx.au3>

GUICreate("Menu test", 800, 600, 200, 200)
Local $Edit = GUICtrlCreateMenu("Edit")
Local $EditSettings = GUICtrlCreateMenu("Settings", $Edit)
Local $EditSettingSettings = GUICtrlCreateMenuItem('Settings', $EditSettings)
Local $EditSettingSequence= GUICtrlCreateMenuItem('Sequence', $EditSettings)
Local $EditBosses = GUICtrlCreateMenu("Bosses", $Edit)
Local $EditBuilds = GUICtrlCreateMenu("Builds", $Edit)
GUISetState()

Local $builds = _FileListToArray(@ScriptDir, "*.au3", 1)
Local $buildsHdl[$builds[0] + 1]
For $i = 1 To $builds[0]
    $buildsHdl[$i] = GUICtrlCreateMenuItem($builds[$i], $EditBuilds)
Next
Local $bosses = _FileListToArray(@ScriptDir & '\..\include', "*.au3", 1)
Local $bossesHdl[$bosses[0] + 1]
For $i = 1 To $bosses[0]
    $bossesHdl[$i] = GUICtrlCreateMenuItem($bosses[$i], $EditBosses)
Next

Local $msg

While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then
        Exit
    Else
        Local $n = _ArraySearch($buildsHdl, $msg, 1)
        If $n > 0 Then
            MsgBox(0, "Tracking menu items", "You selected " & $Builds[$n])
        Else
            $n = _ArraySearch($bossesHdl, $msg, 1)
            If $n > 0 Then
                MsgBox(0, "Tracking menu items", "You selected " & $bosses[$n])
            EndIf
        EndIf
    EndIf
WEnd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

great thanks. for showing I did it a bit other way but...

..
..
..$EditBosses = GUICtrlCreateMenu("Bosses",$Edit)
$EditBuilds = GUICtrlCreateMenu("Builds",$Edit)
$builds = _FileListToArray($BuildsDir,"*.lua",1)
for $i = 1 To $builds[0]
    GUICtrlCreateMenuItem($builds[$i],$EditBuilds)
Next
$bosses = _FileListToArray($bossDir,"*.lua",1)
for $i = 1 To $bosses[0]
    GUICtrlCreateMenuItem($bosses[$i],$EditBosses)
Next

dim $newarray[$builds[0]+$bosses[0]]
for $i = 0 To $builds[0] -1
    $newarray[$i] = $builds[$i+1]
next
for $i = $builds[0]+1 To ($builds[0]+$bosses[0])
    $newarray[$i-1] = $bosses[($i-$builds[0])]
next
..
..
..

..
..
..      Case $FurnaceOfPain
            Chat('FurnaceOfPain', 1)
        Case $ubertristram
            Chat('UberTristram', 1)
    EndSwitch
    If $msg <> 0 and $msg <> -11 and $msg <> -8 Then
    MsgBox(0,$msg,$newarray[$msg-287]); I have 287 static elements
    EndIf
Edited by E1M1

edited

Link to comment
Share on other sites

You got the idea. Now as you say, you arrange storage/retrieval the way that fits the application best. As long as you can access control IDs coveniently and link them to your dynamic items, you have much room for creativity.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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