fiveofoh Posted August 31, 2007 Share Posted August 31, 2007 I'm trying to simply create a script that will show a popup menu on startup, and exit (after doing the appropriate action) when the user clicks on an item, but the menu items don't seem to be responding to clicks - my popup menu just goes away (because it was clicked), without the functions being called. I had an Exit at the end of both functions, but took them out for testing. Here's my code: expandcollapse popup#include <GUIConstants.au3> Opt("GUIOnEventMode", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "DoExit") $mousepos = MouseGetPos() $mygui = GUICreate("My GUI Context Menu", 0, 0, $mousepos[0], $mousepos[1], $WS_POPUP) $contextmenu = GUICtrlCreateContextMenu () If($CmdLine[0] > 0) Then $filename = $CmdLine[1] Else $filename = "menu.ini" EndIf $seclist = IniReadSection($filename, "Menu") $seclength = $seclist[0][0] MsgBox(0, "Test", $seclength) Dim $menuarray[$seclength+1] $menuarray[0] = $seclist[0][0] For $i = 1 to ubound($seclist) - 1 MsgBox(0, "Menu Item", $seclist[$i][0] & "|" & $seclist[$i][1]) MsgBox(0, "Test", $i) $menuid = GUICtrlCreateMenuItem ($seclist[$i][0], $contextmenu) $menuarray[$i] = $menuid GUICtrlSetOnEvent($menuid,"RunProg") Next GUICtrlCreateMenuitem ("", $contextmenu) ; separator $cancelitem = GUICtrlCreateMenuitem ("Cancel", $contextmenu) GUICtrlSetOnEvent ($cancelitem,"DoExit") GUISetState(@SW_SHOW) ShowMenu($mygui, $mousepos[0], $mousepos[1], $contextmenu) While 1 Sleep(100) WEnd Func DoExit() MsgBox (0, "yay!", "wooo!") EndFunc Func RunProg() $menuitem = @GUI_CTRLID MsgBox(0, "Menu Item", $menuitem) $menunum = $menuitem - $menuarray[1] + 1 MsgBox(0, "Run", $seclist[$menunum[1]]) MsgBox(0, "Menunum", $menunum) Run($seclist[$menunum][1]) EndFunc ; Show a menu in a given GUI window which belongs to a given GUI ctrl Func ShowMenu($hWnd, $x, $y, $nContextID) Local $hMenu = GUICtrlGetHandle($nContextID) TrackPopupMenu($hWnd, $hMenu, $x, $y) EndFunc ; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd) Func TrackPopupMenu($hWnd, $hMenu, $x, $y) DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0) EndFunc Exit Link to comment Share on other sites More sharing options...
jfisher Posted September 1, 2007 Share Posted September 1, 2007 This is nearly EXACTLY what I was trying to accomplish by getting menus from an INI. I had no idea how to go about it and this looks like what I need to do. Thanks, and for that reason I am working through this seeing if I can't find a way to get it working as well. Link to comment Share on other sites More sharing options...
Siao Posted September 1, 2007 Share Posted September 1, 2007 GUI width and height equal to 0 is your problem. "be smart, drink your wine" Link to comment Share on other sites More sharing options...
jfisher Posted September 1, 2007 Share Posted September 1, 2007 Yeah thats what I just found out...if you change the GUI create to: $mygui = GUICreate("My GUI Context Menu", 0, 0, $mousepos[0], $mousepos[1], $WS_POPUP) it works just perfect. Thank you for the code btw 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