knowing when (X) button is pushed

X

Xonica Developer

i have this code:
Dim O As System.Diagnostics.StackTrace = New
System.Diagnostics.StackTrace(True)
Dim F As System.Diagnostics.StackFrame
F = O.GetFrame(7)
Select Case F.GetMethod.Name.ToString
Case "SendMessage", "RunDialog" 'close with me.close

Case "CallWindowProc" 'close with (x) button

Case "DispatchMessageW" 'close with Task Manager

Case Else 'booh!

End Select

but don't work!!!!!

i need to know if i have pushed (X) button or me.close
 
M

Morten Wennevik

Hi There,

Testing your code in C# i notice that "DefWndProc" is returned for (X) not
"CallWindowProc".

protected override void OnClosing(CancelEventArgs e)
{
System.Diagnostics.StackTrace O = new System.Diagnostics.StackTrace(true);
System.Diagnostics.StackFrame F = O.GetFrame(7);

switch(F.GetMethod().Name)
{
case "SendMessage":
case "RunDialog":
MessageBox.Show("this.close called");
break;
case "DefWndProc":
MessageBox.Show("(X) clicked");
break;
case "DispatchMessageW":
MessageBox.Show("Task Manager close");
break;
default:
MessageBox.Show("Unknown: " + F.GetMethod().Name);
break;
}
}
 
C

Carlos J. Quintero [.NET MVP]

What does not work? I have done some tests and it works fine for me
(although the approach is quite unreliable)

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top