mfc >> Identifying window to send message to

by Jenson » Mon, 01 Dec 2003 20:46:30 GMT

Assuming an MDI application in which many identical child
windows are open in the client area, if the user clicks the
close button on one of them, how does Windows send the
WM_CLOSE event only to that window? Is it using the window
handle? Basically trying to know how Windows distinguishes
between messages to be sent to different windows the
application owns.

TIA,
Jenson


mfc >> Identifying window to send message to

by Ali R. » Tue, 02 Dec 2003 00:20:56 GMT


The short answer to your question is yes, windows uses the windows hWnd to
send a message to a particular window. In the case of the close button, it
is owned by the a window, and once it is clicked it will send a WM_CLOSE
message to it's owner (parent) window. Take a look a the SendMessage
function (Not CWnd::SendMessage but the api ::SendMessage).

Ali R.








mfc >> Identifying window to send message to

by Jenson » Tue, 02 Dec 2003 21:46:57 GMT

At a broader level, how does Windows first identify
the application to which the message is to be sent to?
Say, in a simple dialog based app, if the user clicks a
button, how is the message routed to the application's
message queue? What goes on internally?

Jenson.

the windows hWnd to
close button, it
send a WM_CLOSE
SendMessage
api ::SendMessage).
message

child
the
window
distinguishes


Identifying window to send message to

by Scott McPhillips [MVP] » Wed, 03 Dec 2003 08:15:05 GMT





Play around with the Spy++ tool that comes with VC. You will see that
Windows has a tree-like list of all top level windows, and their child
windows, and a bunch of properties for every one of these windows. One
of the properties is Z-order, so Windows also knows what is on top of
what. It handles mouse, keys and painting by running up and down these
lists.

When a button is clicked Windows must perform a hit-test algorithm to
figure out which window was clicked, then it sends the mouse messages to
that window. If the window is a button the button code reacts by
sending a click message to its parent window.

--
Scott McPhillips [VC++ MVP]



Similar Threads

1. How to send message to all window(include child window)

Hi,

	How to send a message to every window(include child window),
I use SendMessage ,but It can't do that.
	
	class frmA
	{
		public const int WM_test = 0x400 + 1;
		protected override void WndProc(ref Message m) 
		{
			// Listen for operating system messages.
			switch (m.Msg)
			{
				case WM_test:
					MessageBox.Show(WM_test.ToString());						break;                
			}
			base.WndProc(ref m);
		}
		private void button1_Click(object sender, System.EventArgs e)
		{
			try
			{
				IntPtr nullhandle = IntPtr.Zero;
				int i = SendMessage((int)this.Handle,WM_test,0,0);
				//send ok,i == 1,popup messagebox
				int i = SendMessage((int)nullhandle,WM_test,0,0);
				//i == 0,do nothing
			}
			catch(Exception ep)
			{
				MessageBox.Show(ep.Message);
			}
		}
	}

	void func()
	{
		frmA frmTestA = new frmA();
		frmA frmTestB = new frmA();
		frmTestA.show();
		frmTestB.show();
	}
	//now when i push the frmTestA button1,I want to send the WM_test msg to 
frmTestA and frmTestB,how to do this?
	Is there any designed patterns can implement my request?

best regarsd,

Harvie


2. Sending Window Messages from an MFC app to a Windows Firm tray application

3. Sending message to another window

I have an application using dial monitors which is used in an aution room.

The auctioneer has a form showing details of the current lot number.  As 
he changes to the next lot number I need to send a message to a form on 
the other monitor to change to picture to this new lot.

Shat is the best way to have a form send a message to another form.

ie Monitor one is showing lot 10 details and the monitor two is showing 
the picture of lot 10.  The auction moves to the next lot on his screen 
(lot 11) and the form on the second monitor now updates with the details 
of lot 11.

Regards
Jeff

4. send/post a message to a window - CSharp/C#

5. Send Message to Windows Service

Hi!

I want to develop two applications one a Windows Service and the other a GUI 
based application. I want some sort of communication between Service and 
GUI. I have decided to use Remoting for this purpose.

For this I registered an object on Service side for Remoting purposes. 
Remote Object exposes a function named ReloadFiles() that should internally 
send a message to service class to Reload some files. Now I don't know how 
to send message to that service class because Remote Object doesn't have a 
reference to service.

Anybody there to give me a helping hand.


Thanks in advance.

Ahmad Jalil Qarshi 


6. How to receive message sent from another window? - CSharp/C#

7. Unable to Send text message to child window

hi,

 From My MFC Application I create a modless window on the click of a
button. From the same clicking function I assign a value to an edit
box( CString value).

	CTestModless *p;
	p = new CTestModless;
	p->Create (CTestModless::IDD, GetDesktopWindow());

	CRect rSize ;
	p->GetWindowRect(&rSize);
	p->MoveWindow(10,10, rSize.Width(), rSize.Height());
	p->ShowWindow(SW_SHOW);

	GetDlgItem (IDC_BUTTON2)->EnableWindow(FALSE);

	p->ShowWindow(SW_SHOW);



	p->m_strD1Bc1 = "123";
	p->UpdateData(FALSE);

But it is giving an error telling there is some problem on doing
UpdateData()
.
What could be the reason.
pls help.
Thanx in advance.
Neo.

8. Message Sending from a Control to MainFrame Window