Jump to content

Determine which menuitem activated a function


Recommended Posts

Hi,

I made a nice context menu, which is working quite nice.

But because it's tied to an array, it needs to "know" what option the user clicked to execute the function.

There's a function called "EditStuff()" and it's supposed to be tied to all the context menu's in the array $mnuMoving, which stores all the context menu's. $mnuOptionDown is also an array and is calling the function in question.

How can I determine which $mnuOptionDown activated the link?

@GUI_CtrlId gives me a pretty useless number (94, 114, 124, etc) and @GUI_CtrlHandle gives "0x00000000".

Please help. :)

Link to comment
Share on other sites

Well here's the code I'm using (parts of it anyway):

;part of the gui creation
   $file = FileOpen("sitelist.txt",0)
   While 1+1=2
      $line = FileReadLine($file)
      If @error = -1 Then ExitLoop
      If StringInStr($line,"[Site]") > 0 Then
         $sitename = StringReplace($line,"[Site]","")
         $globItem[$t] = GUICtrlCreateListViewItem($sitename & "|0|0",$lstData)
         $globSiteList[$t] = GUICtrlCreateTreeViewItem($sitename,$treeLinks)
            $mnuMoving[$t] = GUICtrlCreateContextMenu($globSiteList[$t])
               $mnuOptionUp = GUICtrlCreateMenuItem("Move up",$mnuMoving[$t])
               $mnuOptionDown[$t] = GUICtrlCreateMenuItem("Move down",$mnuMoving[$t])
                  GUICtrlSetOnEvent(-1,"MoveDown")
               GUICtrlCreateMenuItem("",$mnuMoving[$t])
               GUICtrlCreateMenuItem("Edit user",$mnuMoving[$t])
                  GUICtrlSetOnEvent(-1,"EditStuff")
               GUICtrlCreateMenuItem("Edit password",$mnuMoving[$t])
               GUICtrlCreateMenuItem("Edit name",$mnuMoving[$t])
               GUICtrlCreateMenuItem("Edit link",$mnuMoving[$t])
        ;_GUICtrlTreeView_SetDropTarget($treeLinks,$globSiteList[$t],True)
         $t += 1
      EndIf
   Wend
   FileClose($file)

;the function in question
Func EditStuff()
MsgBox(0,$globTitle,@GUI_CtrlHandle & " - " & @GUI_CtrlId)
EndFunc
Link to comment
Share on other sites

  • Moderators

$var = GUICtrlCreateMenuItem

If $msg = $var Then

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Well uhm...

$mnuOptionEdit[$t] = GUICtrlCreateMenuItem("Edit user",$mnuMoving[$t])
   GUICtrlSetOnEvent(-1,"EditStuff")

There's no handler or ID assigned to the variable, so how do I check for it? <:)

Why don't you provide a small working GUI so we can show you...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Better yet:

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

Global $hWnd, $hMenu, $aMenuOne[3]
$hWnd = GUICreate("Example")
$hMenu = GUICtrlCreateMenu("Example")
$aMenuOne[1] = GUICtrlCreateMenuItem("In Menu 1", $hMenu)
$aMenuOne[2] = GUICtrlCreateMenuItem("In Menu 2", $hMenu)

;~ Events
GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitFunc")
GUICtrlSetOnEvent($aMenuOne[1], "_EventHandler")
GUICtrlSetOnEvent($aMenuOne[2], "_EventHandler")
;~
GUISetState()

While 1
    Sleep(100000)
WEnd

Func _ExitFunc()
    Exit 1
EndFunc

Func _EventHandler()
    Switch @GUI_CtrlId
        Case $aMenuOne[1]
            MsgBox(64, "Info", "You clicked Menu 1")
        Case $aMenuOne[2]
            MsgBox(64, "Info", "You clicked Menu 2")
    EndSwitch
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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