请问View的实例在哪儿生成? m_wndODraw E:\VCProj\TraceX1\TestTrace1\MainFrm.cpp(111) : error C2248: 'CMsgShowView::CMsgShowView' : cannot access protected member declared in class 'CMsgShowView' e:\vcproj\tracex1\testtrace1\msgshowview.h(16) : see declaration of 'CMsgShowView::CMsgShowView'
if (!m_wndODraw.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(200, 200, 400, 400), this, 1234))
{
MessageBox("Create ODWindow Failed !");
return ;
}
CMyWnd m_wndMy;在工具条响应函数中:
void CMyView::OnCreateWnd()
{
if(m_wndMy.GetSafeHwnd()) return; if (!m_wndMy.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(20, 200 40, 40), this, 1234))
{
MessageBox("创建失败!");
}
}
CMyWnd m_wndMy; 什么意思
CMyWnd 在哪定义的?
m_wndODraw
E:\VCProj\TraceX1\TestTrace1\MainFrm.cpp(111) : error C2248: 'CMsgShowView::CMsgShowView' : cannot access protected member declared in class 'CMsgShowView'
e:\vcproj\tracex1\testtrace1\msgshowview.h(16) : see declaration of 'CMsgShowView::CMsgShowView'
ASSERT(pClass);
CMsgShowView* pView = (CMsgShowView*)pClass->CreateObject(); //创建一个视图
我想实现的功能就是使用菜单,可以动态产生一个listview. 这是个普通形式的窗口,有一些消息从中产生.
, [email protected]
谢谢.
请问你发了没有?
[email protected], 我的Msn [email protected]
我的QQ是9723338但是只有晚上能联系.void CMainFrame::OnShowAll()
{
CDocument* pDoc=GetActiveDocument();
CView* pCurrView=GetActiveView();
CRuntimeClass* pClass = RUNTIME_CLASS(CMsgShowView);
ASSERT(pClass);
CView* pNewView = (CView*)pClass->CreateObject(); pNewView->Create(NULL,
NULL,
AFX_WS_DEFAULT_VIEW,
CRect(200,200,400,400),
this,
AFX_IDW_PANE_FIRST,
NULL); pNewView->OnInitialUpdate(); pNewView->ShowWindow(SW_SHOW);
}
创建倒是创建了,但是显示不出来呀。怎么回事??
如果是的话应该加在CChildFrame中,而不是CMainFrame中
如果要做多文档,那么要添加文档模板
{
CView* pOldView = GetActiveView();
ASSERT(pOldView); CRuntimeClass* pClass = RUNTIME_CLASS(CMsgShowView);
ASSERT(pClass);
CView* pNewView = (CView*)pClass->CreateObject();
ASSERT(pNewView);
if (pNewView->Create(NULL,
NULL,
AFX_WS_DEFAULT_VIEW,
CRect(200,200,400,400),
this,
AFX_IDW_PANE_FIRST,
NULL))
{
pNewView->OnInitialUpdate();
SetActiveView(pNewView);
pOldView->ShowWindow(SW_HIDE);
pNewView->ShowWindow(SW_SHOW);
RecalcLayout(TRUE);
}
}为了更好的看到效果你不妨过载一下CMsgShowView的EraseBkgnd消息,比如:
BOOL CMsgShowView::OnEraseBkgnd(CDC* pDC)
{
CRect rc;
pDC->GetClipBox(&rc);
pDC->FillSolidRect(rc, RGB(255,0,0));
return TRUE;
}
WS_VISIBLE,0,0,1024,768,NULL,NULL,AfxGetApp()-> hInstance,NULL);其中的参数lpszHelloClass使用如下方法得到 LPCTSTR lpszHelloClass =
AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW,
LoadCursor(NULL, IDC_ARROW),
(HBRUSH) (COLOR_WINDOW+1),
LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_OFFICETYPE)));MSDN中有比较详细的其中参数的讲解。
创建好以后
使用ShowWindow(hwnd,SW_SHOW)显示窗口即可