A Question on Message routing in Visual C++
Mihir Dalal -- m_dalal@ECE.concordia.CA
Wednesday, December 04, 1996
Environment: MSVC 1.52, Windows 95
Hi,
I have the following two applications which I intend to run
simulataneously.
1. A MFC SDI application with a form view with a couple of controls over
it.
2. A small application written in C using the Windows SDK to handle modem
communications.
My requirement is to make the two of them communicate with each other
via messages.
At one point when the second application has focus, I broadcast a user
defined message intended to be processed by the view class of the
first application (which temporarily does not have focus, but is still a
top level window).
My problem: The message does reach the main frame of the first
application, but is not routed further down to the view class where I
have a message handler for that message, using which I intend to
disable/enable certain controls on the form view.
Why is it so ?? When an application loses focus, does it mean that its
message routing mechanism gets disabled ??
Also, since I am able capture the message in the main frame class, is
there a way I can access the form view controls of the view class in the
main frame class.
If someone could help.
Mihir.
(University Researcher)
Mike Blaszczak -- mikeblas@nwlink.com
Saturday, December 07, 1996
[Mini-digest: 3 responses]
At 13:43 12/4/96 -0500, Mihir Dalal wrote:
> Environment: MSVC 1.52, Windows 95
>My problem: The message does reach the main frame of the first
>application, but is not routed further down to the view class where I
>have a message handler for that message, using which I intend to
>disable/enable certain controls on the form view.
>Why is it so ??
MFC doesn't rout messages; it routes commands.
The message you're sending is sent, by Windows, to top-level windows
on the desktop. MFC implements the message proc for that one window in
question, and gets the message. It offers it to the object which represents
the frame window in your application. That object is built from a hierarchy
of classes: you've probably derived your own class from CFrameWnd to make
the window, and CFrameWnd is, in turn, derived from CWnd. Code in your
class, CFrameWnd, and CWnd is offered (in that order) a chance to handle
the message.
If nobody out of that list handles the message, it's sent to the Windows
DefaultWindowProc().
MFC routes commands, which sometimes show up as OLE automation method
invocations or as WM_COMMAND messages from controls or menus. Since the
message you posted isn't a WM_COMMAND message, MFC isn't routing it.
>When an application loses focus, does it mean that its
>message routing mechanism gets disabled ??
No.
>Also, since I am able capture the message in the main frame class, is
>there a way I can access the form view controls of the view class in the
>main frame class.
In the frame, get the active view by calling GetActiveView(). On the
returned CView*, call GetDlgItem().
.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.
-----From: "Randy Taylor"
Send a WM_COMMAND message with
the WPARAM equal to an integral value like ID_MY_BEAUTIFULCOMMAND.
Override CFrameWnd::OnCmdMsg to get the message to your
view even if that view is not active.
randy_taylor@ebt.com
----------
> From: Mihir Dalal
> To: mfc-l@netcom.com
> Subject: A Question on Message routing in Visual C++
> Date: Wednesday, December 04, 1996 1:43 PM
>
>
>
> Environment: MSVC 1.52, Windows 95
> Hi,
>
> I have the following two applications which I intend to run
> simulataneously.
>
> 1. A MFC SDI application with a form view with a couple of controls over
> it.
>
> 2. A small application written in C using the Windows SDK to handle modem
> communications.
>
> My requirement is to make the two of them communicate with each other
> via messages.
>
> At one point when the second application has focus, I broadcast a user
> defined message intended to be processed by the view class of the
> first application (which temporarily does not have focus, but is still a
> top level window).
>
> My problem: The message does reach the main frame of the first
> application, but is not routed further down to the view class where I
> have a message handler for that message, using which I intend to
> disable/enable certain controls on the form view.
>
> Why is it so ?? When an application loses focus, does it mean that its
> message routing mechanism gets disabled ??
>
> Also, since I am able capture the message in the main frame class, is
> there a way I can access the form view controls of the view class in the
> main frame class.
>
> If someone could help.
>
> Mihir.
> (University Researcher)
>
>
-----From: Shaju Mathew
>
>
>
> Environment: MSVC 1.52, Windows 95
> Hi,
>
> I have the following two applications which I intend to run
> simulataneously.
>
> 1. A MFC SDI application with a form view with a couple of controls over
> it.
>
> 2. A small application written in C using the Windows SDK to handle modem
> communications.
>
> My requirement is to make the two of them communicate with each other
> via messages.
>
> At one point when the second application has focus, I broadcast a user
> defined message intended to be processed by the view class of the
> first application (which temporarily does not have focus, but is still a
> top level window).
>
> My problem: The message does reach the main frame of the first
> application, but is not routed further down to the view class where I
> have a message handler for that message, using which I intend to
> disable/enable certain controls on the form view.
>
> Why is it so ?? When an application loses focus, does it mean that its
> message routing mechanism gets disabled ??
I'm not surprised - recently I had a similar problem in which my treecontrol
(which's a child of a CDialogBar maintained by my MDI mainframe) messages
were routed only to the CMainFrame class and I had to do all the handling
from CMainFrame, even though I had a std Doc-View template going.
>
> Also, since I am able capture the message in the main frame class, is
> there a way I can access the form view controls of the view class in the
> main frame class.
>
Use GetActiveView() as in
(CFrameWnd*)AfxGetApp()->m_pMainWnd)->GetActiveView());
> If someone could help.
>
> Mihir.
> (University Researcher)
>
>
Hope this helps..>
>
--
***********************************************************************
.---. .---.
Shaju Mathew /" " \ WWW / " "\ Off:(916)785-9018
Performance Technology Lab / / "" \(*|*)/ "" \ \
Hewlett-Packard Company ////// '. V .` \\\\\\ Home:(916)722-4576
8000, Foothills Blvd //// / // : """ : \\ \ \\\\
MS 5723, Roseville // / / /`.""" '\ \ \ \\Fax:(916)785-1264
CA 95747-5723 // //.".\\ \\
------------- -UU---UU---------------
Shaju_Mathew@hp.com '//|||\\`
'' ``
***********************************************************************
| Вернуться в корень Архива
|