📄 用vc++在单文档界面中创建多视图-开发者网络-vc-天极yesky.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0037)http://www.yesky.com/97/1779597.shtml -->
<HTML lang=zh-CN xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>用VC++在单文档界面中创建多视图-开发者网络-VC-天极Yesky</TITLE>
<META content=用VC++在单文档界面中创建多视图, name=description>
<META content=用VC++在单文档界面中创建多视图, name=keywords>
<META content="天极Yesky | 全球中文IT第一门户" name=author>
<META content="天极Yesky | 全球中文IT第一门户" name=Copyright>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-CN><LINK media=all
href="用VC++在单文档界面中创建多视图-开发者网络-VC-天极Yesky.files/y_mobile_content.css"
type=text/css rel=stylesheet>
<SCRIPT src="用VC++在单文档界面中创建多视图-开发者网络-VC-天极Yesky.files/showlay.js"></SCRIPT>
<META content="MSHTML 6.00.2900.3157" name=GENERATOR></HEAD>
<BODY><!--页面头部--><!--头部-->
<DIV id=topmenu><A href="http://www.yesky.com/">Yesky首页</A>| <A
href="http://product.yesky.com/">产品报价</A>| <A
href="http://cseek.yesky.com/">行情</A>| <A href="http://mobile.yesky.com/">手机</A>
| <A href="http://digital.yesky.com/">数码</A> | <A
href="http://notebook.yesky.com/">笔记本</A> | <A
href="http://pc.yesky.com/">台式机</A> | <A href="http://diy.yesky.com/">DIY硬件</A>
| <A href="http://oa.yesky.com/">外设</A> | <A href="http://net.yesky.com/">网络</A>
| <A href="http://dh.yesky.com/">数字家庭</A> | <A
href="http://lab.yesky.com/">评测</A> | <A href="http://soft.yesky.com/">软件</A> |
<A href="http://e.yesky.com/">e时代</A> | <A href="http://game.yesky.com/">游戏</A>
| <A href="http://pic.yesky.com/">图片</A> | <A
href="http://desktop.yesky.com/">壁纸</A> | <A href="http://q.yesky.com/">群乐</A> |
<A href="http://my.yesky.com/">社区</A> | <A href="http://blog.yesky.com/">博客</A>
| <A href="http://www.mydown.com/">下载</A></DIV>
<DIV id=topbox>
<DIV class=tleft><A href="http://www.yesky.com/"><IMG alt=天极Yesky_全球中文IT第一门户
src="用VC++在单文档界面中创建多视图-开发者网络-VC-天极Yesky.files/logo.gif" border=0></A></DIV>
<DIV class=tad><SPAN id=ad1></SPAN></DIV>
<DIV id=search>
<DIV>
<FORM name=searchform action=http://search.chinabyte.com/search method=get
target=_blank><INPUT id=searchzz onmouseover=this.focus() onfocus=this.select()
name=q><INPUT type=hidden value=GB2312 name=encoding><INPUT type=hidden
value=connect name=dir><INPUT type=hidden value=20002 name=cid><INPUT id=search_btn type=submit value=天极搜索> </FORM></DIV>
<DIV class=tdq>
<DIV class=rightarea><A href="http://bj.yesky.com/">北京</A> <A
href="http://hd.yesky.com/">上海</A> <A href="http://gd.yesky.com/">广东</A> <A
href="http://xa.yesky.com/">西安</A><BR><A href="http://cq.yesky.com/">重庆</A> <A
href="http://cd.yesky.com/">成都</A> <A href="http://sy.yesky.com/">沈阳</A> <A
href="http://js.yesky.com/">江苏</A> </DIV>
<DIV class=rightarea_right><A
href="http://my.yesky.com/">用户<BR>登录</A></DIV></DIV></DIV>
<DIV class=tright>
<DIV class=box1>
<SCRIPT src="用VC++在单文档界面中创建多视图-开发者网络-VC-天极Yesky.files/content_text_ad.js"
type=text/javascript></SCRIPT>
</DIV></DIV></DIV>
<SCRIPT src="用VC++在单文档界面中创建多视图-开发者网络-VC-天极Yesky.files/flash.js"
type=text/javascript></SCRIPT>
<!--导航条-->
<DIV id=location>
<DIV class=loleft>您现在的位置: <A href="http://www.yesky.com/">天极Yesky</A> > <A
href="http://soft.yesky.com/">软件频道</A> > <A
href="http://dev.yesky.com/">开发者网络</A> > 用VC++在单文档界面中创建多视图</DIV>
<DIV class=adright><SPAN id=ad2></SPAN></DIV></DIV><!--内容块开始-->
<DIV id=conbox><!--左边开始-->
<DIV id=conleft>
<DIV id=contopla1>
<DIV id=__001>
<DIV class=qkong></DIV>
<DIV class=qw1>全文</DIV>
<DIV class=zkong>
<DIV class=kl></DIV>
<DIV class=bj><A href="http://www.yesky.com/97/1779597.shtml#pls"
target=_self>评论</A></DIV>
<DIV class=kr></DIV>
<SCRIPT type=text/javascript>
var titiepic ="#";
if (titiepic!="#")
{
document.write("<div class=\"kl\"></div><div class=\"bj\"><a href=\"#\" target=\"_blank\">图片</a></div><div class=\"kr\"></div>");
}
</SCRIPT>
</DIV></DIV></DIV>
<DIV class=topadbg><SPAN id=ad10></SPAN></DIV><A name=top></A>
<DIV id=contitle>
<H1>用VC++在单文档界面中创建多视图</H1></DIV>
<DIV id=conauthor><SPAN>2004-03-23 10:12 </SPAN><SPAN>作者: 周伟 </SPAN><SPAN>出处:
CESDN </SPAN><SPAN>责任编辑:<A title=向本编辑提问
href="http://comments.yesky.com/t/·½ÖÛ/6,324/1779597.shtml" target=_blank>方舟</A>
</SPAN></DIV>
<DIV class=topadbg><SPAN id=ad9></SPAN></DIV>
<DIV id=conneirong><SPAN id=ad3></SPAN>
<DIV class=guanggao><SPAN id=contentAdv></SPAN></DIV>
<TABLE cellSpacing=0 cellPadding=5 width=570 bgColor=#fbe392 border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=5 width=570 border=0>
<TBODY>
<TR>
<TD align=middle width=200 bgColor=#e1b004><FONT color=#ffffff><A
href="http://www.my5757.com/yesky/dy.jsp"
target=_blank>天极IT资讯短信服务</A> <B>电脑小技巧</B></FONT><BR>
<TABLE cellSpacing=0 cellPadding=3 width="100%" bgColor=#fffcc0
border=0>
<SCRIPT> function check4() { if (dn.mobile.value.length!=11) { alert("手机号码不正确!"); dn.mobile.focus(); return false; } return true; } </SCRIPT>
<FORM name=dn onsubmit="return check4()"
action=http://www.my5757.com/tj/join.jsp target=_blank>
<TBODY>
<TR vAlign=center>
<TD>资费:包月5元<BR>手机: <INPUT
style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid; HEIGHT: 16px"
size=11 name=mobile> <INPUT type=image height=18 width=45
src="" align=middle border=0 name=image2> </TD></TR><INPUT
type=hidden value=yjq name=stype> </FORM></TBODY></TABLE></TD>
<TD width=370
bgColor=#fbc403>介绍:细处着手,巧处用功。高手和菜鸟之间的差别就是:高手什么都知道,菜鸟知道一些。电脑小技巧收集最新奇招高招,让你轻松踏上高手之路。
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR> 一个单文档界面中存在多个视图,并且可以根据需要进行视图的动态切换,这是当前比较流行的界面风格,它可以满足许多用户在操作和显示方面的需要。这种界面风格的主要代表软件是Outlook
Express。而用VC++实现这种风格的界面有一定难度,笔者就这个问题进行了研究,并归纳总结出两种实现方法(这些代码都在VC++
6.0下调试通过),使用时关键注意步骤和实现思路,不必拘泥于代码的形式。<BR><BR><IFRAME align=center marginWidth=0
marginHeight=0 src="用VC++在单文档界面中创建多视图-开发者网络-VC-天极Yesky.files/dell-240200.htm"
frameBorder=0 width=360 scrolling=no
height=300></IFRAME><BR><BR> 方法一:静态创建切换法<BR><BR> 步骤描述:<BR><BR> 1.在窗口显示之前先将需要切换的所有的视图对象创建好,除首先显示的视图以外,其他在创建时都设置为不可见属性。<BR><BR>
<TABLE width="100%" bgColor=#ffffff>
<TBODY>
<TR>
<TD> CMyWinApp::InitInstance()<BR> { ......<BR> m_pViews[0] =
pView1;<BR> m_pViews[1] = (CView*) new CView2;<BR> CDocument*
pCurrentDoc = ((CFrameWnd*) m_pMainWnd)->GetActiveDocument();<BR> //
初始化创建上下文相关指针<BR> CCreateContext
newContext;<BR> newContext.m_pNewViewClass =
NULL;<BR> newContext.m_pNewDocTemplate =
NULL;<BR> newContext.m_pLastView = NULL;<BR> newContext.m_pCurrentFrame
= NULL;<BR> newContext.m_pCurrentDoc = pCurrentDoc;<BR> //
最初激活视的ID为AFX_IDW_PANE_FIRST,<BR> //对新创建的视图增加这个值,注意对CSplitterWnd不能这样使用<BR> UINT
viewID[2];<BR> viewID[1] = AFX_IDW_PANE_FIRST + 1;<BR> CRect rect(0, 0,
0, 0);<BR> for ( int nView=1; nView<NUMVIEWS; nView++ ) {<BR> //
创建新的视图,创建的视图在应用中永久存在,直到应用程序退出,<BR> //应用程序会自动删除新创建的视图<BR> m_pViews[nView]->Create(NULL,
NULL,<BR> (AFX_WS_DEFAULT_VIEW & ~WS_VISIBLE),<BR> //
AFX_WS_DEFAULT_VIEW代表(WS_BORDER | WS_VISIBLE | WS_CHILD)<BR> rect,
m_pMainWnd, viewID[nView], &newContext);<BR> }<BR> //
当文档模板创建视图的时候,会自动发送WM_INITIALUPDATE消息,<BR> //因此对于我们自己创建的视图,需要人工发送这条消息<BR> ((CForm2*)m_pViews[1])->OnInitialUpdate();<BR> ((CVswapView*)m_pViews[2])->OnInitialUpdate();<BR> ......<BR> }</TD></TR></TBODY></TABLE><BR> 2.视图的切换<BR><BR>
<TABLE width="100%" bgColor=#ffffff>
<TBODY>
<TR>
<TD> CView* CMyWinApp::SwitchView( UINT nIndex )<BR> {<BR> ASSERT(
nIndex >=0 && nIndex < NUMVIEWS );<BR> CView* pNewView =
m_pViews[nIndex];<BR> CView* pActiveView =((CFrameWnd*)
m_pMainWnd)->GetActiveView();<BR> if ( !pActiveView ) //
当前没有激活的视图<BR> return NULL;<BR> if ( pNewView == pActiveView ) //
当前视图和需要切换的视图相同<BR> return pActiveView;<BR> //
交换视图的窗口ID,使RecalcLayout()可以工作<BR> UINT temp =
::GetWindowLong(pActiveView->m_hWnd,
GWL_ID);<BR> ::SetWindowLong(pActiveView->m_hWnd, GWL_ID,
::GetWindowLong(pNewView->m_hWnd,
GWL_ID));<BR> ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);<BR> //
显示新的视图,隐藏前一个视图<BR> pActiveView->ShowWindow(SW_HIDE);<BR> pNewView->ShowWindow(SW_SHOW);<BR> ((CFrameWnd*)
m_pMainWnd)->SetActiveView(pNewView);<BR> ((CFrameWnd*)
m_pMainWnd)->RecalcLayout();<BR> pNewView->Invalidate();<BR> return
pActiveView;<BR> }</TD></TR></TBODY></TABLE><BR>
<SCRIPT>zmbbs=1;</SCRIPT>
<DIV class=right>共2页。 <A class=page href="http://www.yesky.com/97/1779597.shtml"
target=_self><FONT color=#666666><B>1</B></FONT></A> <A class=page
href="http://www.yesky.com/97/1779597_1.shtml" target=_self><B>2</B></A> <A
class=page href="http://www.yesky.com/97/1779597_1.shtml" target=_self><FONT
face=Webdings>8</FONT></A> <A class=page
href="http://www.yesky.com/97/1779597_1.shtml" target=_self><FONT
face=Webdings>:</FONT></A></DIV></DIV><!--广告代码开始-->
<SCRIPT>
var ad_cid;
if (window.location.search.substring(1) != "")
{
ad_cid = window.location.search.substring(1);
} else {
ad_cid = 412;
}
</SCRIPT>
<!--小通栏:c-scolumn顶部500*90--><SPAN id=span_ad1>
<SCRIPT language=JavaScript>
document.write("<script src=\"http://vd.yesky.com/html/"+ad_cid+"/"+ad_cid+"_c-scolumn.js\"><\/script>");</SCRIPT>
</SPAN>
<SCRIPT language=JavaScript>
document.getElementById("ad1").innerHTML=document.getElementById("span_ad1").innerHTML;
document.getElementById("span_ad1").innerHTML="";
</SCRIPT>
<!--c-pip文章正文中间240*200--><SPAN id=span_ad3>
<SCRIPT language=JavaScript>
document.write("<script src=\"http://vd.yesky.com/html/"+ad_cid+"/"+ad_cid+"_c-pip.js\"><\/script>");</SCRIPT>
</SPAN>
<SCRIPT>
if(document.getElementById("contentAdv")) {
document.getElementById("contentAdv").innerHTML=document.getElementById("span_ad3").innerHTML;
document.getElementById("span_ad3").innerHTML="";
} else {
document.getElementById("ad3").innerHTML=document.getElementById("span_ad3").innerHTML;
document.getElementById("span_ad3").innerHTML="";
}</SCRIPT>
<!--c-text-1“您现在的位置”右侧文字--><SPAN id=span_ad2>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -