VAN0 Posted May 27, 2014 Share Posted May 27, 2014 Hello.The _GUICtrlMenu_CreateMenu documentation states_GUICtrlMenu_CreateMenu ( [$iStyle = 8] )$iStyle 32 - Menu owner receives a WM_MENUCOMMAND message instead of a WM_COMMAND message for selectionsSo I tried modify the example provided to use WM_MENUCOMMAND: expandcollapse popup#include <GuiMenu.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global $iMemo Global Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout Example() Func Example() Local $hGUI, $hFile, $hEdit, $hHelp, $hMain ; Create GUI $hGUI = GUICreate("Menu", 400, 300) ; Create File menu $hFile = _GUICtrlMenu_CreateMenu(8+32) _GUICtrlMenu_InsertMenuItem($hFile, 0, "&New", $idNew) _GUICtrlMenu_InsertMenuItem($hFile, 1, "&Open", $idOpen) _GUICtrlMenu_InsertMenuItem($hFile, 2, "&Save", $idSave) _GUICtrlMenu_InsertMenuItem($hFile, 3, "", 0) _GUICtrlMenu_InsertMenuItem($hFile, 4, "E&xit", $idExit) ; Create Edit menu $hEdit = _GUICtrlMenu_CreateMenu(8+32) _GUICtrlMenu_InsertMenuItem($hEdit, 0, "&Cut", $idCut) _GUICtrlMenu_InsertMenuItem($hEdit, 1, "C&opy", $idCopy) _GUICtrlMenu_InsertMenuItem($hEdit, 2, "&Paste", $idPaste) ; Create Help menu $hHelp = _GUICtrlMenu_CreateMenu(8+32) _GUICtrlMenu_InsertMenuItem($hHelp, 0, "&About", $idAbout) ; Create Main menu $hMain = _GUICtrlMenu_CreateMenu(8+32) _GUICtrlMenu_InsertMenuItem($hMain, 0, "&File", 0, $hFile) _GUICtrlMenu_InsertMenuItem($hMain, 1, "&Edit", 0, $hEdit) _GUICtrlMenu_InsertMenuItem($hMain, 2, "&Help", 0, $hHelp) ; Set window menu _GUICtrlMenu_SetMenu($hGUI, $hMain) ; Create memo control $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState(@SW_SHOW) ; Loop until the user exits. GUIRegisterMsg($WM_MENUCOMMAND, "WM_MENUCOMMAND") ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>Example ; Handle menu commands Func WM_MENUCOMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $ilParam Switch _WinAPI_LoWord($iwParam) Case $idNew MemoWrite("New") Case $idOpen MemoWrite("Open") Case $idSave MemoWrite("Save") Case $idExit Exit Case $idCut MemoWrite("Cut") Case $idCopy MemoWrite("Copy") Case $idPaste MemoWrite("Paste") Case $idAbout MemoWrite("About") EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_MENUCOMMAND ; Write message to memo Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWriteBut it doesn't work, nothing happens when any menu item clicked.What I'm doing wrong?Thanks. Link to comment Share on other sites More sharing options...
Sori Posted May 27, 2014 Share Posted May 27, 2014 It appears that your program doesn't see that the menu item has been clicked. I'm not very good with GUIs, but this video may help. If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects. Link to comment Share on other sites More sharing options...
VAN0 Posted May 27, 2014 Author Share Posted May 27, 2014 Thanks for the reply.The built-in functions work fine, no problem there, it's the UDF functions that seems don't work properly... Link to comment Share on other sites More sharing options...
Solution KaFu Posted May 27, 2014 Solution Share Posted May 27, 2014 The documented flags are wrong. You need to apply MNS_NOTIFYBYPOS to the header (main) menu ("MNS_NOTIFYBYPOS is a menu header style and has no effect when applied to individual sub menus."). Also note: "The WM_MENUCOMMAND message gives you a handle to the menu—so you can access the menu data in the MENUINFO structure—and also gives you the index of the selected item, which is typically what applications need. In contrast, the WM_COMMAND message gives you the menu item identifier." expandcollapse popup#include <GuiMenu.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global $iMemo Global Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout Example() Func Example() Local $hGUI, $hFile, $hEdit, $hHelp, $hMain ; Create GUI $hGUI = GUICreate("Menu", 400, 300) ; Create File menu $hFile = _GUICtrlMenu_CreateMenu(8 + 32) ConsoleWrite(@error & @CRLF) _GUICtrlMenu_InsertMenuItem($hFile, 0, "&New", $idNew) _GUICtrlMenu_InsertMenuItem($hFile, 1, "&Open", $idOpen) _GUICtrlMenu_InsertMenuItem($hFile, 2, "&Save", $idSave) _GUICtrlMenu_InsertMenuItem($hFile, 3, "", 0) _GUICtrlMenu_InsertMenuItem($hFile, 4, "E&xit", $idExit) ; Create Edit menu $hEdit = _GUICtrlMenu_CreateMenu(8 + 32) _GUICtrlMenu_InsertMenuItem($hEdit, 0, "&Cut", $idCut) _GUICtrlMenu_InsertMenuItem($hEdit, 1, "C&opy", $idCopy) _GUICtrlMenu_InsertMenuItem($hEdit, 2, "&Paste", $idPaste) ; Create Help menu $hHelp = _GUICtrlMenu_CreateMenu(8 + 32) _GUICtrlMenu_InsertMenuItem($hHelp, 0, "&About", $idAbout) ; Create Main menu $hMain = _GUICtrlMenu_CreateMenu($MNS_NOTIFYBYPOS) _GUICtrlMenu_InsertMenuItem($hMain, 0, "&File", 0, $hFile) _GUICtrlMenu_InsertMenuItem($hMain, 1, "&Edit", 0, $hEdit) _GUICtrlMenu_InsertMenuItem($hMain, 2, "&Help", 0, $hHelp) ; Set window menu _GUICtrlMenu_SetMenu($hGUI, $hMain) ; Create memo control $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState(@SW_SHOW) ; Loop until the user exits. GUIRegisterMsg($WM_MENUCOMMAND, "WM_MENUCOMMAND") ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>Example ; Handle menu commands Func WM_MENUCOMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $ilParam ConsoleWrite($hWnd & @TAB & $iMsg & @TAB & $iwParam & @TAB & $ilParam & @CRLF) ConsoleWrite(_GUICtrlMenu_GetItemText($ilParam, $iwParam) & @CRLF) Switch _WinAPI_LoWord($iwParam) Case $idNew MemoWrite("New") Case $idOpen MemoWrite("Open") Case $idSave MemoWrite("Save") Case $idExit Exit Case $idCut MemoWrite("Cut") Case $idCopy MemoWrite("Copy") Case $idPaste MemoWrite("Paste") Case $idAbout MemoWrite("About") EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_MENUCOMMAND ; Write message to memo Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite VAN0 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
VAN0 Posted May 27, 2014 Author Share Posted May 27, 2014 That's it!Thank you very much! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 27, 2014 Moderators Share Posted May 27, 2014 KaFu,The documented flags are wrongLet me know how they should read and I will change the documentation. 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 Link to comment Share on other sites More sharing options...
KaFu Posted May 27, 2014 Share Posted May 27, 2014 They are declared correctly in _GUICtrlMenu_SetMenuStyle(). OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 27, 2014 Moderators Share Posted May 27, 2014 KaFu,Danke - I will get the 2 pages aligned tomorrow. M23 VAN0 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...
VAN0 Posted May 28, 2014 Author Share Posted May 28, 2014 A little correction, the WM_MENUCOMMAND works, however the switch condition doesn't, it needs replace_WinAPI_LoWord($iwParam)with_GUICtrlMenu_GetItemID($ilParam, $iwParam) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 28, 2014 Moderators Share Posted May 28, 2014 KaFu,_GUICtrlMenu_CreateMenu, _GUICtrlMenu_CreatePopup & _GUICtrlMenu_SetMenuStyle now all aligned with the same style values. M23 KaFu 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...
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