Jump to content
Sign in to follow this  
ReaImDown

How to block the [X] in a window (close button top right)

Recommended Posts

ReaImDown

how would I disable it in a window...say on firefox...

also, how could I disable it in a GUI (made by the running program.)


[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

Share this post


Link to post
Share on other sites
Richard Robertson

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.

Share this post


Link to post
Share on other sites
rasim

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

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
Sign in to follow this  

×