VC中程序运行后弹出 建立空文档失败 对话框解决办法
VC中程序运行后弹出 建立空文档失败 对话框
我用VC+MapX做GIS开发,照着书上录入的程序也还是出现建立空文档失败,尝试了网上看到的一些解决方法都不行,看到比较多的原因当中有:在OnCreate 里面返回-1 也会导致弹出“建立空文档失败”。我想我应该就是这个问题了,但是怎么解决呢,我的程序是照着书上输入的呀???
程序如下:
// MapXSampleView.cpp : implementation of the CMapXSampleView class
//
#include "stdafx.h"
#include "MapXSample.h"
#include "MapXSampleDoc.h"
#include "MapXSampleView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView
IMPLEMENT_DYNCREATE(CMapXSampleView, CView)
BEGIN_MESSAGE_MAP(CMapXSampleView, CView)
//{{AFX_MSG_MAP(CMapXSampleView)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_SETFOCUS()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView construction/destruction
CMapXSampleView::CMapXSampleView()
{
// TODO: add construction code here
}
CMapXSampleView::~CMapXSampleView()
{
}
BOOL CMapXSampleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView drawing
void CMapXSampleView::OnDraw(CDC* pDC)
{
CMapXSampleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView printing
BOOL CMapXSampleView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMapXSampleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMapXSampleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView diagnostics
#ifdef _DEBUG
void CMapXSampleView::AssertValid() const
{
CView::AssertValid();
}
void CMapXSampleView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMapXSampleDoc* CMapXSampleView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMapXSampleDoc)));
return (CMapXSampleDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView message handlers
int CMapXSampleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
double mapCenterX=0,mapCenterY=0,mapZoom=0;
if(!m_ctrlMapX.Create(NULL,WS_VISIBLE,CRect(0,0,100,100),this,IDC_MAP))
return -1;
m_ctrlMapX.SetGeoSet("maps\\china.gst");
m_ctrlMapX.SetTitleText("");
m_ctrlMapX.SetCenterX(mapCenterX);
m_ctrlMapX.SetCenterY(mapCenterY);
m_ctrlMapX.SetZoom(mapZoom);
return 0;
}
void CMapXSampleView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if(cx!=0 && cy!=0)
m_ctrlMapX.MoveWindow(0,0,cx,cy,TRUE);
}
void CMapXSampleView::OnSetFocus(CWnd* pOldWnd)
{
CView::OnSetFocus(pOldWnd);
m_ctrlMapX.SetFocus();
}
------解决方案--------------------
if(!m_ctrlMapX.Create(NULL,WS_VISIBLE,CRect(0,0,100,100),this,IDC_MAP))
return -1;
你跟踪一下 是不是这里返回-1了
------解决方案--------------------
大哥!!!!!下断点,调试自己写的代码 不会?
我用VC+MapX做GIS开发,照着书上录入的程序也还是出现建立空文档失败,尝试了网上看到的一些解决方法都不行,看到比较多的原因当中有:在OnCreate 里面返回-1 也会导致弹出“建立空文档失败”。我想我应该就是这个问题了,但是怎么解决呢,我的程序是照着书上输入的呀???
程序如下:
// MapXSampleView.cpp : implementation of the CMapXSampleView class
//
#include "stdafx.h"
#include "MapXSample.h"
#include "MapXSampleDoc.h"
#include "MapXSampleView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView
IMPLEMENT_DYNCREATE(CMapXSampleView, CView)
BEGIN_MESSAGE_MAP(CMapXSampleView, CView)
//{{AFX_MSG_MAP(CMapXSampleView)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_SETFOCUS()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView construction/destruction
CMapXSampleView::CMapXSampleView()
{
// TODO: add construction code here
}
CMapXSampleView::~CMapXSampleView()
{
}
BOOL CMapXSampleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView drawing
void CMapXSampleView::OnDraw(CDC* pDC)
{
CMapXSampleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView printing
BOOL CMapXSampleView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMapXSampleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMapXSampleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView diagnostics
#ifdef _DEBUG
void CMapXSampleView::AssertValid() const
{
CView::AssertValid();
}
void CMapXSampleView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMapXSampleDoc* CMapXSampleView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMapXSampleDoc)));
return (CMapXSampleDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView message handlers
int CMapXSampleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
double mapCenterX=0,mapCenterY=0,mapZoom=0;
if(!m_ctrlMapX.Create(NULL,WS_VISIBLE,CRect(0,0,100,100),this,IDC_MAP))
return -1;
m_ctrlMapX.SetGeoSet("maps\\china.gst");
m_ctrlMapX.SetTitleText("");
m_ctrlMapX.SetCenterX(mapCenterX);
m_ctrlMapX.SetCenterY(mapCenterY);
m_ctrlMapX.SetZoom(mapZoom);
return 0;
}
void CMapXSampleView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if(cx!=0 && cy!=0)
m_ctrlMapX.MoveWindow(0,0,cx,cy,TRUE);
}
void CMapXSampleView::OnSetFocus(CWnd* pOldWnd)
{
CView::OnSetFocus(pOldWnd);
m_ctrlMapX.SetFocus();
}
------解决方案--------------------
if(!m_ctrlMapX.Create(NULL,WS_VISIBLE,CRect(0,0,100,100),this,IDC_MAP))
return -1;
你跟踪一下 是不是这里返回-1了
------解决方案--------------------
大哥!!!!!下断点,调试自己写的代码 不会?