Trying to SendMessage to the View

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.
kerlauraAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
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

     
}
kerlauraAuthor Commented:
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?
AndyAinscowFreelance programmer / ConsultantCommented:
>>Do I need to include the view's h file in the mainframe?

yes in the .cpp file, that should stop that error message
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

kerlauraAuthor Commented:
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.  

AndyAinscowFreelance programmer / ConsultantCommented:
Where did you put the #include ?  Please copy/paste - this sounds like it *could* be some problem with the ordering of the includes.
kerlauraAuthor Commented:
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"
AndyAinscowFreelance programmer / ConsultantCommented:
?
Please post the top of the QBConnectExView.h file - I assume there are some #includes there.
kerlauraAuthor Commented:
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"
kerlauraAuthor Commented:
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"

AndyAinscowFreelance programmer / ConsultantCommented:
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"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kerlauraAuthor Commented:
That worked.  It now goes to my view to process the message.   Awesome.  Thanks!!!
AndyAinscowFreelance programmer / ConsultantCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.