Click here to Skip to main content
12,702,455 members (36,007 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ Win32
Hi, I have a "Really quit?" dialog that pops up when the user presses the Close button on my application.

However, I _only_ want this dialog to appear when the user presses the close button or the ESC key, not when an external source (e.g. Windows Shutdown or the Uninstall tool) sends the WM_CLOSE message. I.e. it should close immediately on shutdown / logoff / when uninstalling and all other external cases.

What would be the correct way to check for this?
Posted 6-Jun-12 15:18pm
Updated 6-Jun-12 15:31pm
SAKryukov 6-Jun-12 20:28pm
Aha! You are going to close your application by a message from another process! It does not look like a good design...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

you can spot the system wanting to shutdown with the System Shutdown messages[^]

As far as uninstall is concerned, it's probably easiest to create a Custom Action[^] in your installer that only occurs at REMOVE which sends a registered message to your application
Mohibur Rashid 6-Jun-12 22:11pm
Very useful
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you really want to do it through direct handling of WM_CLOSE and then cancel closing, look at the message description:[^].

As you can see, the message does not have parameters except message ID, so you don't have any information on the cause of the message.

If you wanted to prevent closing unconditionally, you would need in WM_CLOSE message handler, you would need to return TRUE from WinProc, without calling the DefWindowProc function, but if you need to do it on the condition related to the source of the message, you don't receive anything which gives you a clue.

You should do some work-around. Insider the application, devise a custom message like "WM_USER_CLOSING", send it inside the application process, handle it, and actually close the window or not, depending on the user's decision. It won't affect a handling of the message WM_CLOSE sent from external application, just as you wanted. But — please see my comment to the question; probably you can create better application design instead.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 6 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100