问一个问题,关于动态创建CView类

alixnuaa 2006-04-24 07:57:52
我利用MFC创建了一个基于SDI的文档,是explore样子的,左边是CTreeView的类,右边是CListView的类,然后建立了一个基于CListView的类,希望通过左边的树形结构,动态的在右边响应,程序老是出现运行时的错误,请问应该怎么操作的?
有没有具体的例子可以参考的?
CView类创建的时候需要有一个ID 号,可是动态生成的时候没有找到具体的 ID号,请各位高手指教。
...全文
364 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
alixnuaa 2006-04-24
  • 打赏
  • 举报
回复
多谢各位
whwjn 2006-04-24
  • 打赏
  • 举报
回复
http://www.vczx.com/article/show.php?id=1132
alixnuaa 2006-04-24
  • 打赏
  • 举报
回复
那怎么和左侧的树联系在一起啊?
alixnuaa 2006-04-24
  • 打赏
  • 举报
回复
是因为我想在左边点树的时候,右边会有不同的响应,所以就想多创建几个CView的类,然后用到new和Create的时候,需要了ID 号的
DentistryDoctor 2006-04-24
  • 打赏
  • 举报
回复
///////////////////////////////////////////////////////////
// Replace the current view in the frame window pFrame
// by a new view of class pViewClass

void EkSwitchViewInFrame( CFrameWnd* pFrame,
CRuntimeClass* pViewClass )
{
ASSERT_VALID( pFrame );
ASSERT( pViewClass != NULL );

ASSERT( pViewClass->
IsDerivedFrom( RUNTIME_CLASS( CView ) ) );

// 1 - Find the currently active view
CView* pActiveView = pFrame->GetActiveView();
if( pActiveView == NULL )
{
TRACE0( "Unable to switch: no active view\n" );
return;
}

if( pActiveView->IsKindOf( pViewClass ) )
{
// No need to switch for same view class
return;
}

// 2 - Store current view position
CRect rcView;
pActiveView->GetWindowRect( &rcView );

// 3 - Find the associated document
CDocument* pDoc = pActiveView->GetDocument();
ASSERT_VALID( pDoc );

// 4 - Make sure the document won't self-destruct
// when active view is destroyed
BOOL bSaveAutoDelete = pDoc->m_bAutoDelete;
pDoc->m_bAutoDelete = FALSE;

// 5 - Destroy the active view
pActiveView->DestroyWindow();

// 6 - Restore document to initial state
pDoc->m_bAutoDelete = bSaveAutoDelete;

// 7 - Initialize creation context used by CreateView
CCreateContext context;
context.m_pNewDocTemplate = NULL;
context.m_pLastView = NULL;
context.m_pCurrentFrame = NULL;

context.m_pNewViewClass = pViewClass;
context.m_pCurrentDoc = pDoc;

// 8 - Create the new view
CView* pNewView = static_cast<CView*>
( pFrame->CreateView( &context ) );

ASSERT_VALID( pNewView );

// 9 - Position the new view like the old one
pFrame->ScreenToClient( &rcView );
pNewView->MoveWindow( &rcView, TRUE );

// 10 - Send WM_INITIALUPDATE to the view
pFrame->InitialUpdateFrame( pDoc, TRUE );
}

///////////////////////////////////////////////////////////
// Return the active frame window or NULL

CFrameWnd* EkGetActiveFrame()
{
CWnd* pMainWnd = AfxGetMainWnd();

ASSERT_VALID( pMainWnd );

if( !pMainWnd->IsKindOf( RUNTIME_CLASS( CFrameWnd ) ) )
{
return NULL;
}

return static_cast<CFrameWnd*>( pMainWnd )
->GetActiveFrame();
}
lixiaosan 2006-04-24
  • 打赏
  • 举报
回复
http://www.vckbase.com/code/winview/advui/cmyexplorer.zip
DentistryDoctor 2006-04-24
  • 打赏
  • 举报
回复
CView类创建的时候需要有一个ID 号?
有这个需要吗?

15,975

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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