当CLeftPane从CView继承时,程序运行完好,可是当我把CLeftPane从CFrameWnd继承过来,在程序退出时会报异常,这是怎么回事?不过我的CRightPane是从CFrameWnd继承过来的。是不是拆分窗口的(0,0)位置一定要是从CView继承过来呢???各位大虾帮我看看吧,多谢了。BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{ CRect rc;
this->GetClientRect(rc);
int iProjWidth = rc.Width()*0.3; if (!m_wndSplitter.CreateStatic(this, 1,2))
return false;
//CLeftPane如果从CFrameWnd继承,程序退出报错!
//CLeftPane如果从CView继承,程序运行正常
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftPane), CSize(iProjWidth,rc.Height()), pContext))
return false;
//CRightPane从CFrameWnd继承,
if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRightPane), CSize(rc.Width()-iProjWidth,rc.Height()), pContext))
return false;
return true;
}如果我把CLeftPane从CView继承过来,以下代码怎么不起作用?(看不到上下两个拆分窗口)
int CLeftView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rc;
this->GetClientRect(rc);
if (!m_Splitter.CreateStatic(this, 2, 1))
return false;
CCreateContext *pContext = (CCreateContext*) lpCreateStruct->lpCreateParams;
if (!m_Splitter.CreateView(0, 0, RUNTIME_CLASS(CProjectListDlg), CSize(rc.Width(), rc.Height()/3), pContext))
return false;
if (!m_Splitter.CreateView(1, 0, RUNTIME_CLASS(CBaseInfoDlg), CSize(rc.Width(), rc.Height()-rc.Height()/3), pContext))
return false;
return 0;
}如果我把CLeftPane从CFrameWnd继承过来,以下代码可以实现(可以看到上下两个拆分窗口),但就是退出程序时报异常,到底是怎么回事?
BOOL CLeftPane::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
CRect rc;
this->GetClientRect(rc);
if (!m_Splitter.CreateStatic(this, 2, 1))
return false;
if (!m_Splitter.CreateView(0, 0, RUNTIME_CLASS(CProjectListDlg), CSize(rc.Width(), rc.Height()/3), pContext))
return false;
if (!m_Splitter.CreateView(1, 0, RUNTIME_CLASS(CBaseInfoDlg), CSize(rc.Width(), rc.Height()-rc.Height()/3), pContext))
return false;
return true;
}
程序异常时停在winfrm.cpp的”***“处void CFrameWnd::OnClose()
{
if (m_lpfnCloseProc != NULL)
(*m_lpfnCloseProc)(this); // Note: only queries the active document
CDocument* pDocument = GetActiveDocument();
if (pDocument != NULL && !pDocument->CanCloseFrame(this))
{
// document can't close right now -- don't close it
return;
}
CWinApp* pApp = AfxGetApp();
if (pApp != NULL && pApp->m_pMainWnd == this)
{
// attempt to save all documents
if (pDocument == NULL && !pApp->SaveAllModified())
return; // don't close it // hide the application's windows before closing all the documents
pApp->HideApplication(); // close all documents first
pApp->CloseAllDocuments(FALSE); // don't exit if there are outstanding component objects
if (!AfxOleCanExitApp())
{
// take user out of control of the app
AfxOleSetUserCtrl(FALSE); // don't destroy the main window and close down just yet
// (there are outstanding component (OLE) objects)
return;
} // there are cases where destroying the documents may destroy the
// main window of the application.
if (!afxContextIsDLL && pApp->m_pMainWnd == NULL)
{
AfxPostQuitMessage(0);
return;
}
} // detect the case that this is the last frame on the document and
// shut down with OnCloseDocument instead.
if (pDocument != NULL && pDocument->m_bAutoDelete)
{
BOOL bOtherFrame = FALSE;
//*** 程序报错时停在此处
POSITION pos = pDocument->GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = pDocument->GetNextView(pos);
ASSERT_VALID(pView);
if (pView->GetParentFrame() != this)
{
bOtherFrame = TRUE;
break;
}
}
if (!bOtherFrame)
{
pDocument->OnCloseDocument();
return;
} // allow the document to cleanup before the window is destroyed
pDocument->PreCloseFrame(this);
} // then destroy the window
DestroyWindow();
}
CCreateContext* pContext)
{ CRect rc;
this->GetClientRect(rc);
int iProjWidth = rc.Width()*0.3; if (!m_wndSplitter.CreateStatic(this, 1,2))
return false;
//CLeftPane如果从CFrameWnd继承,程序退出报错!
//CLeftPane如果从CView继承,程序运行正常
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftPane), CSize(iProjWidth,rc.Height()), pContext))
return false;
//CRightPane从CFrameWnd继承,
if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRightPane), CSize(rc.Width()-iProjWidth,rc.Height()), pContext))
return false;
return true;
}如果我把CLeftPane从CView继承过来,以下代码怎么不起作用?(看不到上下两个拆分窗口)
int CLeftView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rc;
this->GetClientRect(rc);
if (!m_Splitter.CreateStatic(this, 2, 1))
return false;
CCreateContext *pContext = (CCreateContext*) lpCreateStruct->lpCreateParams;
if (!m_Splitter.CreateView(0, 0, RUNTIME_CLASS(CProjectListDlg), CSize(rc.Width(), rc.Height()/3), pContext))
return false;
if (!m_Splitter.CreateView(1, 0, RUNTIME_CLASS(CBaseInfoDlg), CSize(rc.Width(), rc.Height()-rc.Height()/3), pContext))
return false;
return 0;
}如果我把CLeftPane从CFrameWnd继承过来,以下代码可以实现(可以看到上下两个拆分窗口),但就是退出程序时报异常,到底是怎么回事?
BOOL CLeftPane::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
CRect rc;
this->GetClientRect(rc);
if (!m_Splitter.CreateStatic(this, 2, 1))
return false;
if (!m_Splitter.CreateView(0, 0, RUNTIME_CLASS(CProjectListDlg), CSize(rc.Width(), rc.Height()/3), pContext))
return false;
if (!m_Splitter.CreateView(1, 0, RUNTIME_CLASS(CBaseInfoDlg), CSize(rc.Width(), rc.Height()-rc.Height()/3), pContext))
return false;
return true;
}
程序异常时停在winfrm.cpp的”***“处void CFrameWnd::OnClose()
{
if (m_lpfnCloseProc != NULL)
(*m_lpfnCloseProc)(this); // Note: only queries the active document
CDocument* pDocument = GetActiveDocument();
if (pDocument != NULL && !pDocument->CanCloseFrame(this))
{
// document can't close right now -- don't close it
return;
}
CWinApp* pApp = AfxGetApp();
if (pApp != NULL && pApp->m_pMainWnd == this)
{
// attempt to save all documents
if (pDocument == NULL && !pApp->SaveAllModified())
return; // don't close it // hide the application's windows before closing all the documents
pApp->HideApplication(); // close all documents first
pApp->CloseAllDocuments(FALSE); // don't exit if there are outstanding component objects
if (!AfxOleCanExitApp())
{
// take user out of control of the app
AfxOleSetUserCtrl(FALSE); // don't destroy the main window and close down just yet
// (there are outstanding component (OLE) objects)
return;
} // there are cases where destroying the documents may destroy the
// main window of the application.
if (!afxContextIsDLL && pApp->m_pMainWnd == NULL)
{
AfxPostQuitMessage(0);
return;
}
} // detect the case that this is the last frame on the document and
// shut down with OnCloseDocument instead.
if (pDocument != NULL && pDocument->m_bAutoDelete)
{
BOOL bOtherFrame = FALSE;
//*** 程序报错时停在此处
POSITION pos = pDocument->GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = pDocument->GetNextView(pos);
ASSERT_VALID(pView);
if (pView->GetParentFrame() != this)
{
bOtherFrame = TRUE;
break;
}
}
if (!bOtherFrame)
{
pDocument->OnCloseDocument();
return;
} // allow the document to cleanup before the window is destroyed
pDocument->PreCloseFrame(this);
} // then destroy the window
DestroyWindow();
}
解决方案 »
- 再问关于网络报文监听的问题(在PPPoE环境下),请epeaktop看过来
- ado读取Sqlserver某字段失败,能否得到该字段的名称?
- 主程序里面有cpropertysheet,dll里面有cpropertypage,如何加载进来?
- 怎么让某个控件永远得不到焦点
- 请问如何将文字贴到一个固定的区域中
- 我想学vc,不知道是不是已经过时了,哪位指教一下
- 串口通信
- SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,1,NULL,0);除了用这个函数,还有什么好方法能够屏蔽Alt + Tab
- COM高手请进
- 关于重画的问题?
- 一个菜鸟关于一个菜单的问题!!!!
- vc里有没有直接的对话输入框?
{
// TODO: Add your specialized code here and/or call the base class
if(
!m_MainWndSplitter.CreateStatic(this,1,2)||
!m_MainWndSplitter.CreateView(0,0,RUNTIME_CLASS(CConfigForm),CSize(200,0),pContext)||
!m_MsgWndSplitter.CreateStatic(&m_MainWndSplitter,2,1,WS_CHILD|WS_VISIBLE,m_MainWndSplitter.IdFromRowCol(0,1))||
!m_MsgWndSplitter.CreateView(0,0,RUNTIME_CLASS(CSInterFaceView),CSize(0,300),pContext)||
!m_MsgWndSplitter.CreateView(1,0,RUNTIME_CLASS(CStateView),CSize(0,0),pContext)
)return false;
return true;
}
我从CFrameWnd继承就是需要在继续在这个FrameWnd中创建一个分割窗口,用View好像不能创建出来,你可以看看上面我贴出来的代码,程序没有报错,但是没有产生所需要的分割窗口to dailiangcm(dailiang):
你的代码我刚才试过了,没有效果的,我想要的是主窗口被分割成一行两列,而每一列又被分割成两行一列。up
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rc;
this->GetClientRect(rc);
if (!m_Splitter.CreateStatic(this, 2, 1))
return false;
CCreateContext *pContext = (CCreateContext*) lpCreateStruct->lpCreateParams;
if (!m_Splitter.CreateView(0, 0, RUNTIME_CLASS(CProjectListDlg), CSize(rc.Width(), rc.Height()/3), pContext))
return false;
if (!m_Splitter.CreateView(1, 0, RUNTIME_CLASS(CBaseInfoDlg), CSize(rc.Width(), rc.Height()-rc.Height()/3), pContext))
return false;
return 0;
}在线等待!!!急啊!!!!
VERIFY(m_wndSplitter.CreateStatic(this, 2, 1));
VERIFY(m_wndSplitter.CreateView(1, 0,RUNTIME_CLASS(CMyView),
CSize(100, 100), pContext));
m_wndSplitter.SetRowInfo(0,200,0); VERIFY(m_wndSplitter1.CreateStatic(&m_wndSplitter, 1, 2,WS_CHILD|WS_VISIBLE,m_wndSplitter.IdFromRowCol(0,0)));
VERIFY(m_wndSplitter1.CreateView(0, 0, RUNTIME_CLASS(CSecView),
CSize(100, 200), pContext));
VERIFY(m_wndSplitter1.CreateView(0, 1,RUNTIME_CLASS(CLstView),
CSize(100, 200), pContext));m_wndSplitter,m_wndSplitter1是分别定义的两个变量,其他的看着改就可以了。
Step 1.首先Ctrl+W添加两个新类
CMyListView : CListView
CMyTreeView : CTreeViewStep 2.然后Project->Add to Project->Components and Controls
进入Visual C++ Components文件夹
选择添加Splitter Bar
一路OK就OK3.你会发现在CMainFrame中发现增加了一下函数
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
删除其中所有的内容
添加以下代码
m_wndSplitter.CreateStatic(this ,1, 2);
m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CTreeView), CSize(202, 0), pContext);
m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CListView), CSize(0, 0), pContext);return TRUE;Step 4.加入CTreeView,CListView的头文件即可Step 5.如有任何问题,可以发信给我
[email protected]
我尽力帮你解决---------------------------
May you succeed!
-------------------------------