Click here to Skip to main content
Licence CPOL
First Posted 6 Dec 2003
Views 67,255
Downloads 1,884
Bookmarked 17 times

Disable System Close Button on a Console Application

By John L. DeVito | 6 Dec 2003
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
9 votes, 40.9%
1
2 votes, 9.1%
2
1 vote, 4.5%
3
6 votes, 27.3%
4
4 votes, 18.2%
5
2.64/5 - 22 votes
μ 2.57, σa 2.92 [?]

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)

About the Author

John L. DeVito

Architect
None
United States United States

Member

Follow on Twitter Follow on Twitter
Teaching myself Microsoft technologies after initially learning from open source mainly linux/c.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generaleasiest way to disable the close button in console window Pinmemberrix18:07 2 Oct '10  
Question#include "DisableCloseBtn.h" Pinmember000dreamsound0006:37 18 Jul '07  
AnswerRe: #include "DisableCloseBtn.h" PinmemberJohn L. DeVito16:49 18 Jul '07  
GeneralEasier way Pinmembersgtawol6:01 7 Aug '06  
Questionhow to add item to windows explorer popUp menue Pinmemberwow_tato7:29 24 Dec '03  
GeneralThis one is really easy PinsussJesterka3:55 9 Dec '03  
GeneralRe: This one is really easy Pinmemberkha0s9:22 9 Dec '03  
QuestionWhy? Pinmemberdog_spawn13:42 7 Dec '03  
AnswerRe: Why? Pinsusshrabe23:22 7 Dec '03  
GeneralRe: Why? Pinmemberdog_spawn5:33 8 Dec '03  
GeneralRe: Why? PinmemberThe___Dude10:02 6 Sep '07  
You have to understand everyone’s situation is different.
 
Here’s my first use for this functionality: I have a console app on my server and it will be watching for file activity from user requests over a web service and the console app will act as the gateway to query WDS 3.0 and return the dataset via xml file back to the service for response to the client app. I want to disable the X to make sure "I" don't close it by mistake in one of my click frenzy moments when working on the server and am not use to this service running yet. If i close it by mistake all in process requests and new requests will fail.
 
And my second: This also would be useful for my large OCR processes which scan thousands of pages but due to my OCR's SDK functionality there is no middle ground during processing where i can close the process and not expect it to have to start all over again.
 
So in some instances this method can be used to make sure the user or process has a better experience.
AnswerRe: Why? Pinmemberkha0s6:20 8 Dec '03  
GeneralRe: Why? PinmemberAnthony_Yio17:03 10 Dec '03  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 7 Dec 2003
Article Copyright 2003 by John L. DeVito
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid