RTFC Posted March 28, 2023 Share Posted March 28, 2023 If you don't want the standard drop-down menu's from the top menu bar, here's a simple way to catch user clicks there, so you end up with a top button bar instead, without defining actual buttons. No handling is provided other than item ID written to console. Took me about a full day of forum grazing to cobble it together. expandcollapse popup; edited Helpfile example script for _GUICtrlMenu_CreateMenu #include <GUIConstantsEx.au3> #include <GuiMenu.au3> #include <WinAPIConv.au3> #include <WindowsConstants.au3> Example() Func Example() Local $hGUI, $hFile, $hEdit, $hHelp, $hMain ; Create GUI $hGUI = GUICreate("Menu", 400, 300) ; Create menu items $hFile = _GUICtrlMenu_CreateMenu() $hEdit = _GUICtrlMenu_CreateMenu() $hHelp = _GUICtrlMenu_CreateMenu() ; Create Main menu $hMain = _GUICtrlMenu_CreateMenu() _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 $g_idMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0) GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") GUISetState(@SW_SHOW) ; ADDED LINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUIRegisterMsg( $WM_MENUSELECT, "WM_MENUSELECT_Events") GUIRegisterMsg( $WM_ENTERMENULOOP, "WM_ENTERMENULOOP" ) Global $hGuiHandle=WinGetHandle("","") ; get GUI handle too ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>Example ;========================================================================== ; ADDED Func WM_MENUSELECT_Events($hWndGUI, $MsgID, $wParam, $lParam) Static $first=False $first=Not $first ; to filter out the dummy click that resets detection Local $index = _LoWord($wParam) Local $flags = _HiWord($wParam) If $first And BitAND($flags, $MF_MOUSESELECT) Then ConsoleWrite("top menu ID: " & $index & @CRLF) Return $GUI_RUNDEFMSG EndFunc Func _HiWord($x) Return BitShift($x, 16) EndFunc Func _LoWord($x) Return BitAND($x, 0xFFFF) EndFunc Func WM_ENTERMENULOOP( $hWnd, $iMsg, $iwParam, $ilParam ) ControlClick($hGuiHandle, "", "") ; dummy click at menu item 0 to reset detection Return $GUI_RUNDEFMSG EndFunc My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 28, 2023 Moderators Share Posted March 28, 2023 RTFC, If you use the native menu functions it is a little bit easier: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $mFilemenu = GUICtrlCreateMenu("&File") $mExititem = GUICtrlCreateMenuItem("E&xit", $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 WEnd M23 RTFC 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...
RTFC Posted March 29, 2023 Author Share Posted March 29, 2023 (edited) A light in the darkness as always, Melba. None of the previous discussions I read on this topic presented this (better) solution. I think it's about time you consider uploading your AutoIt knowledge to an AI for posterity's sake (maybe with a Yoda-voiced speech synthesizer?). Who wouldn't want a pocket-sized Melba sitting on their shoulder, whispering snazzy GUI solutions in one's ear? It would have saved me from writing this Rube-Goldberg contraption. I guess you'd need a dummy control if all menu items are to function as buttons : #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $mDummy = GUICtrlCreateMenu("") $mSpecialitem = GUICtrlCreateMenuItem("&Special", -1) $mSpecialitem2 = GUICtrlCreateMenuItem("&Special2", -1) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $mSpecialitem MsgBox($MB_SYSTEMMODAL, "Hi", "I can be actioned!") Case $mSpecialitem2 MsgBox($MB_SYSTEMMODAL, "Hello", "I can ALSO be actioned!") EndSwitch WEnd Edited March 29, 2023 by RTFC Skeletor 1 My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O 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