knight666 Posted March 13, 2008 Share Posted March 13, 2008 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 More sharing options...
evilertoaster Posted March 13, 2008 Share Posted March 13, 2008 Code would be helpfull. Within the called function you should be able to get the clicked controls handle with @GUI_CtrlHandle so it's hard to say exactly whats wrong in your situation without seeing what you have already. Link to comment Share on other sites More sharing options...
knight666 Posted March 13, 2008 Author Share Posted March 13, 2008 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 More sharing options...
Moderators SmOke_N Posted March 13, 2008 Moderators Share Posted March 13, 2008 $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 More sharing options...
knight666 Posted March 13, 2008 Author Share Posted March 13, 2008 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? < Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 13, 2008 Moderators Share Posted March 13, 2008 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 More sharing options...
Moderators SmOke_N Posted March 13, 2008 Moderators Share Posted March 13, 2008 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 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