lowbred

Disable Window Menu?

16 posts in this topic

Is there a way to disable the window menu (restore, move, resize, minimize, maximize, close). I have read in the forum and seen examples of completely removing the title bar icon but I would like to keep the icon but have no menu.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

AutoIt GUI, also being able to keep the default window border.

Edited by lowbred

Share this post


Link to post
Share on other sites

And here is some my playing example:

#include <GUIConstants.au3>

;~ Const $SC_CLOSE = 0xF060
Const $MF_BYCOMMAND = 0x0
;~ Const $MF_GRAYED = 0x1
;~ Const $WM_SYSCOMMAND = 0x0112

HotKeySet("{F1}", "OnF1")

$gui = GuiCreate("Catch the X Click", 300, 100)
GUISetState()

GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND")

$hMenu = DllCall("user32.dll", "hwnd", "GetSystemMenu", "hwnd", $gui, "int", 0)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_CLOSE, "int", $MF_BYCOMMAND)
;~ DllCall("user32.dll","hwnd","EnableMenuItem", "hwnd", $hMenu[0], "int",$SC_CLOSE, "int", BitOr($MF_BYCOMMAND,$MF_GRAYED))
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_RESTORE, "int", $MF_BYCOMMAND)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_MOVE, "int", $MF_BYCOMMAND)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_SIZE, "int", $MF_BYCOMMAND)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_MINIMIZE, "int", $MF_BYCOMMAND)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_MAXIMIZE, "int", $MF_BYCOMMAND)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_SEPARATOR, "int", $MF_BYCOMMAND)

DllCall("user32.dll","hwnd","DestroyMenu", "hwnd", $hMenu[0])
;~ BOOL WINAPI DestroyMenu(  _In_  HMENU hMenu);

;~ $hMenu = DllCall("user32.dll", "hwnd", "SetMenu", "hwnd", $gui, "int", 0)
;~ BOOL WINAPI SetMenu(  _In_      HWND hWnd,  _In_opt_  HMENU hMenu);

DllCall("user32.dll","hwnd","DrawMenuBar", "hwnd", $gui)
;~ BOOL WINAPI DrawMenuBar(  _In_  HWND hWnd);

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

; to disable Alt+F4
Func On_WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    If BitAND($wParam, 0xFFF0) = $SC_CLOSE Then Return
EndFunc

Func OnF1()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

Thanks Zedna but I was hoping for for the menu not to be there at all... Just gone... Destroyed completely. Also, I would like to keep the functionality of the buttons.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I'm not sure to understand what you need, but try this :

#include <WinAPI.au3>
#include <GUIConstants.au3>

Local $gui = GUICreate("gui", 160, 35)
Local $idButton = GUICtrlCreateButton("Hide SysMenu", 5, 5, 150, 25)
Local $iState = 1

GUISetState()

Local $iShowStyle = _WinAPI_GetWindowLong($gui, $GWL_STYLE )
Local $iHideStyle = BitXOR($iShowStyle, $WS_SYSMENU)

While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then Exit
    If $msg = $idButton Then
        If $iState Then 
            $iStyle = $iHideStyle
            $sText = "Show SysMenu"
        Else
            $iStyle = $iShowStyle
            $sText = "Hide SysMenu"
        EndIf
        _WinAPI_SetWindowLong($gui, $GWL_STYLE, $iStyle)
        GUICtrlSetData($idButton, $sText)
        $iState = NOT $iState
    EndIf
WEnd
Edited by jguinch

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@jguinch

Nice solution! :thumbsup:

Side unwanted effect is that dissapear also application's icon and Min/Max/Close icons in titlebar of window (after covering/uncovering by another application).

Edited by Zedna

Share this post


Link to post
Share on other sites

JohnOne,

MenuConstants.au3. :)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Here is my solution: completely removed system menu but retained system icon

#include <GUIConstants.au3>

;~ Const $SC_CLOSE = 0xF060
Const $MF_BYCOMMAND = 0x0
;~ Const $MF_BYPOSITION = 0x00000400

$gui = GuiCreate("Removed system menu", 300, 100)
GUISetState()

$hMenu = DllCall("user32.dll", "hwnd", "GetSystemMenu", "hwnd", $gui, "int", 0)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_CLOSE, "int", $MF_BYCOMMAND)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_RESTORE, "int", $MF_BYCOMMAND)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_MOVE, "int", $MF_BYCOMMAND)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_SIZE, "int", $MF_BYCOMMAND)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_MINIMIZE, "int", $MF_BYCOMMAND)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_MAXIMIZE, "int", $MF_BYCOMMAND)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",$SC_SEPARATOR, "int", $MF_BYCOMMAND)
DllCall("user32.dll","hwnd","DeleteMenu", "hwnd", $hMenu[0], "int",0, "int", $MF_BYPOSITION) ; separator

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Side unwanted effect is that Min/Max/Close icons/buttons in titlebar of window don't work.

Edited by Zedna

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

;Johnmcloud - 2015
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MenuConstants.au3>

$hGUI = GUICreate("NO_CONTEXT_MENU", 300, 300, -1, -1)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NCRBUTTONDOWN, "WM_NCRBUTTONDOWN")
GUIRegisterMsg($WM_SYSCOMMAND,"WM_SYSCOMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_NCRBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Switch $wParam
        Case $HTCAPTION, $HTSYSMENU, $HTMINBUTTON, $HTMAXBUTTON, $HTTOPRIGHT, $HTBOTTOM
            Return 0
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NCRBUTTONDOWN

Func WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Switch $wParam
        Case $SC_KEYMENU, BitOr($SC_MOUSEMENU, $wParam)
            Return 0
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SYSCOMMAND

Edited by johnmcloud

Share this post


Link to post
Share on other sites

Though it's not working. Left click by mouse on system icon opens system menu.

There's a way to fix that.

Change this line in the WM_COMMAND function.

Case $SC_KEYMENU, BitOR($SC_MOUSEMENU, $wParam)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I forgot it :sweating:

Thanks BrewManNH, code updated

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