大家好,我是一名学习VC++的新手,在学习的过程中遇到了很多问题,谢谢大家的帮忙、指点、斧正,谢谢大家!!!
程序ex18View.cpp代码如下
#include "modellessdlg.h"
#include "stdafx.h"
#include "ex18.h"
#include "ex18Doc.h"
#include "ex18View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEx18View
IMPLEMENT_DYNCREATE(CEx18View, CView)
BEGIN_MESSAGE_MAP(CEx18View, CView)
ON_MESSAGE(WM_GOODBYE, OnGoodbye)
//{{AFX_MSG_MAP(CEx18View)
ON_WM_KEYDOWN()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEx18View construction/destruction
CEx18View::CEx18View()
{
// TODO: add construction code here
m_pDlg = new CModellessDlg(this);
}
CEx18View::~CEx18View()
{
delete m_pDlg;
}
BOOL CEx18View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CEx18View drawing
void CEx18View::OnDraw(CDC* pDC)
{
CEx18Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->TextOut(0,0,"XXXXX");
pDC->TextOut(0,50,"YYYYY");
}
/////////////////////////////////////////////////////////////////////////////
// CEx18View printing
BOOL CEx18View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CEx18View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CEx18View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CEx18View diagnostics
#ifdef _DEBUG
void CEx18View::AssertValid() const
{
CView::AssertValid();
}
void CEx18View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CEx18Doc* CEx18View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx18Doc)));
return (CEx18Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEx18View message handlers
void CEx18View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
m_ModelDlg=new CModellessDlg(CWnd::GetDlgItem(IDD_DIALOG1));
m_ModelDlg->DoModal();
delete m_ModeDlg;
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CEx18View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_pDlg->GetSafeHwnd() == 0)
{
m_pDlg->Create();
}
CView::OnLButtonDown(nFlags, point);
}
void CEx18View::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_pDlg->DestroyWindow();
CView::OnRButtonDown(nFlags, point);
}
LRESULT CEx18View::OnGoodbye(WPARAM wParam, LPARAM lparam)
{
m_pDlg->DestroyWindow();
return 0L;
}
程序ex18view.h 代码如下
// ex18View.h : interface of the CEx18View class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_EX18VIEW_H__2A27F5F6_1A11_40F0_8088_D895D073130B__INCLUDED_)
#define AFX_EX18VIEW_H__2A27F5F6_1A11_40F0_8088_D895D073130B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CModellessDlg; //我这里明明声明了的啊。可是编译的时候却说我没声明,奇怪了
//c:\ex18view.h(13) : see declaration of 'CModellessDlg'
class CEx18View : public CView
{
protected: // create from serialization only
CEx18View();
DECLARE_DYNCREATE(CEx18View)
// Attributes
public:
CEx18Doc* GetDocument();
private:
CModellessDlg* m_pDlg;
CModellessDlg* m_ModelDlg;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEx18View)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CEx18View();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
// Generated message map functions
protected:
//{{AFX_MSG(CEx18View)
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
afx_msg LRESULT OnGoodbye(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in ex18View.cpp
inline CEx18Doc* CEx18View::GetDocument()
{ return (CEx18Doc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_EX18VIEW_H__2A27F5F6_1A11_40F0_8088_D895D073130B__INCLUDED_)
错误提示为:
--------------------Configuration: ex18 - Win32 Debug--------------------
Compiling...
ex18.cpp
ex18View.cpp
C:\ex18View.cpp(22) : error C2065: 'WM_GOODBYE' : undeclared identifier
C:\ex18View.cpp(40) : error C2514: 'CModellessDlg' : class has no constructors
c:\ex18view.h(13) : see declaration of 'CModellessDlg'
C:\ex18View.cpp(45) : warning C4150: deletion of pointer to incomplete type 'CModellessDlg'; no destructor called
c:\ex18view.h(13) : see declaration of 'CModellessDlg'
C:\ex18View.cpp(115) : error C2514: 'CModellessDlg' : class has no constructors
c:\ex18view.h(13) : see declaration of 'CModellessDlg'
C:\ex18View.cpp(116) : error C2027: use of undefined type 'CModellessDlg'
c:\ex18view.h(13) : see declaration of 'CModellessDlg'
C:\ex18View.cpp(116) : error C2227: left of '->DoModal' must point to class/struct/union
C:\ex18View.cpp(117) : error C2065: 'm_ModeDlg' : undeclared identifier
C:\ex18View.cpp(117) : error C2541: delete : cannot delete objects that are not pointers
C:\ex18View.cpp(124) : error C2027: use of undefined type 'CModellessDlg'
c:\ex18view.h(13) : see declaration of 'CModellessDlg'
C:\ex18View.cpp(124) : error C2227: left of '->GetSafeHwnd' must point to class/struct/union
C:\ex18View.cpp(126) : error C2027: use of undefined type 'CModellessDlg'
c:\ex18view.h(13) : see declaration of 'CModellessDlg'
C:\ex18View.cpp(126) : error C2227: left of '->Create' must point to class/struct/union
C:\ex18View.cpp(134) : error C2027: use of undefined type 'CModellessDlg'
c:\ex18view.h(13) : see declaration of 'CModellessDlg'
C:\ex18View.cpp(134) : error C2227: left of '->DestroyWindow' must point to class/struct/union
C:\ex18View.cpp(139) : error C2027: use of undefined type 'CModellessDlg'
c:\ex18view.h(13) : see declaration of 'CModellessDlg'
C:\ex18View.cpp(139) : error C2227: left of '->DestroyWindow' must point to class/struct/union
Generating Code...
Error executing cl.exe.
ex18.exe - 15 error(s), 1 warning(s)
谢谢大家帮忙了!!!!!!!!!谢谢!!!!!!