单文档SDI可以建立多视么? 可以建立多视,用ShowWindow(SW_SHOW),或ShowWindow(SW_HIDE)切换。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <<VC技术内幕>>第20章"拆分窗口和多重视图"有例子 我有例子void CChildFrame::OnViewDesign() { // TODO: Add your command handler code here CWBuilderDoc * pDoc=(CWBuilderDoc *)this->GetActiveDocument(); if (NULL==m_pDesignView){ m_pSourceView=(CWmlEditView *)GetActiveView(); m_pDesignView=new CWBuilderView(); m_pDesignView->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,rectDefault,this,AFX_IDW_PANE_FIRST+1,NULL); } if ((pDoc->IsModified()==TRUE) and and (pDoc->GetPathName()=="")){ AfxMessageBox("必须首先保存文件!"); return; } pDoc->AddView(m_pDesignView); m_pDesignView->SetDlgCtrlID(AFX_IDW_PANE_FIRST); m_pSourceView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1); m_pDesignView->ShowWindow(SW_SHOW); m_pSourceView->ShowWindow(SW_HIDE); this->SetActiveView(m_pDesignView); pDoc->RemoveView(m_pSourceView); m_pDesignView->m_card_num=0; m_pDesignView->m_tree_ctrl.DeleteAllItems(); MSXML::IXMLDocumentPtr xmlDoc; MSXML::IXMLElementPtr xmlElem; MSXML::IXMLElementCollectionPtr xmlElemCol; CoInitialize(NULL); xmlDoc.CreateInstance(__uuidof(MSXML::XMLDocument)); xmlDoc->url=_bstr_t(pDoc->GetPathName()); while (xmlDoc->readyState!=READYSTATE_COMPLETE); xmlElem=xmlDoc->root; CString str="<"; str+=xmlElem->tagName; str+=">"; str+=xmlElem->text; HTREEITEM ti1=m_pDesignView->m_tree_ctrl.InsertItem(str,TVI_ROOT); m_pDesignView->AddSubTree(ti1,xmlElem); xmlElem.Release(); xmlDoc.Release(); for (int i=0;i<=pDoc->m_file_content.GetUpperBound();i++){ CString & str=pDoc->m_file_content.ElementAt(i); m_pDesignView->m_file_content+=str; m_pDesignView->m_file_content+=" "; } while (m_pDesignView->m_file_content.Replace(" "," ")); m_pDesignView->m_file_content.Replace("< ","<"); m_pDesignView->m_file_content.Replace("</ ","</"); m_pDesignView->m_file_content.Replace(" >",">"); int card_start=m_pDesignView->m_file_content.Find("<card"); int card_end=m_pDesignView->m_file_content.Find("</card"); m_pDesignView->m_file_content=m_pDesignView->m_file_content.Mid(card_start,card_end-card_start); m_pDesignView->m_file_content.Replace("<card","<body"); m_pDesignView->m_file_content+="</body>"; CStdioFile file("c:\\temp.tmp",CFile::modeCreate and CFile::modeWrite); file.WriteString(m_pDesignView->m_file_content); file.Close(); m_pDesignView->m_html_view->Navigate("c:\\temp.tmp"); CoUninitialize(); RecalcLayout();}void CChildFrame::OnViewSource() { // TODO: Add your command handler code here CDocument * pDoc=this->GetActiveDocument(); pDoc->AddView(m_pSourceView); m_pSourceView->SetDlgCtrlID(AFX_IDW_PANE_FIRST); m_pDesignView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1); m_pSourceView->ShowWindow(SW_SHOW); m_pDesignView->ShowWindow(SW_HIDE); this->SetActiveView(m_pSourceView); pDoc->RemoveView(m_pDesignView); RecalcLayout(); ::CreateCaret(m_pSourceView->m_hWnd,NULL,2,16); m_pSourceView->ShowCaret();}void CChildFrame::OnUpdateViewDesign(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(GetActiveView()->IsKindOf(RUNTIME_CLASS(CWmlEditView)));}void CChildFrame::OnUpdateViewSource(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(GetActiveView()->IsKindOf(RUNTIME_CLASS(CWBuilderView)));} 我有例子void CChildFrame::OnViewDesign() { // TODO: Add your command handler code here CWBuilderDoc * pDoc=(CWBuilderDoc *)this->GetActiveDocument(); if (NULL==m_pDesignView){ m_pSourceView=(CWmlEditView *)GetActiveView(); m_pDesignView=new CWBuilderView(); m_pDesignView->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,rectDefault,this,AFX_IDW_PANE_FIRST+1,NULL); } if ((pDoc->IsModified()==TRUE) and and (pDoc->GetPathName()=="")){ AfxMessageBox("必须首先保存文件!"); return; } pDoc->AddView(m_pDesignView); m_pDesignView->SetDlgCtrlID(AFX_IDW_PANE_FIRST); m_pSourceView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1); m_pDesignView->ShowWindow(SW_SHOW); m_pSourceView->ShowWindow(SW_HIDE); this->SetActiveView(m_pDesignView); pDoc->RemoveView(m_pSourceView); m_pDesignView->m_card_num=0; m_pDesignView->m_tree_ctrl.DeleteAllItems(); MSXML::IXMLDocumentPtr xmlDoc; MSXML::IXMLElementPtr xmlElem; MSXML::IXMLElementCollectionPtr xmlElemCol; CoInitialize(NULL); xmlDoc.CreateInstance(__uuidof(MSXML::XMLDocument)); xmlDoc->url=_bstr_t(pDoc->GetPathName()); while (xmlDoc->readyState!=READYSTATE_COMPLETE); xmlElem=xmlDoc->root; CString str="<"; str+=xmlElem->tagName; str+=">"; str+=xmlElem->text; HTREEITEM ti1=m_pDesignView->m_tree_ctrl.InsertItem(str,TVI_ROOT); m_pDesignView->AddSubTree(ti1,xmlElem); xmlElem.Release(); xmlDoc.Release(); for (int i=0;i<=pDoc->m_file_content.GetUpperBound();i++){ CString & str=pDoc->m_file_content.ElementAt(i); m_pDesignView->m_file_content+=str; m_pDesignView->m_file_content+=" "; } while (m_pDesignView->m_file_content.Replace(" "," ")); m_pDesignView->m_file_content.Replace("< ","<"); m_pDesignView->m_file_content.Replace("</ ","</"); m_pDesignView->m_file_content.Replace(" >",">"); int card_start=m_pDesignView->m_file_content.Find("<card"); int card_end=m_pDesignView->m_file_content.Find("</card"); m_pDesignView->m_file_content=m_pDesignView->m_file_content.Mid(card_start,card_end-card_start); m_pDesignView->m_file_content.Replace("<card","<body"); m_pDesignView->m_file_content+="</body>"; CStdioFile file("c:\\temp.tmp",CFile::modeCreate and CFile::modeWrite); file.WriteString(m_pDesignView->m_file_content); file.Close(); m_pDesignView->m_html_view->Navigate("c:\\temp.tmp"); CoUninitialize(); RecalcLayout();}void CChildFrame::OnViewSource() { // TODO: Add your command handler code here CDocument * pDoc=this->GetActiveDocument(); pDoc->AddView(m_pSourceView); m_pSourceView->SetDlgCtrlID(AFX_IDW_PANE_FIRST); m_pDesignView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1); m_pSourceView->ShowWindow(SW_SHOW); m_pDesignView->ShowWindow(SW_HIDE); this->SetActiveView(m_pSourceView); pDoc->RemoveView(m_pDesignView); RecalcLayout(); ::CreateCaret(m_pSourceView->m_hWnd,NULL,2,16); m_pSourceView->ShowCaret();}void CChildFrame::OnUpdateViewDesign(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(GetActiveView()->IsKindOf(RUNTIME_CLASS(CWmlEditView)));}void CChildFrame::OnUpdateViewSource(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(GetActiveView()->IsKindOf(RUNTIME_CLASS(CWBuilderView)));} 单文档多视的问题,我在前两天刚作了一个例子:首先在应有程序类中声明: CView *pOldView; CView *pNewView;然后在实现文件中的 ProcessShellCommand()后加入 CView* pActiveView = ((CFrameWnd*)m_pMainWnd)->GetActiveView(); m_pOldView = pActiveView; //保存旧视 m_pNewView = (CView*) new CTrainForm; //新视 CDocument* pCurrentDoc= ((CFrameWnd*)m_pMainWnd)->GetActiveDocument();//取得活动文档 /* 初始化CCreateContext对象,使其指向活动文档。用它为文档增加在 CView::OnCreate()函数中生成的新视 */ CCreateContext newContext; newContext.m_pNewViewClass = NULL; newContext.m_pNewDocTemplate = NULL; newContext.m_pLastView = NULL; newContext.m_pCurrentFrame = NULL; newContext.m_pCurrentDoc = pCurrentDoc; //指向活动文档 // 初始活动视的ID为AFX_IDW_PANE_FIRST,该值按1递增赋予新视 UINT viewID = AFX_IDW_PANE_FIRST + 1; // 创建新视 CRect rect(0, 0, 0, 0); //注意初始化参数为0 m_pNewView->Create(NULL, "AnyWindowName", WS_CHILD, rect, m_pMainWnd, viewID, &newContext); //发送WM_INITIALUPDATE消息 m_pNewView->SendMessage(WM_INITIALUPDATE, 0, 0);然后在利用函数 SwitchView(CView * pNewView)来实现切换它的定以为: CView* CHhApp::SwitchView(CView * pNewView){ //取得活动视 CView* pActiveView = ((CFrameWnd*) m_pMainWnd)->GetActiveView(); //交换视窗口的标识 #ifndef _WIN32 //不是Win32应用,注意使用函数为Word型 UINT temp =::GetWindowWord(pActiveView->m_hWnd, GWW_ID); ::SetWindowWord(pActiveView->m_hWnd, GWW_ID, ::GetWindowWord(pNewView->m_hWnd, GWW_ID)); ::SetWindowWord(pNewView->m_hWnd, GWW_ID, temp); #else //不是Win32应用,注意使用函数为Long型 UINT temp =::GetWindowLong(pActiveView->m_hWnd, GWL_ID); ::SetWindowLong(pActiveView->m_hWnd, GWL_ID, ::GetWindowLong(pNewView->m_hWnd, GWL_ID)); ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp); #endif pActiveView->ShowWindow(SW_HIDE); //将当前视图隐藏 pNewView->ShowWindow(SW_SHOW); //显示新视图 ((CFrameWnd*) m_pMainWnd)->SetActiveView(pNewView); //设置新视图为活动视图 ((CFrameWnd*) m_pMainWnd)->RecalcLayout(); //重新布局 pNewView->Invalidate(); //重绘 return pActiveView; //返回活动视} 为什么串口通讯,数据收不到 怎么没有高手帮我解决这个问题,代码比较长 visual studio 2010和vc6.0在mfc上面主要有哪些不同啊??求大神知道 有用过ReadDirectoryChangesW 的大大吗,进来哈子 vc与.NET比较 请教多线程中使用socket的问题,急,盼复!谢谢! 三合一的问题,哪位高手能解决呢? 有BHO插件开发经验的朋友近来讨论一个问题! 以下是什么问题呢? 寻求一高手做图像识别(有偿) 为什么参数传递不到函数中? VC初学者的问题,求助于大侠 (关于自定义消息)
void CChildFrame::OnViewDesign()
{
// TODO: Add your command handler code here
CWBuilderDoc * pDoc=(CWBuilderDoc *)this->GetActiveDocument();
if (NULL==m_pDesignView){
m_pSourceView=(CWmlEditView *)GetActiveView();
m_pDesignView=new CWBuilderView();
m_pDesignView->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,rectDefault,this,AFX_IDW_PANE_FIRST+1,NULL);
}
if ((pDoc->IsModified()==TRUE) and and (pDoc->GetPathName()=="")){
AfxMessageBox("必须首先保存文件!");
return;
}
pDoc->AddView(m_pDesignView);
m_pDesignView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_pSourceView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1); m_pDesignView->ShowWindow(SW_SHOW);
m_pSourceView->ShowWindow(SW_HIDE); this->SetActiveView(m_pDesignView); pDoc->RemoveView(m_pSourceView);
m_pDesignView->m_card_num=0;
m_pDesignView->m_tree_ctrl.DeleteAllItems();
MSXML::IXMLDocumentPtr xmlDoc;
MSXML::IXMLElementPtr xmlElem;
MSXML::IXMLElementCollectionPtr xmlElemCol;
CoInitialize(NULL);
xmlDoc.CreateInstance(__uuidof(MSXML::XMLDocument));
xmlDoc->url=_bstr_t(pDoc->GetPathName());
while (xmlDoc->readyState!=READYSTATE_COMPLETE);
xmlElem=xmlDoc->root; CString str="<";
str+=xmlElem->tagName;
str+=">";
str+=xmlElem->text; HTREEITEM ti1=m_pDesignView->m_tree_ctrl.InsertItem(str,TVI_ROOT); m_pDesignView->AddSubTree(ti1,xmlElem); xmlElem.Release();
xmlDoc.Release(); for (int i=0;i<=pDoc->m_file_content.GetUpperBound();i++){
CString & str=pDoc->m_file_content.ElementAt(i);
m_pDesignView->m_file_content+=str;
m_pDesignView->m_file_content+=" ";
} while (m_pDesignView->m_file_content.Replace(" "," "));
m_pDesignView->m_file_content.Replace("< ","<");
m_pDesignView->m_file_content.Replace("</ ","</");
m_pDesignView->m_file_content.Replace(" >",">");
int card_start=m_pDesignView->m_file_content.Find("<card");
int card_end=m_pDesignView->m_file_content.Find("</card");
m_pDesignView->m_file_content=m_pDesignView->m_file_content.Mid(card_start,card_end-card_start);
m_pDesignView->m_file_content.Replace("<card","<body");
m_pDesignView->m_file_content+="</body>";
CStdioFile file("c:\\temp.tmp",CFile::modeCreate and CFile::modeWrite);
file.WriteString(m_pDesignView->m_file_content);
file.Close();
m_pDesignView->m_html_view->Navigate("c:\\temp.tmp");
CoUninitialize();
RecalcLayout();
}void CChildFrame::OnViewSource()
{
// TODO: Add your command handler code here
CDocument * pDoc=this->GetActiveDocument(); pDoc->AddView(m_pSourceView);
m_pSourceView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_pDesignView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1); m_pSourceView->ShowWindow(SW_SHOW);
m_pDesignView->ShowWindow(SW_HIDE); this->SetActiveView(m_pSourceView); pDoc->RemoveView(m_pDesignView);
RecalcLayout();
::CreateCaret(m_pSourceView->m_hWnd,NULL,2,16);
m_pSourceView->ShowCaret();
}void CChildFrame::OnUpdateViewDesign(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(GetActiveView()->IsKindOf(RUNTIME_CLASS(CWmlEditView)));
}void CChildFrame::OnUpdateViewSource(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(GetActiveView()->IsKindOf(RUNTIME_CLASS(CWBuilderView)));
}
void CChildFrame::OnViewDesign()
{
// TODO: Add your command handler code here
CWBuilderDoc * pDoc=(CWBuilderDoc *)this->GetActiveDocument();
if (NULL==m_pDesignView){
m_pSourceView=(CWmlEditView *)GetActiveView();
m_pDesignView=new CWBuilderView();
m_pDesignView->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,rectDefault,this,AFX_IDW_PANE_FIRST+1,NULL);
}
if ((pDoc->IsModified()==TRUE) and and (pDoc->GetPathName()=="")){
AfxMessageBox("必须首先保存文件!");
return;
}
pDoc->AddView(m_pDesignView);
m_pDesignView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_pSourceView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1); m_pDesignView->ShowWindow(SW_SHOW);
m_pSourceView->ShowWindow(SW_HIDE); this->SetActiveView(m_pDesignView); pDoc->RemoveView(m_pSourceView);
m_pDesignView->m_card_num=0;
m_pDesignView->m_tree_ctrl.DeleteAllItems();
MSXML::IXMLDocumentPtr xmlDoc;
MSXML::IXMLElementPtr xmlElem;
MSXML::IXMLElementCollectionPtr xmlElemCol;
CoInitialize(NULL);
xmlDoc.CreateInstance(__uuidof(MSXML::XMLDocument));
xmlDoc->url=_bstr_t(pDoc->GetPathName());
while (xmlDoc->readyState!=READYSTATE_COMPLETE);
xmlElem=xmlDoc->root; CString str="<";
str+=xmlElem->tagName;
str+=">";
str+=xmlElem->text; HTREEITEM ti1=m_pDesignView->m_tree_ctrl.InsertItem(str,TVI_ROOT); m_pDesignView->AddSubTree(ti1,xmlElem); xmlElem.Release();
xmlDoc.Release(); for (int i=0;i<=pDoc->m_file_content.GetUpperBound();i++){
CString & str=pDoc->m_file_content.ElementAt(i);
m_pDesignView->m_file_content+=str;
m_pDesignView->m_file_content+=" ";
} while (m_pDesignView->m_file_content.Replace(" "," "));
m_pDesignView->m_file_content.Replace("< ","<");
m_pDesignView->m_file_content.Replace("</ ","</");
m_pDesignView->m_file_content.Replace(" >",">");
int card_start=m_pDesignView->m_file_content.Find("<card");
int card_end=m_pDesignView->m_file_content.Find("</card");
m_pDesignView->m_file_content=m_pDesignView->m_file_content.Mid(card_start,card_end-card_start);
m_pDesignView->m_file_content.Replace("<card","<body");
m_pDesignView->m_file_content+="</body>";
CStdioFile file("c:\\temp.tmp",CFile::modeCreate and CFile::modeWrite);
file.WriteString(m_pDesignView->m_file_content);
file.Close();
m_pDesignView->m_html_view->Navigate("c:\\temp.tmp");
CoUninitialize();
RecalcLayout();
}void CChildFrame::OnViewSource()
{
// TODO: Add your command handler code here
CDocument * pDoc=this->GetActiveDocument(); pDoc->AddView(m_pSourceView);
m_pSourceView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_pDesignView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1); m_pSourceView->ShowWindow(SW_SHOW);
m_pDesignView->ShowWindow(SW_HIDE); this->SetActiveView(m_pSourceView); pDoc->RemoveView(m_pDesignView);
RecalcLayout();
::CreateCaret(m_pSourceView->m_hWnd,NULL,2,16);
m_pSourceView->ShowCaret();
}void CChildFrame::OnUpdateViewDesign(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(GetActiveView()->IsKindOf(RUNTIME_CLASS(CWmlEditView)));
}void CChildFrame::OnUpdateViewSource(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(GetActiveView()->IsKindOf(RUNTIME_CLASS(CWBuilderView)));
}
首先在应有程序类中声明:
CView *pOldView;
CView *pNewView;
然后在实现文件中的 ProcessShellCommand()后加入
CView* pActiveView = ((CFrameWnd*)m_pMainWnd)->GetActiveView();
m_pOldView = pActiveView; //保存旧视
m_pNewView = (CView*) new CTrainForm; //新视
CDocument* pCurrentDoc=
((CFrameWnd*)m_pMainWnd)->GetActiveDocument();//取得活动文档
/* 初始化CCreateContext对象,使其指向活动文档。用它为文档增加在
CView::OnCreate()函数中生成的新视 */
CCreateContext newContext;
newContext.m_pNewViewClass = NULL;
newContext.m_pNewDocTemplate = NULL;
newContext.m_pLastView = NULL;
newContext.m_pCurrentFrame = NULL;
newContext.m_pCurrentDoc = pCurrentDoc; //指向活动文档
// 初始活动视的ID为AFX_IDW_PANE_FIRST,该值按1递增赋予新视
UINT viewID = AFX_IDW_PANE_FIRST + 1;
// 创建新视
CRect rect(0, 0, 0, 0); //注意初始化参数为0
m_pNewView->Create(NULL, "AnyWindowName", WS_CHILD, rect, m_pMainWnd, viewID, &newContext);
//发送WM_INITIALUPDATE消息
m_pNewView->SendMessage(WM_INITIALUPDATE, 0, 0);然后在利用函数 SwitchView(CView * pNewView)来实现切换
它的定以为:
CView* CHhApp::SwitchView(CView * pNewView)
{
//取得活动视
CView* pActiveView = ((CFrameWnd*) m_pMainWnd)->GetActiveView();
//交换视窗口的标识
#ifndef _WIN32 //不是Win32应用,注意使用函数为Word型
UINT temp =::GetWindowWord(pActiveView->m_hWnd, GWW_ID);
::SetWindowWord(pActiveView->m_hWnd, GWW_ID,
::GetWindowWord(pNewView->m_hWnd, GWW_ID));
::SetWindowWord(pNewView->m_hWnd, GWW_ID, temp);
#else //不是Win32应用,注意使用函数为Long型
UINT temp =::GetWindowLong(pActiveView->m_hWnd, GWL_ID);
::SetWindowLong(pActiveView->m_hWnd, GWL_ID,
::GetWindowLong(pNewView->m_hWnd, GWL_ID));
::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);
#endif
pActiveView->ShowWindow(SW_HIDE); //将当前视图隐藏
pNewView->ShowWindow(SW_SHOW); //显示新视图
((CFrameWnd*) m_pMainWnd)->SetActiveView(pNewView); //设置新视图为活动视图
((CFrameWnd*) m_pMainWnd)->RecalcLayout(); //重新布局
pNewView->Invalidate(); //重绘
return pActiveView; //返回活动视
}