Issues while closing non modal dialogs in .net running on windows 7
Hello I've a simple c-sharp windows application. I have a button on this form which launches another non modal pop-up form (fixed tool window). Inside the pop-up form i keep tracking the windows message the user performs on the pop-up form. Whenever the user closes the form (pop-up) i set a flag m_bQueryShutdownSent to true, this is to signal the main form to do something.
I use the line
m_bCloseButtonActive = (m.Result.ToInt32() == HTCLOSE);
to track whether the user had clicked the close button and set the flag m_bCloseBu开发者_开发问答ttonActive
#region WndProc
const int WM_NCHITTEST = 0x0084;
const int WM_NCMOUSEMOVE = 0x00A0;
const int HTCLOSE = 0x0014;
const int WM_QUERYENDSESSION = 0x0011;
private bool m_bCloseButtonActive = false;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCHITTEST)
{
base.WndProc(ref m);
m_bCloseButtonActive = (m.Result.ToInt32() == HTCLOSE);
}
else
{
if (m.Msg == WM_QUERYENDSESSION && this.m_oParentForm != null)
this.m_bQueryShutdownSent = true;
base.WndProc(ref m);
}
}
#endregion WndProc
The problem is though this piece of code works on XP / 32bit machines. It doesnt on Windows 7 x64 (though my application is configured to run as a 32bit app). The popup code is not able to handle the close button click action (Windows 7). Though this is possible on 32 bit machines XP/XP-Embedded/2000
Any help in this regard is deeply appreciated
No real clue why you are doing this. You'd normally use the FormClosed event to find out that a form got closed. The e.CloseReason property tells you why, CloseReason.WindowsShutDown is the exact equivalent to checking for WM_QUERYENDSESSION. If you want to make this close-down conditional then use the FormClosing event instead.
This works properly too when the user closes the form by means other than clicking the Close button. Like by pressing Alt+F4, using the system menu or the taskbar button thumbnail in Win7.
精彩评论