Jump to content

disable close button


baldak
 Share

Recommended Posts

How can I disable the close button ('X') in a window?

I'm not sure you can but you don't have to handle the event that is passed down when the user presses the button, or you could define another style to the window like this: GUICreate("Title",300,300,-1,-1,$WS_POPUPWINDOW)

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

If your referring to an AutoIt Gui window then there's a couple of ways..

You could use OnEvent mode 1 , then just not add an exit function on Gui Event close.

Or

Use Gui register message to catch the X button being clicked.

Example catching the X button being clicked using GuiRegisterMsg() and not sending the msg onto the Gui..

#include <GUIConstants.au3>

Global Const $WM_NCLBUTTONDOWN = 0xA1

GuiCreate("Catch the X Click", 300, 100)
GUISetState()

GUIRegisterMsg ($WM_NCLBUTTONDOWN, "WM_NCLBUTTONDOWN_FUNC")

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd
   
Func WM_NCLBUTTONDOWN_FUNC($hWnd, $Msg, $WParam, $LParam)
    $nID = BitAnd($wParam, 0x0000FFFF)
    If $nID = 20 Then
        Return 0
    Else
        Return $GUI_RUNDEFMSG
    EndIf   
EndFunc

If you mean any type of Non-AutoIt window then it's another story...

Cheers

Link to comment
Share on other sites

Be careful! There is no standard way to close application therefore HotKeySet with F1 to close

#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))

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
Edited by Zedna
Link to comment
Share on other sites

  • 7 years later...

How about

##include <GUIConstants.au3>
#include <WindowsConstants.au3>
Const $SC_CLOSE = 0xF060
HotKeySet("{F1}", "OnF1")

$gui = GUICreate("Click The X ", 269, 48, 2734, 529, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE))
$Label1 = GUICtrlCreateLabel("Press F1 to close", 0, 0, 266, 41)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUISetState(@SW_SHOW)

While 1

WEnd

Func OnF1()
    Exit
EndFunc
Link to comment
Share on other sites

  • Moderators

Elzie,

You are beginning >to make a habit of necroing very old threads - please stop it. :naughty:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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