Skip to content

Instantly share code, notes, and snippets.

@kissgyorgy
Last active July 1, 2021 00:57
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kissgyorgy/4519455 to your computer and use it in GitHub Desktop.
Save kissgyorgy/4519455 to your computer and use it in GitHub Desktop.
AutoIt: Enable or Disable Window buttons via DllCall()
; Original script: http://www.autoitscript.com/forum/topic/100125-disable-close-button/#entry716490
; USer32.dll functions: http://msdn.microsoft.com/en-us/library/ms647985(v=vs.85).aspx
; "The first script ( remove the button ) work fine on XP, the second ( the disable script ) disable only the close button, i have tested both version, the dll and the GuiMenu"
; See http://www.autoitscript.com/forum/topic/147424-disable-or-remove-close-minimize-maximize-buttons-on-any-window-in-runtime/#entry1045390
; ---------------------------------------
#include <GuiMenu.au3>
Run("Notepad")
WinWait("Untitled - Notepad")
$handle = WinGetHandle("Untitled - Notepad")
ConsoleWrite('+ Window Handle: ' & $handle & @CRLF)
DisableButton($handle, $SC_CLOSE)
;~ EnableButton($handle, $SC_CLOSE)
DisableButton($handle, $SC_MAXIMIZE)
DisableButton($handle, $SC_RESTORE)
DisableButton($handle, $SC_MOVE)
Func DisableButton($hWnd, $iButton)
$hSysMenu = _GUICtrlMenu_GetSystemMenu($hWnd, 0)
_GUICtrlMenu_RemoveMenu($hSysMenu, $iButton, False)
_GUICtrlMenu_DrawMenuBar($hWnd)
EndFunc
Func EnableButton($hWnd, $iButton)
$hSysMenu = _GUICtrlMenu_GetSystemMenu($hWnd, 1)
_GUICtrlMenu_RemoveMenu($hSysMenu, $iButton, False)
_GUICtrlMenu_DrawMenuBar($hWnd)
EndFunc
@JUAN-DO
Copy link

JUAN-DO commented Sep 28, 2020

hello thanks this is very good but a question how can I block more things for example new, open

and it can also be blocked from the sub menu, how can I do it, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment