Sign in to follow this  
Followers 0
VAN0

Hide menu bar?

7 posts in this topic

#1 ·  Posted (edited)

Hello.

I have a menu added to GUI with _GUICtrlMenu_SetMenu() function

How do I hide this menu bar?

I'm trying make it show only when pressed ALT key

 

#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   ;==>MemoWrite
Thank you. Edited by VAN0

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by FireFox
1 person likes this

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

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:

post-58062-0-56070900-1401322524_thumb.p

before destroy it looked like this:

post-58062-0-02245100-1401322521_thumb.p

Any ideas what could cause this?

Thanks.

Share this post


Link to post
Share on other sites

The best you can do is probably to use the usual trick: Put the menu in a child window and hide the child window.

#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
1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by VAN0

Share this post


Link to post
Share on other sites

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 menu
Did 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.

1 person likes this

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

_GUICtrlMenu_SetMenu( $hWnd, 0 )   ; Set $hMenu = 0 to remove a menu

Ta-da!

Not only it removes the menu, it also moves everything up, just what I needed.

Thank you very much!

Edited by VAN0

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0