473,395 Members | 1,679 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,395 software developers and data experts.

How do I get control when the close box is clicked?

I would like to display a form to get some cleanup instructions when an app
ends. From the Application.exit method my dialog flashes and leaves.
Is there any way to capture the event before it is too late to show a form?

Thanks
Aug 8 '06 #1
7 2400
You can always subscribe to the Closing/Closed event of the main form
for the application.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ne***************@charter.netwrote in message
news:VL*************@fe02.lga...
>I would like to display a form to get some cleanup instructions when an app
ends. From the Application.exit method my dialog flashes and leaves.
Is there any way to capture the event before it is too late to show a
form?

Thanks

Aug 8 '06 #2
That was the first thing I tried because I was already doing other work
there. I even took the example form from the docs and tried to use that just
to see if something was wrong with my code. I got the same thing. The dialog
flashes but does not stay long enough to be seen let alone respond to.

Thanks
Aug 9 '06 #3
I tried writting a message filter hoping to trap the WM_QUIT message. I
never get such a message. Is there something wrong with this filter?

class TracerMessageFilter : IMessageFilter
{ enum WindowsMessageNumbers
{ WM_NULL = 0X0000,
WM_CREATE = 0X0001,
WM_DESTROY = 0X0002,
WM_MOVE = 0X0003,
WM_SIZE = 0X0005,
WM_ACTIVATE = 0X0006,
WM_SETFOCUS = 0X0007,
WM_KILLFOCUS = 0X0008,
WM_ENABLE = 0X000A,
WM_SETREDRAW = 0X000B,
WM_SETTEXT = 0X000C,
WM_GETTEXT = 0X000D,
WM_GETTEXTLENGTH = 0X000E,
WM_PAINT = 0X000F,
WM_CLOSE = 0X0010,
WM_QUERYENDSESSION = 0X0011,
WM_QUERYOPEN = 0X0013,
WM_ENDSESSION = 0X0016,
WM_QUIT = 0X0012,
WM_ERASEBKGND = 0X0014,
WM_SYSCOLORCHANGE = 0X0015,
WM_SHOWWINDOW = 0X0018,
WM_WININICHANGE = 0X001A,
WM_DEVMODECHANGE = 0X001B,
WM_ACTIVATEAPP = 0X001C,
WM_FONTCHANGE = 0X001D,
WM_TIMECHANGE = 0X001E,
WM_CANCELMODE = 0X001F,
WM_SETCURSOR = 0X0020,
WM_MOUSEACTIVATE = 0X0021,
WM_CHILDACTIVATE = 0X0022,
WM_QUEUESYNC = 0X0023,
WM_GETMINMAXINFO = 0X0024,
WM_PAINTICON = 0X0026,
WM_ICONERASEBKGND = 0X0027,
WM_NEXTDLGCTL = 0X0028,
WM_SPOOLERSTATUS = 0X002A,
WM_DRAWITEM = 0X002B,
WM_MEASUREITEM = 0X002C,
WM_DELETEITEM = 0X002D,
WM_VKEYTOITEM = 0X002E,
WM_CHARTOITEM = 0X002F,
WM_SETFONT = 0X0030,
WM_GETFONT = 0X0031,
WM_SETHOTKEY = 0X0032,
WM_GETHOTKEY = 0X0033,
WM_QUERYDRAGICON = 0X0037,
WM_COMPAREITEM = 0X0039,
WM_GETOBJECT = 0X003D,
WM_COMPACTING = 0X0041,
WM_COMMNOTIFY = 0X0044,
WM_WINDOWPOSCHANGING = 0X0046,
WM_WINDOWPOSCHANGED = 0X0047,
WM_POWER = 0X0048,
WM_COPYDATA = 0X004A,
WM_CANCELJOURNAL = 0X004B,
WM_NOTIFY = 0X004E,
WM_INPUTLANGCHANGEREQUEST = 0X0050,
WM_INPUTLANGCHANGE = 0X0051,
WM_TCARD = 0X0052,
WM_HELP = 0X0053,
WM_USERCHANGED = 0X0054,
WM_NOTIFYFORMAT = 0X0055,
WM_CONTEXTMENU = 0X007B,
WM_STYLECHANGING = 0X007C,
WM_STYLECHANGED = 0X007D,
WM_DISPLAYCHANGE = 0X007E,
WM_GETICON = 0X007F,
WM_SETICON = 0X0080,
WM_NCCREATE = 0X0081,
WM_NCDESTROY = 0X0082,
WM_NCCALCSIZE = 0X0083,
WM_NCHITTEST = 0X0084,
WM_NCPAINT = 0X0085,
WM_NCACTIVATE = 0X0086,
WM_GETDLGCODE = 0X0087,
WM_SYNCPAINT = 0X0088,
WM_NCMOUSEMOVE = 0X00A0,
WM_NCLBUTTONDOWN = 0X00A1,
WM_NCLBUTTONUP = 0X00A2,
WM_NCLBUTTONDBLCLK = 0X00A3,
WM_NCRBUTTONDOWN = 0X00A4,
WM_NCRBUTTONUP = 0X00A5,
WM_NCRBUTTONDBLCLK = 0X00A6,
WM_NCMBUTTONDOWN = 0X00A7,
WM_NCMBUTTONUP = 0X00A8,
WM_NCMBUTTONDBLCLK = 0X00A9,
WM_NCXBUTTONDOWN = 0X00AB,
WM_NCXBUTTONUP = 0X00AC,
WM_NCXBUTTONDBLCLK = 0X00AD,
WM_INPUT = 0X00FF,
WM_KEYFIRST = 0X0100,
WM_KEYDOWN = 0X0100,
WM_KEYUP = 0X0101,
WM_CHAR = 0X0102,
WM_DEADCHAR = 0X0103,
WM_SYSKEYDOWN = 0X0104,
WM_SYSKEYUP = 0X0105,
WM_SYSCHAR = 0X0106,
WM_SYSDEADCHAR = 0X0107,
WM_UNICHAR = 0X0109,
WM_KEYLAST109 = 0X0109,
WM_KEYLAST108 = 0X0108,
WM_IME_STARTCOMPOSITION = 0X010D,
WM_IME_ENDCOMPOSITION = 0X010E,
WM_IME_COMPOSITION = 0X010F,
WM_IME_KEYLAST = 0X010F,
WM_INITDIALOG = 0X0110,
WM_COMMAND = 0X0111,
WM_SYSCOMMAND = 0X0112,
WM_TIMER = 0X0113,
WM_HSCROLL = 0X0114,
WM_VSCROLL = 0X0115,
WM_INITMENU = 0X0116,
WM_INITMENUPOPUP = 0X0117,
WM_MENUSELECT = 0X011F,
WM_MENUCHAR = 0X0120,
WM_ENTERIDLE = 0X0121,
WM_MENURBUTTONUP = 0X0122,
WM_MENUDRAG = 0X0123,
WM_MENUGETOBJECT = 0X0124,
WM_UNINITMENUPOPUP = 0X0125,
WM_MENUCOMMAND = 0X0126,
WM_CHANGEUISTATE = 0X0127,
WM_UPDATEUISTATE = 0X0128,
WM_QUERYUISTATE = 0X0129,
WM_CTLCOLORMSGBOX = 0X0132,
WM_CTLCOLOREDIT = 0X0133,
WM_CTLCOLORLISTBOX = 0X0134,
WM_CTLCOLORBTN = 0X0135,
WM_CTLCOLORDLG = 0X0136,
WM_CTLCOLORSCROLLBAR = 0X0137,
WM_CTLCOLORSTATIC = 0X0138,
WM_MOUSEFIRST = 0X0200,
WM_MOUSEMOVE = 0X0200,
WM_LBUTTONDOWN = 0X0201,
WM_LBUTTONUP = 0X0202,
WM_LBUTTONDBLCLK = 0X0203,
WM_RBUTTONDOWN = 0X0204,
WM_RBUTTONUP = 0X0205,
WM_RBUTTONDBLCLK = 0X0206,
WM_MBUTTONDOWN = 0X0207,
WM_MBUTTONUP = 0X0208,
WM_MBUTTONDBLCLK = 0X0209,
WM_XBUTTONDOWN = 0X020B,
WM_XBUTTONUP = 0X020C,
WM_XBUTTONDBLCLK = 0X020D,
WM_MOUSELAST = 0X020D,
WM_MOUSELAST20A = 0X020A,
WM_MOUSELAST209 = 0X0209,
WM_PARENTNOTIFY = 0X0210,
WM_ENTERMENULOOP = 0X0211,
WM_EXITMENULOOP = 0X0212,
WM_NEXTMENU = 0X0213,
WM_SIZING = 0X0214,
WM_CAPTURECHANGED = 0X0215,
WM_MOVING = 0X0216,
WM_POWERBROADCAST = 0X0218,
WM_DEVICECHANGE = 0X0219,
WM_MDICREATE = 0X0220,
WM_MDIDESTROY = 0X0221,
WM_MDIACTIVATE = 0X0222,
WM_MDIRESTORE = 0X0223,
WM_MDINEXT = 0X0224,
WM_MDIMAXIMIZE = 0X0225,
WM_MDITILE = 0X0226,
WM_MDICASCADE = 0X0227,
WM_MDIICONARRANGE = 0X0228,
WM_MDIGETACTIVE = 0X0229,
WM_MDISETMENU = 0X0230,
WM_ENTERSIZEMOVE = 0X0231,
WM_EXITSIZEMOVE = 0X0232,
WM_DROPFILES = 0X0233,
WM_MDIREFRESHMENU = 0X0234,
WM_IME_SETCONTEXT = 0X0281,
WM_IME_NOTIFY = 0X0282,
WM_IME_CONTROL = 0X0283,
WM_IME_COMPOSITIONFULL = 0X0284,
WM_IME_SELECT = 0X0285,
WM_IME_CHAR = 0X0286,
WM_IME_KEYDOWN = 0X0290,
WM_IME_KEYUP = 0X0291,
WM_MOUSEHOVER = 0X02A1,
WM_MOUSELEAVE = 0X02A3,
WM_NCMOUSEHOVER = 0X02A0,
WM_NCMOUSELEAVE = 0X02A2,
WM_WTSSESSION_CHANGE = 0X02B1,
WM_TABLET_FIRST = 0X02c0,
WM_TABLET_LAST = 0X02df,
WM_CUT = 0X0300,
WM_COPY = 0X0301,
WM_PASTE = 0X0302,
WM_CLEAR = 0X0303,
WM_UNDO = 0X0304,
WM_RENDERFORMAT = 0X0305,
WM_RENDERALLFORMATS = 0X0306,
WM_DESTROYCLIPBOARD = 0X0307,
WM_DRAWCLIPBOARD = 0X0308,
WM_PAINTCLIPBOARD = 0X0309,
WM_VSCROLLCLIPBOARD = 0X030A,
WM_SIZECLIPBOARD = 0X030B,
WM_ASKCBFORMATNAME = 0X030C,
WM_CHANGECBCHAIN = 0X030D,
WM_HSCROLLCLIPBOARD = 0X030E,
WM_QUERYNEWPALETTE = 0X030F,
WM_PALETTEISCHANGING = 0X0310,
WM_PALETTECHANGED = 0X0311,
WM_HOTKEY = 0X0312,
WM_PRINT = 0X0317,
WM_PRINTCLIENT = 0X0318,
WM_APPCOMMAND = 0X0319,
WM_THEMECHANGED = 0X031A,
WM_HANDHELDFIRST = 0X0358,
WM_HANDHELDLAST = 0X035F,
WM_AFXFIRST = 0X0360,
WM_AFXLAST = 0X037F,
WM_PENWINFIRST = 0X0380,
WM_PENWINLAST = 0X038F,
WM_APP = 0X8000,
}
public bool PreFilterMessage (ref Message m)
{ ShowWindowsMessage(m.Msg);
return false;
}
private void ShowWindowsMessage (int msgno)
{ WindowsMessageNumbers mymsg = (WindowsMessageNumbers) msgno;
Console.WriteLine("Message Number " + msgno.ToString()
+ "---" + string.Format("{0:X}", msgno)
+ "---" + mymsg.ToString());
}
}
Aug 9 '06 #4
It seems that an Application IFilter only gets a few of the messages. If I
get the messages at the WNDPROC for the form I am interested in I can do
what I want but this seems to be much more work than it should be.

protected override void WndProc(ref Message m)
{ MTGStatic.WindowsMessageNumbers mymsg = (MTGStatic.WindowsMessageNumbers)
m.Msg;
switch (mymsg)
{ case MTGStatic.WindowsMessageNumbers.WM_SYSCOMMAND:
MTGStatic.WindowsSystemCommands mycommand =
(MTGStatic.WindowsSystemCommands) m.WParam;
switch (mycommand)
{ case MTGStatic.WindowsSystemCommands.SC_CLOSE:
MTGTracer.AskStatusQuestions();
break;
}
break;
}
base.WndProc(ref m);
}
Aug 9 '06 #5
ne***************@charter.net wrote:
That was the first thing I tried because I was already doing other work
there. I even took the example form from the docs and tried to use that just
to see if something was wrong with my code. I got the same thing. The dialog
flashes but does not stay long enough to be seen let alone respond to.
Are you opening the other form with Show() or ShowDialog()? Calling
ShowDialog in OnClosing should work! If not, please post the shortest
possible working program to demonstrate the problem.

Max
Aug 9 '06 #6
I had tried both and neither worked.

If I make a simple application. Use the wizzard and then copy the example
dialog code from the docs it works as you said it would, so I must have
something else going on to mess things up.

It even works if I put the dialog after the run statment in the main
function.

I guess more digging is in order.

Thanks
Tom
Aug 10 '06 #7
In the closing event, try

e.Cancel = true;

When you want to cancel closing the form.

ne***************@charter.net wrote:
I had tried both and neither worked.

If I make a simple application. Use the wizzard and then copy the example
dialog code from the docs it works as you said it would, so I must have
something else going on to mess things up.

It even works if I put the dialog after the run statment in the main
function.

I guess more digging is in order.

Thanks
Tom
Aug 10 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tim Graichen | last post by:
Hello, I am making use of the Active X calendar control (mscal.Calendar.7) in several places in my main form, with the following code Below is an example of the code I'm using for the...
3
by: hermawih | last post by:
Please help . I want to load the contents of another rtf document by double-clicking the words . Chapter1.rtf Chapter2.rtf Chapter3.rtf ....
1
by: mhnazly | last post by:
i'm trying to read data from SQL Server database using data reader and assigned it to a label in my asp.net web application. but when the button is clicked, nothing appears. please help, thanks. ...
1
by: Roz Lee | last post by:
I have a page with two textboxes and two buttons which post back to the server. I want to detect which button has been clicked for testing purposes preferably clientside, but otherwise serverside....
7
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
6
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I...
7
by: Siv | last post by:
Hi, I have an MDI application that uses a generic "ShowPage" routine in a module that is called when I want to display a child form. The basic idea is that in the module I have declared each form...
4
by: James Page | last post by:
I can't seem to get HtmlTextWriter / renderControl to work for sending a control (html) in an e-mail messsage (VB.NET). Keeps telling me that control needs to be in a form tag with runat server...
6
by: hemant.singh | last post by:
Hi all, I am trying to get a way by which I'll know exactly when user goes out of my site by clicking on close button in browser, So that w/e user click close button in browser, I can send a...
1
by: Swans, What Swans? | last post by:
I have a form with (among other controls) three text boxes that hold date fields from the underlying ControlSource. I have the OnDoubleClick event for each set to open up a Modal Popup form that...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.