Preventing console window close
Posted: Fri Apr 21, 2006 11:27 pm
Hi, is there any way to prevent a user from closing the console window while a program is running? I'm still very new to Windows programming, so I guess I'm missing something basic here! After reading various threads and articles I've tried the following two methods, neither of which work. Any help or hints would be welcome 
Attempt 1
Trap the close window event.
I've found out how to do something before the window closes, but can't figure out how to ignore the close event. The window still closes after console_handler() is called
Attempt 2
Disable the close button
If the close button and system menu option are disabled the user can't easily close the window. The code below does not work.
con_handle shown as 7
system_menu shown as 0

Attempt 1
Trap the close window event.
I've found out how to do something before the window closes, but can't figure out how to ignore the close event. The window still closes after console_handler() is called
Code: Select all
EnableExplicit
Procedure console_handler(my_event.l)
If my_event = #CTRL_CLOSE_EVENT
PrintN("Close in 3 seconds... Can't stop it!")
Delay(3000)
EndIf
EndProcedure
OpenConsole()
SetConsoleCtrlHandler_(@console_handler(), 1)
PrintN("Try and stop the console closing...Close the window now")
Input()
CloseConsole()
Disable the close button
If the close button and system menu option are disabled the user can't easily close the window. The code below does not work.
con_handle shown as 7
system_menu shown as 0
Code: Select all
EnableExplicit
Global con_handle.l
Global system_menu.l
OpenConsole()
con_handle = GetStdHandle_(#STD_OUTPUT_HANDLE)
Debug "con_handle = " + Str(con_handle)
system_menu = GetSystemMenu_(con_handle, #False)
Debug "system_menu = " + Str(system_menu)
EnableMenuItem_(system_menu, #SC_CLOSE, #MF_BYCOMMAND | #MF_DISABLED)
DrawMenuBar_(con_handle)
PrintN("Close window should be disabled but isn't")
Input()
CloseConsole()