We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Analog to WM_CLOSE handling

Thread ID:

Created:

Updated:

Platform:

Replies:

20834 Oct 26,2004 03:14 PM UTC Jul 12,2005 08:30 AM UTC WinForms 5
loading
Tags: FAQ
Administrator [Syncfusion]
Asked On October 26, 2004 03:14 PM UTC

Hi. I have a GDBG in which I''d like to ensure that the user has the option to save any unsaved changes when the application is being shut down. In the C/C++ world, I would handle WM_CLOSE or WM_DESTROY for the window or control I''m coding. What should I use in .NET? Thanks, Andy

Holger Persch
Replied On October 27, 2004 03:19 AM UTC

Hi Andy, You can handle the form''s "Closing" event. The CancelEventArgs is providing a "Cancel" member that can be used to prevent closing the form. Regards, Holger Persch

Administrator [Syncfusion]
Replied On October 27, 2004 09:02 AM UTC

I''m actually looking for a way to hook into the closing of a UserControl-derived control as opposed to a form. At the Windows SDK level, I know that WM_DESTROY (or WM_CLOSE) will always be called for every window. So if I create a custom control, that control will receive a WM_DESTROY message when that control is being destroyed no matter what the reason (be it application shutdown, or some other user-generated reason). I saw that UserControl has a HandleDestroyed event which looked promising. But it does not appear to be fired at the time that the user closes the tab-page in which my control resides (it gets called later when shutting down the app). >Hi Andy, > >You can handle the form''s "Closing" event. The CancelEventArgs is providing a "Cancel" member that can be used to prevent closing the form. > >Regards, >Holger Persch

Holger Persch
Replied On October 28, 2004 03:02 AM UTC

Hi Andy, What''s about this? protected override void WndProc(ref Message message) { if (message.Msg == 0x0002 /* WM_DESTROY */) { } base.WndProc(ref message); } Regards, Holger

Administrator [Syncfusion]
Replied On October 28, 2004 01:52 PM UTC

Thanks for your help. What I''ve done, temporarily, is to add some code that calls the control''s parent''s dispose method when that control is being closed. This forces an immediate call to HandleDestroyed in which I can manage saving any unsaved changes. >Hi Andy, > >What''s about this? > >protected override void WndProc(ref Message message) >{ > if (message.Msg == 0x0002 /* WM_DESTROY */) > { > } > > base.WndProc(ref message); >} > >Regards, >Holger

Sharad Sharma
Replied On July 12, 2005 08:30 AM UTC

Hi Andy, I found this page while searching a solution for "incorporating a user control (with a combobox and a button) into a GridDataBoundGrid (not the normal GridControl)". Can you help me out in this probles as much as you can. Thanks and regards. KAPIL S. >I''m actually looking for a way to hook into the closing of a UserControl-derived control as opposed to a form. > >At the Windows SDK level, I know that WM_DESTROY (or WM_CLOSE) will always be called for every window. So if I create a custom control, that control will receive a WM_DESTROY message when that control is being destroyed no matter what the reason (be it application shutdown, or some other user-generated reason). > >I saw that UserControl has a HandleDestroyed event which looked promising. But it does not appear to be fired at the time that the user closes the tab-page in which my control resides (it gets called later when shutting down the app). > > >>Hi Andy, >> >>You can handle the form''s "Closing" event. The CancelEventArgs is providing a "Cancel" member that can be used to prevent closing the form. >> >>Regards, >>Holger Persch

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;