473,394 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Prevent Window Closure on Application Exit

Oralloy
988 Expert 512MB
I am building a command-line application which writes messages to the terminal as it processes. There is no GUI for this applicaion.

Currently I run from the command line, although in "normal use", our field-service people will just double-click on the image name in the explorer.

Normally the program just runs "silently", and the window should close at end of execution. QED.

When a failure occurrs, then I would like for my field people to capture the output and send a copy to me.
  • This lets us "fix" the problem immediately, resulting in happy customer.
  • Avoids scheduling a second customer-site visit.
  • Upgrades cause minimal customer down-time.

When I did something similar to this years ago, I remember setting a bit somewhere (a properties check-box) that prevented window closure.

I have looked for this check-box on the "Command Prompt" window properties (alt-space|Properties) and on the menu-item properties (right-mouse|Properties}. Neither seems to provide a suitable property.

What am I missing?

Do you have any suggestions?

Thank You,
Oralloy
Sep 23 '16 #1

✓ answered by Luuk

To disable the Close button in the caption dynamically, you enable and disable the SC_CLOSE menu item in your system menu.
Expand|Select|Wrap|Line Numbers
  1. void DisableCloseButton(HWND hwnd)
  2. {
  3.  EnableMenuItem(GetSystemMenu(hwnd, FALSE), SC_CLOSE,
  4.                 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
  5. }
  6.  
  7. void EnableCloseButton(HWND hwnd)
  8. {
  9.  EnableMenuItem(GetSystemMenu(hwnd, FALSE), SC_CLOSE,
  10.                 MF_BYCOMMAND | MF_ENABLED);
  11. }

1 3893
Luuk
1,047 Expert 1GB
To disable the Close button in the caption dynamically, you enable and disable the SC_CLOSE menu item in your system menu.
Expand|Select|Wrap|Line Numbers
  1. void DisableCloseButton(HWND hwnd)
  2. {
  3.  EnableMenuItem(GetSystemMenu(hwnd, FALSE), SC_CLOSE,
  4.                 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
  5. }
  6.  
  7. void EnableCloseButton(HWND hwnd)
  8. {
  9.  EnableMenuItem(GetSystemMenu(hwnd, FALSE), SC_CLOSE,
  10.                 MF_BYCOMMAND | MF_ENABLED);
  11. }
Jan 6 '18 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Guinness Mann | last post by:
Pardon me if this is not the optimum newsgroup for this post, but it's the only .NET newsgroup I read and I'm certain someone here can help me. I have a C# program that checks for an error...
4
by: Karin | last post by:
Are there any situations when you cannot use Application.Exit? I have a class Error with a static function LogError and a static counter Errors. If more than 10 errors occur during 1 minute I want...
1
by: Brendan Miller | last post by:
I am trying to close my application using Application.exit() in the frmMain_Closing event. When the form closes the process does not. My application only has one form (no other classes either). ...
4
by: Chuck | last post by:
Hello everybody, I need to abort execution during start up, while the constructor called by Application.Run is executing. If the database fails to connect during my application's startup I...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
1
by: Ioannis Vranos | last post by:
I am currently reading a chapter involving multithreading, and some sample code calls Environment::Exit() to terminate the application with all threads. What is the difference from...
4
by: Bob Day | last post by:
Using VS 2003, VB.net... I am confused about the Application.Exit method, where the help states "This method does not force the application to exit." Aside from the naming confusion, how do I...
2
by: cweeks | last post by:
When the user clicks on my Exit menu command I call Close() followed by Application.Exit(). The GUI goes away as expected but the process is still listed in Task Manager. What do I need to do to...
1
by: =?Utf-8?B?VGFvZ2U=?= | last post by:
Hi All, When I use applcation.exit() in winForm application, the form closed, but the process is still going!! ( The debug process is still running if debug in VS IDE). Environment.Exit(0) works...
6
nev
by: nev | last post by:
when i click the 'x' box of a form to exit i get the Error creating window handle. but when i use my file menu exit menuitem which does... Global.System.Windows.Forms.Application.Exit() my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.