Click here to Skip to main content
15,886,519 members
Articles / Desktop Programming / MFC
Article

Disable System Close Button on a Console Application

Rate me:
Please Sign up or sign in to vote.
2.81/5 (23 votes)
6 Dec 2003CPOL 104.2K   3.4K   18   14
This code is a simple way to disable the close button on a Windows Console Application. It can also be used to disable any of the system menu buttons

Introduction

This program is a VERY simple one to demostrate how to disable the close button on a Windows Console App. When I was looking up how to do this, I failed to find anything to help me on the site save the forums.

In reality we simply need to call two separate functions GetSystemMenu() and DeleteMenu(). This same algorithm can be used to disable/enable ANY of the system menu buttons.

The entry point for YOUR code is in the else block after testing for MFC failure.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems / Hardware Administrator
United States United States
Teaching myself Microsoft technologies after initially learning from open source mainly linux/c.
Currently administer a small network of approx. 20 clients. The company I work for has switch to a different more "modern?" dispatch/scheduling solution. I feel all solutions we've found are unsuitable and so I'd like to start my own solution from scratch.


Comments and Discussions

 
Generaleasiest way to disable the close button in console window Pin
rix2-Oct-10 17:07
rix2-Oct-10 17:07 
GeneralRe: easiest way to disable the close button in console window Pin
knestel5-Dec-13 2:35
knestel5-Dec-13 2:35 
Question#include "DisableCloseBtn.h" Pin
000dreamsound00018-Jul-07 5:37
000dreamsound00018-Jul-07 5:37 
AnswerRe: #include "DisableCloseBtn.h" Pin
John L. DeVito18-Jul-07 15:49
professionalJohn L. DeVito18-Jul-07 15:49 
GeneralEasier way Pin
sgtawol7-Aug-06 5:01
sgtawol7-Aug-06 5:01 
Not sure if this was available when you released this solution, but there is an easier way IMO.

http://support.microsoft.com/default.aspx?scid=kb;en-us;201553

2 lines for this fix instead of your 9 line fix.
Questionhow to add item to windows explorer popUp menue Pin
wow_tato24-Dec-03 6:29
wow_tato24-Dec-03 6:29 
GeneralThis one is really easy Pin
Jesterka9-Dec-03 2:55
Jesterka9-Dec-03 2:55 
GeneralRe: This one is really easy Pin
John L. DeVito9-Dec-03 8:22
professionalJohn L. DeVito9-Dec-03 8:22 
QuestionWhy? Pin
dog_spawn7-Dec-03 12:42
dog_spawn7-Dec-03 12:42 
AnswerRe: Why? Pin
hrabe7-Dec-03 22:22
hrabe7-Dec-03 22:22 
GeneralRe: Why? Pin
dog_spawn8-Dec-03 4:33
dog_spawn8-Dec-03 4:33 
GeneralRe: Why? Pin
The___Dude6-Sep-07 9:02
The___Dude6-Sep-07 9:02 
AnswerRe: Why? Pin
John L. DeVito8-Dec-03 5:20
professionalJohn L. DeVito8-Dec-03 5:20 
GeneralRe: Why? Pin
Anthony_Yio10-Dec-03 16:03
Anthony_Yio10-Dec-03 16:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.