为什么创建视图会失败?!

yzhouen 2009-08-03 04:29:46
我在propertypage 指定RECT里创建一个VIEW,为什么会创建失败?
创建代码如下:
CCreateContext pContext;
CWnd* pFrameWnd = this;
pContext.m_pCurrentDoc = NULL;
pContext.m_pNewViewClass = RUNTIME_CLASS(CZoomView);
pView =(CZoomView *) ((CFrameWnd*)pFrameWnd)->CreateView(&pContext);
ASSERT(pView);
pView->ShowWindow(SW_NORMAL);
pView->MoveWindow(rectpic);

在CFrameWnd::CreateView的ASSERT_KINDOF(CWnd, pView);有问题
CWnd* CFrameWnd::CreateView(CCreateContext* pContext, UINT nID)
{
ASSERT(m_hWnd != NULL);
ASSERT(::IsWindow(m_hWnd));
ASSERT(pContext != NULL);
ASSERT(pContext->m_pNewViewClass != NULL);

// Note: can be a CWnd with PostNcDestroy self cleanup
CWnd* pView = (CWnd*)pContext->m_pNewViewClass->CreateObject();
if (pView == NULL)
{
TRACE1("Warning: Dynamic create of view type %hs failed.\n",
pContext->m_pNewViewClass->m_lpszClassName);
return NULL;
}
ASSERT_KINDOF(CWnd, pView); //单步运行到这里就无法继续往下执行了
...............
}

...全文
517 36 打赏 收藏 转发到动态 举报
写回复
用AI写文章
36 条回复
切换为时间正序
请发表友善的回复…
发表回复
yzhouen 2009-08-13
  • 打赏
  • 举报
回复
void CZoomView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();

m_layout.cx = 1000;
m_layout.cy = 40000;

m_page.cx = m_layout.cx/2;
m_page.cy = m_layout.cy/2;
m_line.cx = m_layout.cx/50;
m_line.cy = m_layout.cy/50;
SetScrollSizes(MM_TEXT, m_layout, m_page, m_line);

m_bInitialSize = TRUE;

if (m_pdcMemory->GetSafeHdc() == NULL)
{
CClientDC dc(this);
OnPrepareDC(&dc);
m_pdcMemory->CreateCompatibleDC(&dc);

// makes bitmap same size as display window
CRect clientRect(0,0,0,0);
GetClientRect(clientRect);
if (m_pBitmap != NULL)
{
delete m_pBitmap;
m_pBitmap = NULL;
}
m_pBitmap = new CBitmap();
m_pBitmap->CreateCompatibleBitmap(&dc, clientRect.right,
clientRect.bottom);
}
}
MoXiaoRab 2009-08-12
  • 打赏
  • 举报
回复
void CZoomView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();

// TODO: Add your specialized code here and/or call the base class
CSize sizeTotal;
sizeTotal.cx = sizeTotal.cy = 1000;
SetScrollSizes(MM_TEXT, sizeTotal);
}
MoXiaoRab 2009-08-12
  • 打赏
  • 举报
回复
OnInitialUpdate()贴出来看看,我估计这个写得有问题
MoXiaoRab 2009-08-12
  • 打赏
  • 举报
回复
代码太多,眼看花了...
dl551djs 2009-08-12
  • 打赏
  • 举报
回复
看的眼花
也没看出啥
晒月光的青蛙 2009-08-12
  • 打赏
  • 举报
回复
=帮顶定啦
yzhouen 2009-08-12
  • 打赏
  • 举报
回复
这个问题解决200分全部给他
wu_qing_yun 2009-08-12
  • 打赏
  • 举报
回复
楼主太富有了
yzhouen 2009-08-12
  • 打赏
  • 举报
回复
没有来实质性解决问题的吗?
shakeyou123 2009-08-12
  • 打赏
  • 举报
回复
人工UP
yzhouen 2009-08-12
  • 打赏
  • 举报
回复
再UP一下,问题仍然没有解决
yzhouen 2009-08-06
  • 打赏
  • 举报
回复
人呢?分数可以再加!
eagerle01 2009-08-06
  • 打赏
  • 举报
回复
帮顶
  • 打赏
  • 举报
回复
顶起
yzhgr 2009-08-06
  • 打赏
  • 举报
回复
学习一下
yzhouen 2009-08-05
  • 打赏
  • 举报
回复
再顶一次
job82824 2009-08-04
  • 打赏
  • 举报
回复
学习下。
MSDN注解:CreateView
--Use this member function to create "views" that are not CView-derived within a frame. After calling CreateView, you must manually set the view to active and set it to be visible; these tasks are not automatically performed by CreateView
--使用这个函数来创建的views应该是框架当中的非CView类的派生类(我想楼主的CScrollView应该是CView类的派生类吧?)。在创建后,你必须手动激活该视,并设置它为可见;这些工作并不能由CreateView来完成.
个人感觉还不如在矩形区域内创建一个窗口CWnd呢,然后在里边显示需要看到的内容?
yzhouen 2009-08-04
  • 打赏
  • 举报
回复
CZoomView是由CScrollView派生的


#if !defined(AFX_ZOOMVIEW_H__461510AD_E0E4_4CB6_B4B7_3E186AC2B08C__INCLUDED_)
#define AFX_ZOOMVIEW_H__461510AD_E0E4_4CB6_B4B7_3E186AC2B08C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ZoomView.h : header file
//


class CZoomView : public CScrollView
{
protected:
public:
CZoomView(); // protected constructor used by dynamic creation
DECLARE_DYNAMIC(CZoomView)

// Attributes
public:
// Flicker free attributes
CDC* m_pdcMemory;
CBitmap* m_pBitmap;
BOOL m_bInitialSize;

protected:
// Zooom attributes
float m_zoomFactor;
float m_minZoomFactor;
float m_maxZoomFactor;
CSize m_line;
CSize m_page;
CSize m_layout;
CSize m_displaySize;

// Operations
public:
// Display Operation /////////////////////////////////////////////////////
int SetMapMode(CDC* pDC);
void SetDisplaySize(void);
void SetZoomScale(float fScale);
void SetZoomArea(CRect zoomRect);
CPoint GetCenterScrollPosition(void);
void LPtoDP(LPPOINT lpPoint);
void LPtoDP(LPRECT lpRect);
void LPtoDP(LPSIZE lpSize);
void DPtoLP(LPPOINT lpPoint);
void DPtoLP(LPRECT lpRect);
void DPtoLP(LPSIZE lpSize);
CSize GetDisplaySize() {return m_displaySize;};
//////////////////////////////////////////////////////////////////////////

int FloatToInt(float fNumber);

protected:
void SetZoomFactor(float fZoomFactor);

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CZoomView)
protected:
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual void OnInitialUpdate(); // first time after construct
//}}AFX_VIRTUAL

// Implementation
protected:
public:
virtual ~CZoomView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

// Generated message map functions
//{{AFX_MSG(CZoomView)
afx_msg void OnPaint();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_ZOOMVIEW_H__461510AD_E0E4_4CB6_B4B7_3E186AC2B08C__INCLUDED_)
yzhouen 2009-08-04
  • 打赏
  • 举报
回复
回复楼上,我把你的这段代码添进去是正常的,为什么改成我自己的VIEW就不行了呢?
CZoomView *pView = new CZoomView();
CRuntimeClass * pViewClass = RUNTIME_CLASS(CZoomView);
CCreateContext context;
context.m_pCurrentFrame = NULL;
context.m_pCurrentDoc = NULL;
context.m_pNewViewClass = pViewClass;
context.m_pNewDocTemplate = NULL;

CRect rc;
m_pParentWnd = new CWnd;
m_pParentWnd->Attach(pView->m_hWnd);
m_ViewWnd.GetClientRect(&rc);

pView->Create(NULL,NULL,WS_CHILD|WS_VISIBLE,rc,&m_ViewWnd,11,&context);



yzhouen 2009-08-04
  • 打赏
  • 举报
回复
10楼的pXXXView 和 m_hParent 变量是怎么来的?
加载更多回复(16)

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧