GeekIT Posted December 1, 2013 Posted December 1, 2013 Hi everyone I have a quick question about menus in autoit: Is it normal that I can't use menu's in forms that don't have sub-menu's? example: $Form = GUICreate("Test.", 300, 200) $Menu = GUICtrlCreateMenu("Menu") While 1 Switch GUIGetMsg() Case $Menu MsgBox(0,'never works','never works!'); <--- why won't this work? EndSwitch
water Posted December 1, 2013 Posted December 1, 2013 Welcome to AutoIt and the forum! Did you check the example that can be found in the help file for function GUICtrlCreateMenu? At least line GUISetState() is missing. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted December 1, 2013 Posted December 1, 2013 BTW: Could you please enclose your code in AutoIt code tags (the blue "A" icon in the editor). Enhances readability My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
kylomas Posted December 1, 2013 Posted December 1, 2013 (edited) GeekIT, You're also missing the WEND stmt to close the while loop. Try it like this... #include <GUIConstantsEx.au3> $Form = GUICreate("Test.", 300, 200) $Menu = GUICtrlCreateMenu("Menu") $Menumsg1 = GUICtrlCreateMenuItem('Message # 1', $Menu) $Menumsg2 = GUICtrlCreateMenuItem('Message # 2', $Menu) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Menumsg1 MsgBox(0, 'never works', 'never works!'); <--- why won't this work? Case $Menumsg2 MsgBox(0, '', 'Of course it works' & @crlf & 'Read the HELP file.'); <--- why won't this work? EndSwitch WEnd See the Help file for explanation... kylomas edit: spelling Edited December 1, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
water Posted December 1, 2013 Posted December 1, 2013 I assume the missing WEnd statement is just a copy&paste mistake My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Moderators Melba23 Posted December 1, 2013 Moderators Posted December 1, 2013 GeekIT,I can get as far as recognising the click on the menu bar. But as yet I cannot get out of the blocking menu loop - you need to press {ESCAPE} to reenter the script and get the dummy to fire: expandcollapse popup#include <GUIConstantsEx.au3> #include <Constants.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) $cMenuDummy = GUICtrlCreateDummy() 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 $cMenuDummy MsgBox($MB_SYSTEMMODAL, "Hi", "I can be actioned!") Case $mAboutitem MsgBox($MB_SYSTEMMODAL, "Solved", "That was hard work!") EndSwitch WEnd Func _WM_ENTERMENULOOP($hWnd, $iMsg, $wParam, $lParam) If $hWnd = $hGUI Then 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) GUICtrlSendToDummy($cMenuDummy) ExitLoop EndIf Next EndIf EndFuncI will keep working on it this afternoon. In the mean time if you have any questions, please ask. M23 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
GeekIT Posted December 1, 2013 Author Posted December 1, 2013 Welcome to AutoIt and the forum! Did you check the example that can be found in the help file for function GUICtrlCreateMenu? At least line GUISetState() is missing. yes and i know, is just an example. thanks for the reply (:
GeekIT Posted December 1, 2013 Author Posted December 1, 2013 (edited) GeekIT, You're also missing the WEND stmt to close the while loop. I know, was just explaining my problem. I want to use a menu without sub menu's. I want it so that you just have to click on the menu button itself and then do something... Edited December 1, 2013 by GeekIT Fixed tags
GeekIT Posted December 1, 2013 Author Posted December 1, 2013 (edited) GeekIT,I can get as far as recognising the click on the menu bar. But as yet I cannot get out of the blocking menu loop - you need to press {ESCAPE} to reenter the script and get the dummy to fire: I will keep working on it this afternoon. In the mean time if you have any questions, please ask. Thanks but you don't have to do all that for me (:I just wanted to know if this was normal. thanks for the help! Edited December 1, 2013 by Melba23 Fixed tags
Moderators Solution Melba23 Posted December 1, 2013 Moderators Solution Posted December 1, 2013 (edited) GeekIT,Jos came up with a solution: #include <GUIConstantsEx.au3> #include <Constants.au3> #Include <GuiMenu.au3> $hGUI = GUICreate("Test", 500, 500) $mFilemenu = GUICtrlCreateMenu("File") $mExititem = GUICtrlCreateMenuItem("Exit", $mFilemenu) $mSpecialitem = GUICtrlCreateMenuItem("Special", -1) $mHelpmenu = GUICtrlCreateMenu("?") $mAboutitem = GUICtrlCreateMenuItem("About", $mHelpmenu) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $mExititem Exit Case $mSpecialitem MsgBox($MB_SYSTEMMODAL, "Hi", "I can be actioned!") Case $mAboutitem MsgBox($MB_SYSTEMMODAL, "Solved", "Thank Jos for that!") EndSwitch WEndM23Edit: And so did wraithdu:expandcollapse popup#include <GUIConstantsEx.au3> #include <Constants.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) $cMenuDummy = GUICtrlCreateDummy() 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 $cMenuDummy MsgBox($MB_SYSTEMMODAL, "Hi", "I can be actioned!") Case $mAboutitem MsgBox($MB_SYSTEMMODAL, "Solved", "That was hard work!") EndSwitch WEnd Func _WM_ENTERMENULOOP($hWnd, $iMsg, $wParam, $lParam) If $hWnd = $hGUI Then For $i = 0 To $iCount Local $tRect = _GUICtrlMenu_GetItemRectEx($hGUI, $hMenu, $i) Local $aMousePos = MouseGetPos() Local $tPOINT = DllStructCreate($tagPOINT) $tPOINT.x = $aMousePos[0] $tPOINT.y = $aMousePos[1] Local $aRes = DllCall("User32.dll", "int", "PtInRect", "struct*", $tRect, "struct", $tPOINT) If Not @error And $aRes[0] Then ConsoleWrite("You clicked: " & _GUICtrlMenu_GetItemText($hMenu, $i) & @CRLF) GUICtrlSendToDummy($cMenuDummy) ControlClick($hGUI, "", $hGUI) Return 0 EndIf Next EndIf EndFunc Edited December 1, 2013 by Melba23 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
GeekIT Posted December 1, 2013 Author Posted December 1, 2013 Ah, I see. Thanks for all the help guys!
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