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

Newbie: Getting MyView not CView

Basic as they come:

I have created an App in Visual Studio and I'm using the following code to get the view:
CFrameWnd * pFrame = (CFrameWnd*)AfxGetApp()->m_pMainWnd;
CView * pView = pFrame->GetActiveView();

The problem is that I have a function in MyView that I want to use.  When I try and type cast pView, like ((CMyView*)pView)->ProcessInput
, I get the error:
error C2065: 'CMyView' : undeclared identifier

How do I get a pointer so I can call ProcessInput in the MyView class.  Using the #include "MyView.h" doesn't work.

Thanks.

0
crazykz
Asked:
crazykz
1 Solution
 
chensuCommented:
Using #include "MyView.h" should work.

#include "stdafx.h"

// other #include

#include "MyView.h"

((CMyView*)pView)->ProcessInput();


There is another way to do it. Use a user-defined message and post it to the view.

#define    WM_USER_PROCESSINPUT    (WM_USER + 1)

pView->PostMessage(WM_USER_PROCESSINPUT);


BEGIN_MESSAGE_MAP(CMyView, CView)
    ON_MESSAGE(WM_USER_PROCESSINPUT, OnProcessInput)
END_MESSAGE_MAP()

LRESULT CMyView::OnProcessInput(WPARAM, LPARAM)
{
    // ...
    return 0;
}
0
 
crazykzAuthor Commented:
I did find the problem and you were right that the #include should work.  The problem I had was that just including the View.h caused errors with recognizing the declaration of the CMyDocument.  I included the CMyDocument class also to the View class and the problem resolved itself.

The important part here is that I learn the correct way to do this.  I apologize for submitting this trivial question.  Thank you for your answer.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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