In addition to all the good advice given already, here's how to "disable" the red close X on the top right of a window:
Declare these external functions in your window:
EDIT: changed some uLong types for longptr (the hWnd ones):
// api functions to manipulate menu on title bar
Function ulong GetSystemMenu (longptr hWnd, boolean bRevert) Library "user32.dll"
Function boolean DeleteMenu (ulong hMenu, uint uPosition, uint uFlags) Library "user32.dll"
Function boolean DrawMenuBar (longptr hWnd) Library "user32.dll"
And then call this script in the Open() event of the window. It will still show the "X" but in a disabled state and nothing happens when you click on it:
//// System Menu Command Values
//constant ulong SC_SIZE = 61440
//constant ulong SC_MOVE = 61456
//constant ulong SC_MINIMIZE = 61472
//constant ulong SC_MAXIMIZE = 61488
//constant ulong SC_NEXTWINDOW = 61504
//constant ulong SC_PREVWINDOW = 61520
//constant ulong SC_RESTORE = 61632
constant ulong SC_CLOSE = 61536
// Menu Flags
constant ulong MF_BYCOMMAND = 0
hWnd = Handle(this)
// get menu handle for this window's system menu
hMenu = GetSystemMenu(hWnd, False)
// If successful, delete menu items from this window's system menu
// which is displayed when clicking the control box.
if hMenu > 0 then
//Delete menu items close, size, minimize, maximize, move
DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
// DrawMenuBar will redraw the menu with the "deletemenu" changes applied
Just in case it might be useful to anyone.
1. Define a Boolean instance variable in the window and set its initial value to False.
2. Prior to issuing the Close function set the instance Boolean variable to True.
3. Check the value of the instance Boolean in the window's CloseQuery event.