Avatar of PalmerEnv
PalmerEnv

asked on 

Determining the source of the WM_CLOSE message.

Hello, people

I am writing an application which is intended to run for very long periods of time. As it is now the application, when minimised, puts an icon in the system tray and happily runs in the background.

I would also like the application to minimise into the system tray when the user clicks in the close button (X button in top right-hand corner) or if they select close from the system menu. Basically I want to be really sure that the user want to close the application and to do this I want them to specifically select Close from the file menu, where they will be prompted to make sure.

I thought that I would implement it in the OnClose handler in the MainFrame class. However, there is no way (well, none that I can find) of determining the WM_CLOSE message's source.

Any help on this would be much appreciated.

Thanks.

System Programming

Avatar of undefined
Last Comment
nonubik
Avatar of nonubik
nonubik

You should implement OnSysCommand(UINT nID, LPARAM lParam) and check whether nID is SS_CLOSE.

The framework calls this member function when the user selects a command from the Control menu, or when the user selects the Maximize/Minimize or Close button.

ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of nonubik
nonubik

I'd like to know what's wrong with my comment, please.
Avatar of PalmerEnv
PalmerEnv

ASKER

Hey,  nonubik.

There's nothing particularly wrong with your answer. I just find AndyAinscow's a little more elegant and easier to implement.
Avatar of nonubik
nonubik

Well, if adding member variables is more elegant....
Avatar of PalmerEnv
PalmerEnv

ASKER

I appreciate that you took time to answer my question, however, I feel that AndyAinscow's solution provides a way of achieving what I want without hassle and, more importantly, quickly.

Again, thanks for taking the time to answer but I will implement AndyAinscow's solution and therefore I think that he deserves the points.
Avatar of nonubik
nonubik

I have no problem with your choice, I just needed some explanation.
System Programming
System Programming

Kernel and system programming is the process of creating the software necessary for a computer or device to function and operate other programs. Some operating systems (such as Microsoft Windows) are proprietary, but others, such as the various Linux distributions, are open source.

41K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo