分割窗口后,第2个视图,自己定义的类,添加了一个GetDocument()函数
class CView_Default : public CView
{
public:
CMyDoc* GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*) m_pDocument;
}}然后在这里加载3个位图
void CView_Default::OnDraw(CDC* pDC)
{
//CDocument* pDoc = GetDocument();
// TODO: add draw code here
CMyDoc* pDoc = GetDocument(); 
ASSERT_VALID(pDoc);            //如果把这两行和定义的GetDocument()删除,一样可以加载.可是别人程序里也是这样写的,为什么不报错?这里这样写那里写错了?        CBitmap bmp1,bmp2,bmp3;
    bmp1.LoadBitmap(CJ_STR1_UP);
    bmp2.LoadBitmap(CJ_STR2_UP);
    bmp3.LoadBitmap(CJ_STR3_UP);
    // Get the size of the bitmap
    BITMAP bmpInfo1,bmpInfo2,bmpInfo3;    bmp1.GetBitmap(&bmpInfo1);
bmp2.GetBitmap(&bmpInfo2);
bmp3.GetBitmap(&bmpInfo3);      // Create an in-memory DC compatible with the
      // display DC we're using to paint
      CDC dcMemory1,dcMemory2,dcMemory3;      dcMemory1.CreateCompatibleDC(pDC);
  dcMemory2.CreateCompatibleDC(pDC);
  dcMemory3.CreateCompatibleDC(pDC);      // Select the bitmap into the in-memory DC
      CBitmap* pOldBitmap1 = dcMemory1.SelectObject(&bmp1);
  pDC->BitBlt(220, 60, bmpInfo1.bmWidth, bmpInfo1.bmHeight, &dcMemory1, 
         0, 0, SRCCOPY);
      dcMemory1.SelectObject(pOldBitmap1);      CBitmap* pOldBitmap2 = dcMemory2.SelectObject(&bmp2);
  pDC->BitBlt(500,520,bmpInfo2.bmWidth,bmpInfo2.bmHeight,&dcMemory2,0,0,SRCCOPY);
  dcMemory2.SelectObject(pOldBitmap2);   CBitmap* pOldBitmap3 = dcMemory3.SelectObject(&bmp3);
  pDC->BitBlt(610,200,bmpInfo3.bmWidth,bmpInfo3.bmHeight,&dcMemory3,0,0,SRCCOPY);
  dcMemory3.SelectObject(pOldBitmap3);
}运行提示错误
View_Default.cpp
e:\vc\vc程序\程序\数据采集\view_default.h(21) : error C2143: syntax error : missing ';' before '*'
e:\vc\vc程序\程序\数据采集\view_default.h(21) : error C2501: 'CMyDoc' : missing storage-class or type specifiers
e:\vc\vc程序\程序\数据采集\view_default.h(22) : error C2501: 'GetDocument' : missing storage-class or type specifiers
e:\vc\vc程序\程序\数据采集\view_default.h(25) : warning C4183: 'GetDocument': member function definition looks like a ctor, but name does not match enclosing class
E:\vc\vc程序\程序\数据采集\View_Default.cpp(42) : error C2440: 'initializing' : cannot convert from 'int *' to 'class CMyDoc *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.数据采集.exe - 4 error(s), 1 warning(s)

解决方案 »

  1.   

    这是编译错误,不是执行错误。
    #include "MyDoc.h"
      

  2.   

    在 class CView_Default : public CView前class CMyDoc;头文件还有冲突再调整
      

  3.   

    #include "MyDoc.h" 这个头文件已经包含,在头文件中的顺序会影响吗?
      

  4.   

    工程名字是中文,在新建的最后一步把默认改成CMyDoc了的,这样有影响?
    我是在新建的时候用CFormView做基类,分割后第2个窗口才是从View派生,上面的代码是第2个窗口类的
    #include "MyDoc.h" 这个头文件已经包含,就是不知道到底出问题在那里?