Sign in to follow this  
Followers 0
waardd

variable numer of menu items to case

6 posts in this topic

This code generates a menuitem with entrys, but also a combobox.

My question is how to set the case statement to match the menuitems...

$RunKiezer = GUICtrlCreateCombo("", 10, 265, 125) ; create first item
Local $FileList=_FileListToArray("C:\home\links\","*", 1)
Local $cData = ""
For $i = 1 To Ubound($FileList)-1
;create automatic menu
$filelist[$i] = GUICtrlCreateMenuItem(StringLeft($filelist[$i],(StringLen($fileList[$i])-4)), $Links)
 
$cData &= "|" & StringLeft($filelist[$i],(StringLen($fileList[$i])-4))
Next
GUICtrlSetData($RunKiezer, $cData)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Switch
    Case $filelist[0] To $filelist[UBound($filelist) - 1]
        ; do stuff
EndSwitch

EDIT:

Hold on, there was more..

EDIT:

Here we go.

Global $hMenuItems[10]

Global $hWnd = GUICreate("Test")
Global $hMenu = GUICtrlCreateMenu("Test")

For $i = 0 To UBound($hMenuItems) - 1
    $hMenuItems[$i] = GUICtrlCreateMenuItem("Item #" & $i, $hMenu)
Next

GUISetState()
While 1
    $iMsg = GUIGetMsg()

    Switch $iMsg
        Case -3
            Exit

        Case $hMenuItems[0] To $hMenuItems[UBound($hMenuItems) - 1]
            For $i = 0 To UBound($hMenuItems) - 1
                If ($iMsg == $hMenuItems[$i]) Then
                    MsgBox(0, "", "Item #" & $i & " pressed.")
                EndIf
            Next

    EndSwitch
WEnd
Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

This is a simple way of doing it.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <File.au3>
local $hGUI = GUICreate("GUI", 640, 580, -1, -1, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX))
$RunKiezer = GUICtrlCreateCombo("", 10, 265, 125) ; create first item
Local $FileList =_FileListToArray("A:UsersSanjaiDesktopSetup Fusion","*", 1)
Local $cData = ""
$Links = GUICtrlCreateMenu("Links")
For $i = 1 To Ubound($FileList)-1
;create automatic menu
$filelist[$i] = GUICtrlCreateMenuItem(StringLeft($filelist[$i],(StringLen($fileList[$i])-4)), $Links)
$cData &= "|" & StringLeft($filelist[$i],(StringLen($fileList[$i])-4))
Next
GUICtrlSetData($RunKiezer, $cData)
GUISetState() ;Show GUI
While 1
$Msg = GUIGetMsg()
   Switch $Msg
   Case $GUI_EVENT_CLOSE
   ConsoleWrite("close?"&@lf)
   ExitLoop
   Case Else
   For $iX = 0 To $filelist[0]-1
   If $Msg = $FileList[$iX] Then
    MsgBox(0,"Clicked","Menu Item Control Id:"&$FileList[$iX])
   EndIf
   Next
   EndSwitch
WEnd
GUIDelete($hGUI)
Exit

Share this post


Link to post
Share on other sites

@AlmarM

Your creation works that the message says "item x" is pressed, but after the selection the corresponding item must be run and then it says that it can not run c:<dir><dir>x where x is a number. For insatnce Item 1 relates to 56 so it tries to run c:homelinks65

Share this post


Link to post
Share on other sites

I'm having a little bit trouble understanding what you mean.

Are you looking for ShellExecute ?


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

No sorry... i found my error.

Because of the double use of the array, the array was filled the second time with numbers. Therefor my run command did not work.

I solved it by creating a second array and now it works perfect.

Tnx for all your help.

Global $linkList=_FileListToArray("C:homelinks","*", 1)
Global $linkitems=_FileListToArray("C:homelinks","*", 1)
For $i = 1 To Ubound($linklist)-1
$linklist[$i] = GUICtrlCreateMenuItem(StringLeft($linklist[$i],(StringLen($linkList[$i])-4)), $Links,$i)
Next
Case $linklist[0] To $linklist[UBound($linklist) - 1]
    For $i = 0 To UBound($linklist) - 1
    If ($nMsg == $linklist[$i]) Then
        TrayTip("Link","Toepassing wordt gestart.",2)
    ShellExecute("C:homelinks" & $linkitems[$i])
    EndIf
    Next

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