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
496 Views

Similar Articles

[PageSpeed] 1

>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:

Printing WORD docs from a form
I have a button on a form and I want it to print a Word mail merge document that contains data from the database that is linked to my application. I'm using the following code but always get a 5922 error - Word can't open the source... All variable names contain valid data, so that's NOT the problem. With appWord .Visible = True .Documents.Open pathdocname With .ActiveDocument.MailMerge .MainDocumentType = wdFormLetters strConnection = "DSN=MS Access Databases;" _ & "DB...

Painting in Mainframe Window
Hi All How can i paint inside a Mainframe Window of MDI Application..... Suppose i want a Text Message there "BLAH BLAH" Tell Where to put my Code in WM_Paint .????? Thanxs Ashutosh there is a class -- CLogoMdi in demo classes of CxImage599a (http://www.xdp.it/) that may help you. though in fact i don't understand the usage of SubclassWindow(in the demo, m_LogoMdiClientWnd.SubclassWindow(m_hWndMDIClient) ). can someone tell me? thanks. "Ashutosh" <efextra@efextra.com> д����Ϣ���� :uUM1tSWlEHA.592@TK2MSFTNGP11.phx.gbl... > Hi All > How can i paint ins...

Cashier-to-cashier and store-to-store messages
I have looked breifly at the Messages function within Store Operations manager. It seems like a pretty basic way to send simple one-off messages from cashier to cashier (more often, from manager to cashier). This is a good start, but I want to expand upon it. I would like to be able to dynamically create messages based on certain system actions (groups of items are put on sale, a purchse order is received, commission rate changes on a group of items, etc). I would like to have standard message templates which can be populated with item or customer information. Taking this to the next ...

Outlook Mobile service
Hi all, I have added an OMS account and sent a test message from the Accounts set up area no problem. I shut down and restarted Outlook 2007 as instructed but no matter what I do I cannot find a Text Message option in the "New" drop down or from the "File/New" on the Menu???? I can see the account under the options if I go to create a new email account but if I try typing in a mobile number it just refuses to do anything. Anyone have any ideas? I have searched MS help and Google without any luck. An associated but possibly unrelated issue is that I cannot see a Mobile a...

how to send a message to a distribution list
I have forwarded mail and i wish to send it to a distribution list. please tell me the steps to be followed. Also please let me know how to send a new mail to a distribution list Suresh wrote: > I have forwarded mail and i wish to send it to a distribution list. > please tell me the steps to be followed. Also please let me know how > to send a new mail to a distribution list I'm not sure what you're asking exactly. You send email to email addresses - are you talking about personal distribution lists in Outlook? Please post by including a concise summary of your question i...

Does a View have and ID?
I know controls have ID's, Dialogs have ID's, but does a View have and ID? If not, Is there something in CWnd I can use to set an ID for a View? Thanks, -- Tea Ear grey Hot. Tea Ear grey Hot Damn you. Hi, "Computer" wrote: > I know controls have ID's, Dialogs have ID's, but does a View have and ID? > If not, Is there something in CWnd I can use to set an ID for a View? > Yes, controls and dialogs have ids. But these ids may not be always applicable; one may create a button with an ID = 1 hoping that he will not use the id. In other words,having a ...

Message Tracking Database is Not Available
I receive a message when I attempt to search for a message that says "The Tracking Database on the Server is not Available or the message has left the Exchange Organization" Facility: Microsoft Exchange Management ID No: C1032751 We are having a strange problem on this server in where incoming mail from certain domains (such as cox.net) never arrive to the intended recipients but other domains work with no problem. What makes this even more strange is that when I send email from cox.net to the intended recipient in the CC or BCC line it makes it to them. I was going to b...

can not type in body message area
On web access I can not type in the body of message. Can someone please tell me how to fix this? On 3/8/2010 6:41 PM, carol25 wrote: > On web access I can not type in the body of message. Can someone please tell > me how to fix this? This is specific to your Internet Explorer version. You are talking to the Exchange 2003 OWA, right? Are you on Vista? We really need the version information on all products involved when you post a question. The culprit is probably the rich text control is not loading. http://www.slipstick.com/exs/owa.asp You are also advised to please ...

Tasks Not Recieved, Messages OK, No NDR
Exchange 2003 SP2 just updated through June's updates, Server 2003 SP1 When our intern assigns an Outlook task, it is not recieved by me. I can assign and send her one fine. This behaviour seems to have begun when the recent updates were applied, is anyone aware of a problem? There is nothing new in the bad mail folder, nothing in the pickup folder, nothing in the ESM queueu, on the senders machine the task is put in the sent folder and listed in her task list as "waiting for response from recipient"...she can send email messages no problem. Can someone point me to the ...

Messages sitting in Outbox
I see this is a problem that others are experiencing with Outlook 2002. Sometimes when I send an email, the message sits in the Outbox. This usually happens when I am sending a message to a group of recipients. So, I click to resend same message. The problem is that the message has, in fact, been sent and I end up sending several copies. My question is: How can I know if it has gone out, other than including my name in the list? Is there a tool or setting that limits the number of recipients for one message that I can change? Thank you. ...

QUES: There was an Error Opening this Message??
Hi... I've a friend who's running Windows-7 and Windows Live Mail (WLM) since about Christmas. Lately she's trying to read her email and has been getting a "There was an error opening this message" window. She can read most mail messages but not others. I've copied the entire "Windows Live Mail" folder to desktop and WLM said it was rebuilding but I couldn't IMPORT much back in. I also deleted the windows message store file; again it was rebuilt but went back to not opening the same messages as before. Google shows others have had...

Duplicate E-mail Messages/Duplicate Calendar Entries
PC running Outlook 2003 with Business Contact Manager using Windows XP and networked. Recipients receive two of the same e-mails, even through only one sent. Happens both internally and externally, and only sporatically. Seems to happen when e-mail is addressed to multiple recipients. Calendar items also appear to double, and in some cases triple, when synching Oulook and Palm Pilot calendars. do you use POP3? >-----Original Message----- >PC running Outlook 2003 with Business Contact Manager >using Windows XP and networked. > >Recipients receive two of the same e-ma...

Need help recovering messages deleted by Symantec Spam filter
Hello all, I need help with the following situation. We just installed the new version of Symantec Small Business Antivirus with Exchange Filtering (AV ver is 8.1, Filtering is ver 4.0). I activated the Spam filters, but the users and external contacts complained about the warning messages. The office manager (more like a VP) said to stop the warnings, and stop the identified spam from showing up in the users mailboxes. I complied, and set the Spam filter to delete messages identified as Spam, and turned off the notices. Long story short, the spam filter of course caught legitimate mail. User...

Ex2007
Ex2007B2 & Outlook2007B2 Basically I have a different mailbox for most of my email addresses. In 2003 I could give UserA permissions to open UserB's mailbox by adding UserA to UserB's permissions in Exchange Advanced tab - Mailbox Rights. How do I do the equivalent in 2007? I really don't want to have to log into each Outlook profile as that username! On 21 Oct 2006 07:31:59 -0700, doug.masters@gmail.com wrote: >Ex2007B2 & Outlook2007B2 > >Basically I have a different mailbox for most of my email addresses. >In 2003 I could give UserA permissions to open ...

Formating date in Data Analysis view for PWA 2007
PWA 2007 Data Analysis View gurus, please advise. Any way we could change the days to show up as actual days (Sun 11, Mon 12) instead of Day 11, Day 12 etc? Kahuna -- No, sorry, but this is not possible. You would have to manually edit the Caption property of EVERY day, which would be a very laborious process that I doubt you would want to do. Hope this helps. -- Dale A. Howard [MVP] VP of Educational Services msProjectExperts http://www.msprojectexperts.com http://www.projectserverexperts.com "We write the books on Project Server" "kahuna" &l...

how do i protect a word doc, but leave some areas editable?
I have a word document formatted, but there are certain pieces of information that need to be edited each time it is used. How do I create it so only the set sections can be changed? Lainey25 wrote: > I have a word document formatted, but there are certain pieces of > information that need to be edited each time it is used. How do I > create it so only the set sections can be changed? See http://word.mvps.org/FAQs/TblsFldsFms/LinesInForms.htm and the links in that article. These articles illustrate the steps for Word 2003 or earlier. If you have Word 2007, post ba...

How can I see pending messages in Exchange?
Our users received a notice from Exchange that delivery of their messages was delayed. It turned out this was because our ISP's SMTP relay host was down. However when Exchange first started telling users, 4 hours after they tried to send, that their message was delayed, I immediately wanted to check and look at the messages pending in the Exchange outgoing SMTP queue. That's when I realized I didn't know how to do this. In Lotus Domino, there is a file called mail.box that holds all outgoing messages until they are processed. There are also dashboard gauges that show...

Multiple Duplicate Email Messages #2
As the subject suggests, I am getting duplicate emails everytime outlook access my pop account. I have set the pop setings to leave a copy on the server as my main computer is at home and downloads all emails there. But EVERY time it pops my account, the same messages are downloaded. I currently have 8 copies of everything. How do I overcome this problem? Thanks. Hi Hasan, maybe this sites could help: http://support.microsoft.com/kb/289942/en http://support.microsoft.com/kb/284404/en http://support.microsoft.com/kb/317945/en http://support.microsoft.com/kb/292249/en http://support.mic...

How do I change the layout of my doc. to one pg landscape/ one por
How do I change the layout of my 5 page document to one page landscape and on page portrait. Group all on the page, rotate 90 degrees, adjust the elements to fit. -- Mary Sauer MS MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Dora" <Dora@discussions.microsoft.com> wrote in message news:7172D72F-588A-4A5B-9C8F-D9EFA161FB7C@microsoft.com... > How do I change the layout of my 5 page document to one page landscape and on > page portrait. ...

can exchange message center track email sent by an application
Hi, exchange message center track email sent by an application? Is the above possible? thanks, -danny yes if you know the email address of the application sending the email. "PLAGOOMS" wrote: > > Hi, > exchange message center track email sent by an application? > Is the above possible? > > thanks, > -danny ...

Error message #79
I'm having a problem w/dragging & dropping email into folders while using MS Outlook 2003. After dropping about 3/4 email messages into folders (no matter where you drop them)I recieve this error message "Not enough storage is available to process this command". I've ckecked Event Viewer & task manager & cannot find any information about this problem so I can address it.I have also tried "Rebooting" and still get the same issue. Does anyone know how I can solve this issue??? ...

Sending a message to all child windows
Hello, I think this is a basic question, but I'm not sure how to handle it. How can I send a message to all child windows (recursively) and handle it in more than one window? I have several custom controls and there are times when I need to notify them all about something (a connection state change, for example). I would like to do something like AfxGetMainWnd()->SendMessage(UWM_MY_REG_MSG,...) and all would handle the message. Thanks, Pedro "Pedro Ferreira" <none@none.com> wrote in message news:O1A364n6HHA.4476@TK2MSFTNGP06.phx.gbl... > Hello, > > ...

Move sent messages to subfolder
I've noticed that for people that I've created a rule to move incoming messages to an inbox subfolder, my sent messages also get moved to that folder. But I haven't created a rule to do this - just a rule for the incoming messages. This is useful and I want to replicate it on my outlook at work without creating a lot of new rules. How do I do this? I'm using outlook 2000 in both cases with no MS Exchange. Thanks. Check Tools | Options | E-Mail Options | Advanced E-Mail Options Do you have the option to save sent items with the original in folders other than the Inbox checked?...

No NDR/warning for messages that exceed message size limit
Has anyone seen the following problem: config - Exchange 2000 SP3 on Windows 2000 SP3 When message size limits are set and a user tries to send a message that exceeds the limit, the message appears to be sent normally. In addition, there is no NDR returned and the message is never delivered to the recipient. It appears that Exchange accepts the over-size message, then drops it without letting anybody know that the message was too big. Also, if an external message come in that causes the mailbox size limit to be exceeded, neither the sender nor recipient is informed and the message appears to...

Smart List Error Message
The following error message pops up when attempting to start the Smart List in GP v. 9.0: SVC_EXPLORER_BACKGROUND_CUSTOM The user is asked whether they would like temporary or permanent access. Whichever you choose if you hit OK enough times you will finally end up with access to the Smart List. The error only occurs for users who have restricted access to the system to certain parts of the system. Thanks~! It seems that you have removed access to the SVC_Explorer_Background_Custom form in security in the Field Service module. That is "bad" as you've noticed. You mu...