How to route a message from MainFrame to Doc and View?

Hello everyone,

I am working on an SDI application called Test. In the 
CTestApp::InitInstance() I create a worker thread to which I pass the HWND of 
the application (*m_pMainWnd) and the message ID. In the worker thread, when 
I post a message using PostMessage() to the main window, I can only catch it 
in the MainFrame. I tryied to catch it in the TestDoc or in the TestView 
without succeeding. From my understanding, whenever the MainFrame receives a 
message it routes it to the documents and views, if it didn't handle it!

1. How could I route the received message in the MainFrame to the TestDoc or 
the TestView?

2. Is it a bad practice to make the MainFrame know the TestDoc or the 
TestView by calling GetActiveDocument() and GetActiveView()?

Thank you,
Geo
0
Geo (129)
11/17/2004 3:32:04 PM
vc.mfc 33608 articles. 0 followers. Follow

12 Replies
503 Views

Similar Articles

[PageSpeed] 22

>I am working on an SDI application called Test. In the 
>CTestApp::InitInstance() I create a worker thread to which I pass the HWND of 
>the application (*m_pMainWnd) and the message ID. In the worker thread, when 
>I post a message using PostMessage() to the main window, I can only catch it 
>in the MainFrame. I tryied to catch it in the TestDoc or in the TestView 
>without succeeding. From my understanding, whenever the MainFrame receives a 
>message it routes it to the documents and views, if it didn't handle it!

MFC message routing only applies to WM_COMMAND messages. See "TN021:
Command and Message Routing" in MSDN.

Dave
0
davidl7375 (2060)
11/17/2004 5:24:44 PM
Thank you Dave,

But then how would I communicate the message content to the Doc or View?

Thanks

"David Lowndes" wrote:

> >I am working on an SDI application called Test. In the 
> >CTestApp::InitInstance() I create a worker thread to which I pass the HWND of 
> >the application (*m_pMainWnd) and the message ID. In the worker thread, when 
> >I post a message using PostMessage() to the main window, I can only catch it 
> >in the MainFrame. I tryied to catch it in the TestDoc or in the TestView 
> >without succeeding. From my understanding, whenever the MainFrame receives a 
> >message it routes it to the documents and views, if it didn't handle it!
> 
> MFC message routing only applies to WM_COMMAND messages. See "TN021:
> Command and Message Routing" in MSDN.
> 
> Dave
> 
0
Geo (129)
11/17/2004 6:41:02 PM
>But then how would I communicate the message content to the Doc or View?

Via the lParam?

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl7375 (2060)
11/17/2004 8:07:41 PM
Dave,

lParam is an argument that I should pass to a function. Could you please 
tell me which function should I call to be able to communicate with the Doc 
or the View.

Thanks

"David Lowndes" wrote:

> >But then how would I communicate the message content to the Doc or View?
> 
> Via the lParam?
> 
> Dave
> -- 
> MVP VC++ FAQ: http://www.mvps.org/vcfaq
> 
0
Geo (129)
11/17/2004 8:50:03 PM
Use WM_NOTIFY. I'm not sure, though, if it gets routed to the document. But 
it gets routed to the active view.

"Geo" <Geo@discussions.microsoft.com> wrote in message 
news:6D43C223-2683-42E4-A2CD-748857C0298F@microsoft.com...
> Thank you Dave,
>
> But then how would I communicate the message content to the Doc or View?
>
> Thanks
>
> "David Lowndes" wrote:
>
>> >I am working on an SDI application called Test. In the
>> >CTestApp::InitInstance() I create a worker thread to which I pass the 
>> >HWND of
>> >the application (*m_pMainWnd) and the message ID. In the worker thread, 
>> >when
>> >I post a message using PostMessage() to the main window, I can only 
>> >catch it
>> >in the MainFrame. I tryied to catch it in the TestDoc or in the TestView
>> >without succeeding. From my understanding, whenever the MainFrame 
>> >receives a
>> >message it routes it to the documents and views, if it didn't handle it!
>>
>> MFC message routing only applies to WM_COMMAND messages. See "TN021:
>> Command and Message Routing" in MSDN.
>>
>> Dave
>> 


0
alegr (1131)
11/17/2004 9:23:42 PM
In your worker thread you only have m_pMainWnd pointer,  you post or send the 
message to your mainframe is reasonable. You certainly get reroute this 
message to Doc and then propogate it to view, even to other objects they 
managed. It is perfect working.

Regards,
Linus

"Geo" wrote:

> Hello everyone,
> 
> I am working on an SDI application called Test. In the 
> CTestApp::InitInstance() I create a worker thread to which I pass the HWND of 
> the application (*m_pMainWnd) and the message ID. In the worker thread, when 
> I post a message using PostMessage() to the main window, I can only catch it 
> in the MainFrame. I tryied to catch it in the TestDoc or in the TestView 
> without succeeding. From my understanding, whenever the MainFrame receives a 
> message it routes it to the documents and views, if it didn't handle it!
> 
> 1. How could I route the received message in the MainFrame to the TestDoc or 
> the TestView?
> 
> 2. Is it a bad practice to make the MainFrame know the TestDoc or the 
> TestView by calling GetActiveDocument() and GetActiveView()?
> 
> Thank you,
> Geo
0
linus1 (4)
11/17/2004 10:14:02 PM
Geo wrote:
> Hello everyone,
> 
> I am working on an SDI application called Test. In the 
> CTestApp::InitInstance() I create a worker thread to which I pass the HWND of 
> the application (*m_pMainWnd) and the message ID. In the worker thread, when 
> I post a message using PostMessage() to the main window, I can only catch it 
> in the MainFrame. I tryied to catch it in the TestDoc or in the TestView 
> without succeeding. From my understanding, whenever the MainFrame receives a 
> message it routes it to the documents and views, if it didn't handle it!
> 
> 1. How could I route the received message in the MainFrame to the TestDoc or 
> the TestView?
> 
> 2. Is it a bad practice to make the MainFrame know the TestDoc or the 
> TestView by calling GetActiveDocument() and GetActiveView()?
> 
> Thank you,
> Geo

The MainFrame already "knows" the TestDoc and TestView.  There's no 
reason not to use GetActiveDocument and GetActiveView (in an SDI app).

-- 
Scott McPhillips [VC++ MVP]

0
Scott
11/17/2004 11:38:33 PM
Linus,

"Linus" wrote:
> In your worker thread you only have m_pMainWnd pointer,  you post or send the 
> message to your mainframe is reasonable. You certainly get reroute this 
> message to Doc and then propogate it to view, even to other objects they 
> managed. It is perfect working.

This is the question, how can I rerout the message to Doc?

Thank you
0
Geo (129)
11/18/2004 12:33:03 AM
Geo wrote:

> Linus,
> 
> "Linus" wrote:
> 
>>In your worker thread you only have m_pMainWnd pointer,  you post or send the 
>>message to your mainframe is reasonable. You certainly get reroute this 
>>message to Doc and then propogate it to view, even to other objects they 
>>managed. It is perfect working.
> 
> 
> This is the question, how can I rerout the message to Doc?
> 
> Thank you

CMyDocument* pDoc = (CMyDocument*)GetActiveDocument();
pDoc->OnMyMessage();

-- 
Scott McPhillips [VC++ MVP]

0
Scott
11/18/2004 1:51:50 AM
>lParam is an argument that I should pass to a function. Could you please 
>tell me which function should I call to be able to communicate with the Doc 
>or the View.

I think you've got the wrong end of the stick from my original reply -
read about using WM_COMMAND messages in the article I mentioned,
WM_COMMAND messages should get routed automatically. If you don't want
to do that,  you have to write your own code to send the message where
you want it.

Dave
0
davidl7375 (2060)
11/18/2004 9:32:58 AM
You communicate with the view by simply doing a SendMessage to the current view. But there
is no way to send a message to a document. One way to avoid this is to create an invisible
top-level window which is the message sink for such messages, then have it call methods of
the document. You might check out my article on adding a timer to a CDocument class (yes,
it made sense!) to see how to do this trick. Not pretty, but it works well. 

Generally, if you are in SDI, it makes no sense to have the thread communicate with the
mainframe when the purpose is to communicate to the view; pass in the CView* pointer to
the thread.
				joe

On Wed, 17 Nov 2004 10:41:02 -0800, Geo <Geo@discussions.microsoft.com> wrote:

>Thank you Dave,
>
>But then how would I communicate the message content to the Doc or View?
>
>Thanks
>
>"David Lowndes" wrote:
>
>> >I am working on an SDI application called Test. In the 
>> >CTestApp::InitInstance() I create a worker thread to which I pass the HWND of 
>> >the application (*m_pMainWnd) and the message ID. In the worker thread, when 
>> >I post a message using PostMessage() to the main window, I can only catch it 
>> >in the MainFrame. I tryied to catch it in the TestDoc or in the TestView 
>> >without succeeding. From my understanding, whenever the MainFrame receives a 
>> >message it routes it to the documents and views, if it didn't handle it!
>> 
>> MFC message routing only applies to WM_COMMAND messages. See "TN021:
>> Command and Message Routing" in MSDN.
>> 
>> Dave
>> 

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
11/21/2004 6:23:32 AM
And, for that matter, there is no reason to pass a message to the main window if it is
destined for the view. Pass it directly to the view. Let the view act as proxy for the
document.
				joe

On Wed, 17 Nov 2004 18:38:33 -0500, "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
wrote:

>Geo wrote:
>> Hello everyone,
>> 
>> I am working on an SDI application called Test. In the 
>> CTestApp::InitInstance() I create a worker thread to which I pass the HWND of 
>> the application (*m_pMainWnd) and the message ID. In the worker thread, when 
>> I post a message using PostMessage() to the main window, I can only catch it 
>> in the MainFrame. I tryied to catch it in the TestDoc or in the TestView 
>> without succeeding. From my understanding, whenever the MainFrame receives a 
>> message it routes it to the documents and views, if it didn't handle it!
>> 
>> 1. How could I route the received message in the MainFrame to the TestDoc or 
>> the TestView?
>> 
>> 2. Is it a bad practice to make the MainFrame know the TestDoc or the 
>> TestView by calling GetActiveDocument() and GetActiveView()?
>> 
>> Thank you,
>> Geo
>
>The MainFrame already "knows" the TestDoc and TestView.  There's no 
>reason not to use GetActiveDocument and GetActiveView (in an SDI app).

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
11/21/2004 6:24:53 AM
Reply:

Similar Artilces:

Message From Field in Folder
When viewing the list of my new messages, is there a way to see the email address of the sender instead of the alias before I open it? In the From column I see "John". When I open the email I see "John <john@johnsemail.com>". I want to see the "john@johnsemail.com" before I open it so I can tell the difference between emails from "Microsoft Support <yourfu@edifyouopenedthis.com>" and "Microsoft Support <someguywhosreally@microsoft.com>" I am currently using outlook 2002 and 2003 alternately based on my mood. Mike If you ...

how to format :send picture with message: as a default
each time i sent a graphic i must go to the format and click "send picture with message." how do I make this a default so it is there permanently.I am running on a Windows XP and am using Outlook Express for my mail. LYNNY <LYNNY@discussions.microsoft.com> wrote: > each time i sent a graphic i must go to the format and click "send > picture with message." how do I make this a default so it is there > permanently.I am running on a Windows XP and am using Outlook Express > for my mail. Ask in an Outlook Express newsgroup. -- Brian Tillman ...

CDO eMail messages not working from FoxPro since installing KB8929
We installed the Exchange 2000 Update (KB892986) and since then our code that creates CDO eMails errors out with the following message: "OLE IDispatch exception code 0 from CDO.Message.1: The transport lost its connection to the server." We are planning to reverse thes updates over the weekend. Does anyone know a better way around this? ...

attachments in inbound messages do not decode #2
I have a problem with an exchange 5.5 server (on NT 4 box). All of a sudden message attachments from a specific outside domain do not decode. See below the attachment just shows up has junk. How do you fix this? Other interesting thing if I forward (either internal or external) the message to anyone the attachment works fine. I have searched but haven't found any pertinent ports. Paul ------------------------------------------------------------------------------------------------------------------- > -----Original Message----- > From: Nolan, Pati > Sent: Friday, November 11...

Messages stuck in Queue with status Active and eventually fail.
I have an exchange 2000 server with SP3. The scenario is this; Everything has been functioning great except emailing to AOL, so I setup a smart host to use our ISP's smtp server. Well, they are getting flagged as open relay and the mail is rejected. So I had them setup a reverse dns lookup for our IP so I could send mail directly. I found a site that allows me to check RBL's and we came up good on about 25 of them, so we aren't black listed. Now we can email aol users without any problems, but all of a sudden, I can't get the server to deliver mail to other exchang...

Message Stuck in Outbox to Only One Particular Email Address
Hi: I have Outlook 2007 and have been using it for about 2 months or so. I have encountered a problem with sending emails. I have sent emails to a particular email address (WinTips-Tricks@yahoogroups.com ) and the emails get stuck in the outbox. The CPU usage is very high (about 76%) and the taskbar icon flashes furiously. If I look in the outbox, the email is also doing a staccato flash. At the bottom of Outlook the send says complete, yet the flashing taskbar icon, and flashing email in the outbox remain. After awhile (about 2-3 minutes) this stops, but the email remains in the outbox....

Help: message "Requesting data from Exchange Server"
Has anyone figure out why we receive the pop-up message "Requesting data from Exchange Server" when we try to open an email in outlook? We are using Exchange 2000. Is there a parameter we can change to fix this issue? "Kenny" <anonymous@discussions.microsoft.com> wrote: >Has anyone figure out why we receive the pop-up >message "Requesting data from Exchange Server" when we >try to open an email in outlook? We are using Exchange >2000. > >Is there a parameter we can change to fix this issue? Depends to a greater or lesser extent ...

alter default view for operations
I'd like to just see parameter types, not names. I don't want to see: methodName( in request : LongRequestObjectName ) : ResponseObjectName I'd like to see: methodName( LongRequestObjectName ) : ResponseObjectName -------------- Justin ...

Messages stuck in Outbox + Heavy CPU load Outlook 2007
Hi, I am using Outlook 2007 with Windows Vista Ultimate. I have a very annoying problem. On a random messages, Outlook "decides" that a certain message will not leave the outbox whatsoever, even if I will write the same message again and again. It happens usually with attachments (usually small ones) but not always. This is what is happening usually: I am writing the message as usual, and trying to send it. In the lower corner, Outlook informs that send/receive was completed successfully but the message remains in the outbox, and somehow blinks a little (if I can describe it ...

Combined view of inboxes. How?
Hi all, I just came back to outlook after years. I'm testing the 2010 beta and god, I'm impressed. One thing though I would like but can't achive; In the favoutites pane, you can set up favourite inbox so you can have a quick glance at what's going on on your favourite account. Great, but I would like to be able to have all inboxes in that place. To be specific, I want all the folders etc as they are now but want to be able to preview all incoming mail from many accounts by clicking just one button. I don't want it to move and merge emails from many inboxes ...

Creating a new default message template
I have a email template that I want to make the default. In other words, when you click on New to create a new email, I want the message template that I have created to come up as the default. Does anyone know how to do this? What you are proposing is a very bad idea. Using a custom form as the = default for new messages will guarantee that non-Outlook recipients = won't be able to read attachments you send.=20 I'd suggest that you back up and explain what functionality you were = hoping to add by changing the message form, and in what version of = Outlook.=20 --=20 Sue Mosher, ...

Outlook message bodies Blank
When I open my email in outlook the body is empty. I seem to remember somethig about my AVG doing something. Any Ideas how to fix this? Thanks Disable the email scanning feature in your anti-virus software. (For example, in AVG, uncheck certify under the email scanning settings.) You'll still be protected by its other features and by Outlook's own security, and new messages shouldn't lose their bodies. Messages you've already received, though, can't be repaired. Hal -- Hal Hostetler, CPBE -- hhh@kvoa.com Senior Engineer/MIS -- MS MVP-Print/Imaging -- WA7BGX http://w...

Calendar Views
I was wondering if there was a way to get the monthly calendar to not show mondays but more importantly to expand the saturday and sunday into there own boxes. No, you cannot hide Mondays. To get the full display of the weekend days, right click in an empty area of the calendar and select Other Settings. Uncheck "Compress Weekend Days." --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without reading. After searching google.grou...

'Signature for new messages' which won't work
Hi, I have Outlook 2003 and if I go to Tools>Options>Mail Format I see I can choose a signature for new messages. I have 3 e-mail accounts set up, and have set a new message signature for each one, e.g.: 1) Home > Sig 1 (default) 2) Work > Sig 2 3) Play > Sig 3 However when I try to create a new e-mail message, it seems impossible to automatically start a new e-mail using my Work or Play accounts, and therefore have the signature automatically entered. So what is the point of this feature if there is no way to use it? I'm sure I'm missing so...

View Tasks in calendar?
Outlook 2003 Can I? I don't mean in that seperate display on the right. Thanks... Bob Only if you create items in your calendar folder either manually or with = a tool like Taskline. --=20 Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for=20 Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx =20 "Bob Newman" <bobnewman@cox.net> wrote in message = news:JK4xh.6009$gJ1.4000@newsfe17.lga... > Outl...

Automatic .Doc Mail merge
Hi All, is there any way or Method of the proxy dll, that allows to execute the mail merge of am Offer / Quote / Order template generating a .Doc document ? Thx Gianluca ...

Not able to view activities
Hi, I have a MS CRM 3.0 VPC running. I have allocated 1GB memory as recommended. However, whenever I try opening Activities(any entity for that matter), it is throwing an error dialog "An error has occured. For more information, contact you system administrator." I checked the event viewer, but there is no information about any error/exception. I searched for the CRM log, but couldn't locate it. Pls help me fix this issue. Thanks and Regards, Mahalax. ...

view multiple public calendars
We have seven public folders set up as calendar for room appointments. How can we view them side by side as shared calendars? The only way I can think of implementing this is to set up 7 user accounts and share their calendars. -- Posted via a free Usenet account from http://www.teranews.com version of outlook? if 2003 or 2007, add them to the public folder favorites and they'll be in the calendar list. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Need Help with Common Tasks? http://www.outlook-tips.net/beginner/ Outlook 2007: http://www.slipst...

Cannot view any form in crm 3.0
We have just installed CRM 3.0 on MS server 2003. I have created an account which has a system administrator role assigned to it. The issue is that when I open CRM web (on the server) when I select account, contact, activities, calendar etc... I get the following error: An error has occured. For more information, contact your system administrator. Now if I open CRM web using an account which has restricted access mode ticked, I don't get any errors, everything opens fine. The problem is that with an restricted access code i can't do much. I have tried assigning different roles ...

Can't view OWA internally
I am unable to view the OWA internally unless I VPN to someone then I can view it. Externally I can view it just fine. Any ideas would be appreciated. How are you attempting to access OWA internally? Are you typing http://servername/exchange, or are you typing a name that has been registered in external DNS? What do you mean when you say you VPN to someone and then view it? You shouldn't need to VPN to anything if you are attached to the same physical network that your Exchange server is on. -- Ben Winzenz Exchange MVP MessageOne "Kyle S" <KyleS@discussions.micr...

How do you edit HTML source in a new outlook email message?
Trying to create a new email message by inserting HTML. I don't see a place to edit source for a new message. This is probably a really easy thing to do, I just can't find out where the "edit source" option is, and the help files don't seem to be any help. Thanks, Justin The feature doesn't exist in Microsoft Outlook. "justinvanderpol" <justinvanderpol@discussions.microsoft.com> wrote in message news:1ADC71DF-40BC-4656-98A8-A473EB40E837@microsoft.com... > Trying to create a new email message by inserting HTML. I don't see a > place ...

Viewing multiple excell spreadsheets on the task bar
Why is it that when I have 3 or more excell spreadsheets open they are not all listed on my task bar the only way I can get to them is by going to the window button and selecting the one I want to see, I want to be able to ALT TAB between them and they are not listing them for me in the task bar only the current one I have open? Are you using XP? Sounds like that feature of XP which groups several windows of one application into one spot on the task bar. There may be a way to shut this off in taskbar properties. Click on the task bar and select properties. "Megan" wrote: ...

New Exchange Routing Group in child domain / site
I have just finished installing a child domain (leaf node) and installing a exchange server for that new domain. First problem I had was that when my email was coming in via the main domain it was sending some of the public folder emails over to the sub domain (witch I had not configured for public folders) So I placed each domain in its own routing group, created a routing connect (both ways) pointing at each other as well as SMTP Connectors with * and cost of 1 (all default settings in each location / routing group. These server will be split via a T1 and both will receive email (ma...

OE Can Compact Messages!
Hi, I repeatedly get the often complained about message from OE; "To free up disk space Outlook Express can compact messages...........". I've read the answers to other posters re this nuisance and have dealt with all "The Usual Suspects". In fact that has been my practice for a long time without ever encountering this problem. It has surfaced only recently with no changes in the PC of which I'm aware. The crowning insult occurred today immediately after I had just completed a total manual compacting. A solution would be greatly appreciated. T...

Can't open up Outlook messages
The Microsoft Outlook screen will appear. When I click on the messages they will not open up. I get a message that Outlook Not Responding. Not sure if a connection problem (Using Road Runner), a server problem or a computer problem. Any advice will be appreciated. I have Windows XP Home Edition installed. Thanks. ...