现在想编一个小游戏,但又不想完全使用sdk,因而想单独使用主框架加视图类完成!
现在遇到的问题是无法单独使用CFormView的视图类!希望有不使用Doc/View的兄弟姐妹们指点一下。
我现在尝试如下:BOOL CStep6App::InitInstance()
{#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
m_pMainWnd = pMainFrame;
return TRUE;
}//然后在主窗体通过菜单显示不同窗体:
void CMainFrame::OnBegin()
{
// TODO: Add your command handler code here
CRuntimeClass* prt = RUNTIME_CLASS(CStep6View); CStep6View *pBounceWnd = (CStep6View *)prt->CreateObject();; pBounceWnd->ShowWindow(SW_NORMAL);
pBounceWnd->UpdateWindow();
return;
}视图类的实现是采用向导生成的,运行就出现异常!如何修改呢?唉,感觉MFC灵活性实在太差,每个类基本不能单独使用,远远没有使用java或sdk方便!
如果动不动就要看源代码也实在太烦了!希望有人能提供范例!MSDN里面提供的例子其父类是CMDIChildWnd,我想改成CFormView!
现在遇到的问题是无法单独使用CFormView的视图类!希望有不使用Doc/View的兄弟姐妹们指点一下。
我现在尝试如下:BOOL CStep6App::InitInstance()
{#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
m_pMainWnd = pMainFrame;
return TRUE;
}//然后在主窗体通过菜单显示不同窗体:
void CMainFrame::OnBegin()
{
// TODO: Add your command handler code here
CRuntimeClass* prt = RUNTIME_CLASS(CStep6View); CStep6View *pBounceWnd = (CStep6View *)prt->CreateObject();; pBounceWnd->ShowWindow(SW_NORMAL);
pBounceWnd->UpdateWindow();
return;
}视图类的实现是采用向导生成的,运行就出现异常!如何修改呢?唉,感觉MFC灵活性实在太差,每个类基本不能单独使用,远远没有使用java或sdk方便!
如果动不动就要看源代码也实在太烦了!希望有人能提供范例!MSDN里面提供的例子其父类是CMDIChildWnd,我想改成CFormView!
解决方案 »
- 请教InstallShield的序列号生成算法?
- 如何在一个进程创建之前截获这个进程运行
- 得到内存的地址绝对值,这样取法对不对?
- MFC中初始化控件应该放在哪个事件中?
- 处理了wm_windowposchanging消息窗口不能移动了???
- udp传输问题,包长超过1472就收不到
- api 编辑框问题
- 【提示:】如何得到DLL加载时的状态比如。 DLL_PROCESS_ATTACH DLL_PROCESS_DETACH
- 急!求教!有谁知道DMI,如何从bois中得到主板和内存的信息
- 关于创建bmp图片的问题[100分]急需!!!
- 谁对smtp协议(RFC 821)pop3协议(RFC 1939)比较熟悉,可以给我介绍一下么??
- 同一个USB音频设备在xp和2000下的名字不同。有没有什么类似ID的属性与操作系统无关?
{
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
// To create the main window, this code creates a new frame window
// object and then sets it as the application's main window object. CMainFrame* pFrame = new CMainFrame;
m_pMainWnd = pFrame; // create and load the frame with its resources pFrame->LoadFrame(IDR_MAINFRAME);
pFrame->SetIcon(LoadIcon(IDR_MAINFRAME),FALSE); // The one and only window has been initialized, so show and update it.
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow(); return TRUE;
}
你的OnBegin是部队的,下面是运行视图的代码:
bool DeleteView()
{ CDocument * pDoc= NULL;
CCreateContext context;
pDoc=this->GetActiveDocument();
ASSERT(pDoc); context.m_pNewViewClass=RUNTIME_CLASS(CNetObserverView);
context.m_pCurrentDoc=NULL;
context.m_pNewDocTemplate=NULL;
context.m_pLastView=NULL;
context.m_pCurrentFrame=NULL;
if(m_pSplt==NULL)
{
TRACE("delete View is error!\n");
return false; }
pDoc->m_bAutoDelete=FALSE;
if (m_pSplt->m_hWnd)
{
m_pSplt->DestroyWindow();
}
delete m_pSplt;
m_pSplt=NULL;
pDoc->m_bAutoDelete=TRUE;
//下面要创建父窗口的右侧视图
m_wndSplitter.CreateView(0,1,context.m_pNewViewClass,CSize(100, 100), &context);
CView * pNewView= (CView *)m_wndSplitter.GetPane(0,1);
pNewView->OnInitialUpdate();
SetActiveView(pNewView);
m_wndSplitter.RecalcLayout();
TRACE("delete View is good!\n"); return true;
}bool AddView(CRuntimeClass *pNewViewClass)
{
//if(m_pSplt!=NULL) return ;
//添加View,用于服务列表视图
CDocument * pDoc= NULL;
CCreateContext context;
pDoc=this->GetActiveDocument();
ASSERT(pDoc);
ASSERT(m_pSplt==NULL);
//设备上下文
// if(m_pSplt!=NULL) return false;
context.m_pNewViewClass=pNewViewClass;
context.m_pCurrentDoc=NULL;
context.m_pNewDocTemplate=NULL;
context.m_pLastView=NULL;
context.m_pCurrentFrame=NULL; pDoc->m_bAutoDelete=FALSE;
CView* pV = (CView *)m_wndSplitter.GetPane(0,1);
ASSERT(pV);
pV->DestroyWindow();
pDoc->m_bAutoDelete=TRUE;
m_pSplt = new CSplitterWnd;
if (!m_pSplt->CreateStatic (&m_wndSplitter, 2,1,WS_CHILD|WS_VISIBLE,m_wndSplitter.IdFromRowCol(0,1)))
{
TRACE("Add View is error!\n");
return false;
}
CView * pNewView;
context.m_pNewViewClass=RUNTIME_CLASS(CNetObserverView);
m_pSplt->CreateView(0,0,context.m_pNewViewClass,CSize(100, 100), &context);
pNewView= (CView *)m_pSplt->GetPane(0,0);
pNewView->OnInitialUpdate(); context.m_pNewViewClass=pNewViewClass;
m_pSplt->CreateView(1,0,pNewViewClass,CSize(100, 100), &context);
pNewView= (CView *)m_pSplt->GetPane(1,0);
pNewView->OnInitialUpdate();
SetActiveView(pNewView);
m_pSplt->RecalcLayout();
m_wndSplitter.RecalcLayout();
RecalcLayout();
TRACE("Add View is good!\n"); return true;
}
先DeleteView()再AddView*()