aleksa Posted March 15, 2013 Share Posted March 15, 2013 (edited) I'm just curious why this doesn't work. Why doesn't the program exit when exit menu is clicked. What am I doing wrong? #include #include #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 221, 173, 192, 114) $exit = GUICtrlCreateMenu("Exit") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $exit ;This doesn't get called Exit EndSwitch WEnd Edited March 15, 2013 by aleksa Link to comment Share on other sites More sharing options...
Nessie Posted March 15, 2013 Share Posted March 15, 2013 (edited) You are not using a MenuItem so GUIGetMsg doesn't get nothing. Create a menu item and all will work good: #include <GUIConstantsEx.au3> #region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 221, 173, 192, 114) $Menu = GUICtrlCreateMenu("File") $Menu_Exit = GUICtrlCreateMenuItem("Exit", $Menu) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Menu_Exit Exit EndSwitch WEnd Hi! Edited March 15, 2013 by Nessie aleksa 1 My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s). My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all! My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 15, 2013 Moderators Share Posted March 15, 2013 aleksa, You need a MenuItem in the menu: #include <GUIConstantsEx.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 221, 173, 192, 114) $Menu = GUICtrlCreateMenu("Exit") $mExit = GUICtrlCreateMenuItem("Exit", $Menu) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $mExit ; Note multiple controls <<<<<<<<<<<<<<<<<<< Exit EndSwitch WEnd Somewhere I once did manage to get a menu to fire directly - I will see if I can find it. M23 aleksa 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 15, 2013 Moderators Share Posted March 15, 2013 aleksa,Found it - but it is probably too complex for your needs, so I suggest using a MenuItem as I suggested above: expandcollapse popup#include <GUIConstantsEx.au3> #Include <GuiMenu.au3> $hGUI = GUICreate("Test", 500, 500) $mFilemenu = GUICtrlCreateMenu("File") $mExititem = GUICtrlCreateMenuItem("Exit", $mFilemenu) $mSpecialitem = GUICtrlCreateMenu("Special") $mHelpmenu = GUICtrlCreateMenu("?") $mAboutitem = GUICtrlCreateMenuItem("About", $mHelpmenu) GUISetState() $hMenu = _GUICtrlMenu_GetMenu($hGUI) $iCount = _GUICtrlMenu_GetItemCount($hMenu) - 1 GUIRegisterMsg(0x0211,"_WM_ENTERMENULOOP") ; WM_ENTERMENULOOP While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $mExititem Exit Case $mAboutitem MsgBox(0, "Solved", "That was hard work!") EndSwitch WEnd Func _WM_ENTERMENULOOP($hWnd, $iMsg, $wParam, $lParam) For $i = 0 To $iCount Local $tRect = _GUICtrlMenu_GetItemRectEx($hGUI, $hMenu, $i) Local $aMousePos = MouseGetPos() Local $aRes = DllCall("User32.dll", "int", "PtInRect", "ptr", DllStructGetPtr($tRect), "int", $aMousePos[0], "int", $aMousePos[1]) If Not @error And $aRes[0] Then ConsoleWrite("You clicked: " & _GUICtrlMenu_GetItemText($hMenu, $i) & @CRLF) ExitLoop EndIf Next EndFuncNote that clicking a menu is a modal operation - so you will need to click again to reactivate the script after having clicked a menu with no items. M23 aleksa 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
aleksa Posted March 15, 2013 Author Share Posted March 15, 2013 Thanks for you replies. I'm glad I figured that out Melba32 code will definitely be in my template list 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