• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 524
  • Last Modified:

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.
0
kerlaura
Asked:
kerlaura
  • 6
  • 6
1 Solution
 
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

     
}
0
 
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?
0
 
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
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
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.  

0
 
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.
0
 
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"
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
?
Please post the top of the QBConnectExView.h file - I assume there are some #includes there.
0
 
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"
0
 
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"

0
 
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"

0
 
kerlauraAuthor Commented:
That worked.  It now goes to my view to process the message.   Awesome.  Thanks!!!
0
 
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now