473,385 Members | 2,005 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,385 software developers and data experts.

WndProc method

I am trying to use this method to capture a user pressing the "X" in the
upper right-hand corner. I tried using the following code, but anytime I
exit the program it gets hit no matter what I press.

if(m.Msg == 0x0010) { //X button location

MessageBox.Show("Yeah i am close button here");

}

base.WndProc(ref m);

}
Nov 16 '05 #1
3 4362
Why not to use Closed/Closing event instead?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"John S" <jo********@cinfin.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I am trying to use this method to capture a user pressing the "X" in the
upper right-hand corner. I tried using the following code, but anytime I
exit the program it gets hit no matter what I press.

if(m.Msg == 0x0010) { //X button location

MessageBox.Show("Yeah i am close button here");

}

base.WndProc(ref m);

}

Nov 16 '05 #2
John,

When u exit the application either by pressing X button or from menu,
WM_CLOSE message is fired and its caught in the wndproc.

If you want to cancel the close operation after hiting close, you have to
use CancelEventArgs in Form_closing event.

The alternative way to code in File->Exit is to use

Application.ExitThread();

This wont hit wndproc. It will force the application to exit.
--
Shak
(Houston)
"John S" <jo********@cinfin.com> wrote in message
news:#h**************@TK2MSFTNGP10.phx.gbl...
I am trying to use this method to capture a user pressing the "X" in the
upper right-hand corner. I tried using the following code, but anytime I
exit the program it gets hit no matter what I press.

if(m.Msg == 0x0010) { //X button location

MessageBox.Show("Yeah i am close button here");

}

base.WndProc(ref m);

}

Nov 16 '05 #3
Hi,

You can by looking for non-client mouse message and then checking the
hittest value.

const int WM_NCLBUTTONDOWN = 0x00A1;
const int HTCLOSE = 20;

protected override void WndProc(ref Message m)
{
if ( m.Msg == WM_NCLBUTTONDOWN &&
m.WParam.ToInt32() == HTCLOSE )
{
Console.WriteLine( "X pressed");
}
base.WndProc (ref m);
}

HTH,
greetings

"John S" <jo********@cinfin.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I am trying to use this method to capture a user pressing the "X" in the
upper right-hand corner. I tried using the following code, but anytime I
exit the program it gets hit no matter what I press.

if(m.Msg == 0x0010) { //X button location

MessageBox.Show("Yeah i am close button here");

}

base.WndProc(ref m);

}

Nov 16 '05 #4

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

Similar topics

6
by: Turbo_King | last post by:
Hi, I am trying to write a class which creates a window and then assigns a method of the class as the wndproc function for the window so that each instance of the class can handle the messages...
0
by: sshuangw | last post by:
Hello: I am encountering a very weird issue with MDI child, Overriden WndProc function and hidden form. Basically, the application has two forms, Form1(parent form), Form2(Child form),...
2
by: Ed Sutton | last post by:
How can a WndProc be created inside a component? Currently I have a WndProc in my frmMain. It looks for WM_DEVICECHANGE messages for connection and removal events for a USB/Serial device. My...
0
by: han.phony | last post by:
Hi, I am trying to intercept the message sent back by winmm.dll's mciSendString method when playback is finished. I tried to override the WndProc in the form but I didn't get/intercept the message,...
2
by: dworthem | last post by:
if I have the compiler option /clr:oldSyntax in a Windows Forms application protected: void WndProc(System::Windows::Forms::Message* m) is called If I remove oldSyntax protected:
2
by: Phuff | last post by:
I have an application that should run in the system tray while open. It is supposed to be open at all times and I need it to dissapear when the "X" button is pushed on the form...but without...
2
by: Chris Ashley | last post by:
Hi, I'm overriding WndProc to process some custom messages like so: protected override void WndProc(ref Message m) { if (m.Msg == ImageFileMsg.MSG_IF_NEW_DATA) { ProcessNewDataMessage(m);
4
by: Rob | last post by:
I've constructed a user control inherited from ListView so I can handle and respond to scrolling events (to keep 2 listviews scrolling in sync). My user control includes an Overrides of WndProc...
6
by: --== Alain ==-- | last post by:
Hi, How can i do if i want to subclass WndProc from a control to MyNewWndProc ? in fact i have a UserControl on which i have another control (ListVire). And i want to subclass the WndProc of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.