Jump to content

Recommended Posts

Posted

You can't exactly disable it, per se. You need access to the closing window message. You return a cancel value to the operating system and you have effectively canceled the closing of the window.

You could also mess with styles and remove the buttons completely.

Posted (edited)

ReaImDown

Try this:

#include <GuiMenu.au3>

HotKeySet("^d", "_CloseButton_Disable")
HotKeySet("^e", "_CloseButton_Enable")
HotKeySet("{ESC}", "_Exit")

$title = "[Class:Notepad]"

Run("notepad.exe")

WinWait($title)

Global $hWnd = WinGetHandle($title)
Global $hWndPrevious

While 1
    Sleep(100)
WEnd

Func _CloseButton_Disable()
    Local $hMenu = _GUICtrlMenu_GetSystemMenu($hWnd)
    If $hMenu = $hWndPrevious Then Return False
    
    _GUICtrlMenu_RemoveMenu($hMenu, 6, True)
    _GUICtrlMenu_RemoveMenu($hMenu, 5, True)
    _GUICtrlMenu_DrawMenuBar($hMenu)
    
    WinSetState($hWnd, "", @SW_HIDE)
    WinSetState($hWnd, "", @SW_SHOW)
    
    $hWndPrevious = $hMenu
EndFunc

Func _CloseButton_Enable()
    Local $hMenu = _GUICtrlMenu_GetSystemMenu($hWnd, True)
    If $hMenu = $hWndPrevious Then Return False
    
    WinSetState($hWnd, "", @SW_HIDE)
    WinSetState($hWnd, "", @SW_SHOW)
    
    $hWndPrevious = $hMenu
EndFunc

Func _Exit()
    If WinExists($hWnd) Then WinClose($hWnd)
    Exit
EndFunc
:) Edited by rasim

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...