Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: Judago
I'm writing a win32 (well 2000 and above) console app and want
to disable the close button, the reason being that I want
to be sure all data entered is saved before exit. I'm using
Dev-c++ 4.9.9.2.The below code is what is giving me trouble, it disables the
x on the top corner but the alt+spacebar/click on top left hand
corner menu reactivates it along with having close on the
menu it's self active:#define _WIN32_WINNT 0x0500 #include <windows.h> int main() { EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED); DrawMenuBar(GetConsoleWindow()); system ("pause"); }Simply changing "EnableMenuItem" to "RemoveMenu" does work but
since it's a console app I want to restore the default menus,
size, colour, ect. on exit.GetSystemMenu(GetConsoleWindow(), TRUE);Comes close to restoring it but it's not the default console
menu, just a generic menu.
Can anyone please point me to either a way to disable close
properly or even restore the default console menu when I'm
finished?

Have you tried just calling FreeConsole() and AllocConsole() to spawn your own console window? That way, you don't have to worry about resetting the menu, nor hooking the console.

Thanks Razor2.3, I didn't even know about FreeConsole() and AllocConsole(). It works perfectly.
Now I can just remove the close command as their will always be some sort of a custom field based on getch() that detects esc or alt+f4.
Thanks again.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |