?
Solved

Trying to SendMessage to the View

Posted on 2008-11-11
12
Medium Priority
?
518 Views
Last Modified: 2013-12-14
I have an application (Doc/View) architecture that contains two programs that run at once.  One is for interfacing with the user.  The other is usually doing stuff in the background.  My problem is that I want to process the receiving message in the View, but the OnCopyData will only respond from the Frame using my current method.  The way I see it, I either need to get the HWND of the view for the SendMessage or I need to figure out how to push the message to the view from the frame.

Code on the sending app:
HWND m_RemoteWindow;
m_RemoteWindow=::FindWindow(NULL,m_AppName);
// I have also tried m_RemoteWindow=::FindWindow(_T("CQBConnectExView"),m_AppName);
::SendMessage(m_RemoteWindow,WM_COPYDATA,(WPARAM)m_thisHWND,(LPARAM)&MyCDS);


Code on the receiving app that gets hit:
BOOL CMainFrame::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
      // TODO: Add your message handler code here and/or call default


      return CFrameWnd::OnCopyData(pWnd, pCopyDataStruct);
}


Code on the receiving app that does not get hit:
BOOL CQBConnectExView::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
      // TODO: Add your message handler code here and/or call default

      return CHtmlView::OnCopyData(pWnd, pCopyDataStruct);
}

One solution would be to pass the variables to the view, but I am unsure how to call a function in the view from the frame.
0
Comment
Question by:kerlaura
  • 6
  • 6
12 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 22931663
Create a public function in the view eg.

BOOL DoCopyData(COPYDATASTRUCT* pCopyDataStruct);

and

BOOL CMainFrame::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
      CMyView* pView = (CMyView*)GetActiveView();

if(pView)
  return pView->DoCopyData(pCopyDataStruct);

return FALSE;  //or TRUE if you prefer

     
}
0
 

Author Comment

by:kerlaura
ID: 22931764
I created the function in the view and modified my frame code as follows, but I get a compile error:
BOOL CMainFrame::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
      // TODO: Add your message handler code here and/or call default
      CQBConnectExView* pView = (CQBConnectExView*)GetActiveView();

      if(pView)
      
      pView->DoMsgData(pCopyDataStruct);

      return CFrameWnd::OnCopyData(pWnd, pCopyDataStruct);
}

I get the following
error C2065: 'CQBConnectExView' : undeclared identifier

Do I need to include the view's h file in the mainframe?
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 22931816
>>Do I need to include the view's h file in the mainframe?

yes in the .cpp file, that should stop that error message
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:kerlaura
ID: 22931887
I now get many compile errors.

I put the following in mainfrm.cpp
#include "QBConnectExView.h"

some of the errors are:
e:\projects\QBConnectEx\QBConnectEx\QBConnectExView.h(17): error C2143: syntax error : missing ';' before '*'
e:\projects\QBConnectEx\QBConnectEx\QBConnectExView.h(17): error C2501: 'CQBConnectExView::CQBConnectExDoc' : missing storage-class or type specifiers

without the view's include in the frame and the call to DoMsgData it compiles fine, so I am not sure how to proceed.  

0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 22931938
Where did you put the #include ?  Please copy/paste - this sounds like it *could* be some problem with the ordering of the includes.
0
 

Author Comment

by:kerlaura
ID: 22932021
It is at the top of mainfrm.cpp
I tried moving it before each of the other includes one at time and still compile error each time.

#include "stdafx.h"
#include "QBConnectEx.h"
#include "MainFrm.h"
#include ".\mainfrm.h"
#include "QBConnectExView.h"
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 22932391
?
Please post the top of the QBConnectExView.h file - I assume there are some #includes there.
0
 

Author Comment

by:kerlaura
ID: 22932440
the view cpp file has
#include "stdafx.h"
#include "QBConnectEx.h"

#include "QBConnectExDoc.h"
#include "QBConnectExView.h"
#include ".\qbconnectexview.h"

and the view's h file has
#include "resource.h"       // main symbols

#include "../QBConnectCommon/QBCRegistry.h"
#include "../QBConnectCommon/QBMsgs.h"
#include "AppMessageBox.h"
0
 

Author Comment

by:kerlaura
ID: 22932453
whoops... i copied wrong

the view's cpp file has
#include "stdafx.h"
#include "QBConnectEx.h"

#include "QBConnectExDoc.h"
#include "QBConnectExView.h"
#include ".\qbconnectexview.h"

and the view's h file has
#include "e:\projects\qbconnectex\qbconnectcommon\qbmsgs.h"

The app's h file has

#include "resource.h"       // main symbols

#include "../QBConnectCommon/QBCRegistry.h"
#include "../QBConnectCommon/QBMsgs.h"
#include "AppMessageBox.h"

0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 22932711
OK, first a little tidying up

#include "QBConnectExView.h"
#include ".\qbconnectexview.h"
there is no small/capital letter difference for the files and .\ is the same as not being there - so both #includes are the same.

If I were you I would remove the redundant duplicates - it makes things easier to read.



I have done a quick hack job here.
Try this in the main frame .cpp file

#include "QBConnectExDoc.h"
#include "QBConnectExView.h"

0
 

Author Comment

by:kerlaura
ID: 22932783
That worked.  It now goes to my view to process the message.   Awesome.  Thanks!!!
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 22932881
Good.


ps. Don't forget you need to accept a comment as an answer to close the question otherwise another expert has to read the comments then make a recommendation
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question