You are here

Disable close button in Windows application with Autoit

Not perfect, shift+10, alt+F4, ... already works):

; 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
#include <GuiMenu.au3>

Run("Notepad")
WinWait("[CLASS:Notepad]")

$handle = WinGetHandle("[CLASS: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