VAN0 Posted May 28, 2014 Share Posted May 28, 2014 (edited) Hello.I have a menu added to GUI with _GUICtrlMenu_SetMenu() functionHow do I hide this menu bar?I'm trying make it show only when pressed ALT key 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() _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() _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() _GUICtrlMenu_InsertMenuItem($hHelp, 0, "&About", $idAbout) ; 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 $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState(@SW_SHOW) ; Loop until the user exits. GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>Example ; Handle menu commands Func WM_COMMAND($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_COMMAND ; Write message to memo Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWriteThank you. Edited May 28, 2014 by VAN0 Link to comment Share on other sites More sharing options...
FireFox Posted May 28, 2014 Share Posted May 28, 2014 (edited) Hi, Thanks for the helpfile example (that's ironic). Read it again, and you will have the answer in it (for the _GUICtrlMenu_SetMenu one). Br, FireFox. Edited May 28, 2014 by FireFox VAN0 1 Link to comment Share on other sites More sharing options...
VAN0 Posted May 29, 2014 Author Share Posted May 29, 2014 Thanks for the reply.So, destroying whole menu is the only way? I was hoping for some kind of less aggressive, hiding way.Also, the help example seems to work fine with destroy menu, however in my script the menu stays but it looses style, it simply become windows 98 style:before destroy it looked like this:Any ideas what could cause this?Thanks. Link to comment Share on other sites More sharing options...
LarsJ Posted May 29, 2014 Share Posted May 29, 2014 The best you can do is probably to use the usual trick: Put the menu in a child window and hide the child window.expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiMenu.au3> Opt( "MustDeclareVars", 1 ) Global $iMemo Global Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout Global $hGui, $hChild MainProgram() Func MainProgram() $hGui = GUICreate( "Hide menu", 400, 340, -1, -1, BitOR( $GUI_SS_DEFAULT_GUI, $WS_SIZEBOX ) ) $hChild = GUICreate( "", 400-6, 20, -2, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGui ) ; Create File menu Local $hFile = _GUICtrlMenu_CreateMenu() _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 Local $hEdit = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hEdit, 0, "&Cut", $idCut) _GUICtrlMenu_InsertMenuItem($hEdit, 1, "C&opy", $idCopy) _GUICtrlMenu_InsertMenuItem($hEdit, 2, "&Paste", $idPaste) ; Create Help menu Local $hHelp = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hHelp, 0, "&About", $idAbout) ; Create Main menu Local $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($hChild, $hMain) GUISwitch( $hGui ) ; Create memo control $iMemo = GUICtrlCreateEdit("", 2, 30, 396, 268, 0) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") MemoWrite("Tested on Windows 7. May be you need to adjust the positions and sizes of the controls on another Windows.") Local $idShowMenu = GUICtrlCreateButton( "Show menu", 2, 305, 100, 30 ) Local $idHideMenu = GUICtrlCreateButton( "Hide menu", 112, 305, 100, 30 ) GuiRegisterMsg( $WM_NCACTIVATE, "WM_NCACTIVATE" ) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState() GUISetState( @SW_SHOW, $hChild ) While 1 Local $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $hGui Switch $aMsg[0] Case $idShowMenu GUISetState( @SW_SHOW, $hChild ) Case $idHideMenu GUISetState( @SW_HIDE, $hChild ) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch EndSwitch WEnd GUIDelete( $hGui ) Exit EndFunc ; Handle menu commands Func WM_COMMAND($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_COMMAND ; Write message to memo Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite Func WM_NCACTIVATE( $hWnd, $iMsg, $wParam ) If $hWnd = $hGui Then If Not $wParam Then Return 1 EndIf If $hWnd = $hChild Then If Not $wParam Then Return 1 EndIf EndFunc VAN0 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
VAN0 Posted May 29, 2014 Author Share Posted May 29, 2014 (edited) The best you can do is probably to use the usual trick: Put the menu in a child window and hide the child window.Thank you.This seems to be best approach for my needs. Now need figure out how to make everything move up to fill up the empty space when menu is hidden. Shouldn't be too hard.P.S.I still curious what could possibly cause menu looses it's style instead of being completely removed?[EDIT]I just noticed, in your example the menu has a weird style on mouse over (blue highlighting), it's like in my screenshot, however when it's opened the items look fine. Any ideas why is that? Edited May 29, 2014 by VAN0 Link to comment Share on other sites More sharing options...
Solution LarsJ Posted May 30, 2014 Solution Share Posted May 30, 2014 Removing the main menu from a window and destroying a menu are two different things:_GUICtrlMenu_SetMenu( $hWnd, 0 ) ; Set $hMenu = 0 to remove a menu _GUICtrlMenu_DestroyMenu( $hMenu ) ; Destroy a menuDid you use both commands?For differences in menu styles use _GUICtrlMenu_GetMenuStyle and _GUICtrlMenu_GetMenuInfo to investigate the problem. May be you can do something about it. May be not. One can rarely use that kind of tricks at no cost. VAN0 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
VAN0 Posted May 30, 2014 Author Share Posted May 30, 2014 (edited) _GUICtrlMenu_SetMenu( $hWnd, 0 ) ; Set $hMenu = 0 to remove a menuTa-da!Not only it removes the menu, it also moves everything up, just what I needed.Thank you very much! Edited May 30, 2014 by VAN0 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