lowbred Posted March 28, 2015 Posted March 28, 2015 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.
Zedna Posted March 28, 2015 Posted March 28, 2015 Do you mean menu in your own AutoIt's application or menu in external application? Resources UDF ResourcesEx UDF AutoIt Forum Search
lowbred Posted March 28, 2015 Author Posted March 28, 2015 (edited) AutoIt GUI, also being able to keep the default window border. Edited March 28, 2015 by lowbred
Zedna Posted March 28, 2015 Posted March 28, 2015 Here is something for you to start with https://msdn.microsoft.com/en-us/library/windows/desktop/ff468865%28v=vs.85%29.aspx Resources UDF ResourcesEx UDF AutoIt Forum Search
Zedna Posted March 28, 2015 Posted March 28, 2015 And here is some my playing example: expandcollapse popup#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 Resources UDF ResourcesEx UDF AutoIt Forum Search
lowbred Posted March 28, 2015 Author Posted March 28, 2015 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.
jguinch Posted March 29, 2015 Posted March 29, 2015 (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 March 29, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Zedna Posted March 29, 2015 Posted March 29, 2015 (edited) @jguinch Nice solution! 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 March 29, 2015 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
JohnOne Posted March 29, 2015 Posted March 29, 2015 Where are the $SC* constants located like $SC_MOVE ? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Moderators Melba23 Posted March 29, 2015 Moderators Posted March 29, 2015 JohnOne,MenuConstants.au3. M23 JohnOne 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
JohnOne Posted March 29, 2015 Posted March 29, 2015 Cheers M Has StaticConstants written all over it. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Zedna Posted March 29, 2015 Posted March 29, 2015 (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 March 29, 2015 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
johnmcloud Posted April 1, 2015 Posted April 1, 2015 (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 April 2, 2015 by johnmcloud
Zedna Posted April 1, 2015 Posted April 1, 2015 @johnmcloud Nice elegant approach! Though it's not working. Left click by mouse on system icon opens system menu. Resources UDF ResourcesEx UDF AutoIt Forum Search
BrewManNH Posted April 2, 2015 Posted April 2, 2015 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 GudeHow 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
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