📄 csdn_文档中心_怎样在一个一般窗口或是dialog上面使用分割窗口.htm
字号:
<TD><B> 怎样在一个一般窗口或是Dialog上面使用分割窗口.</B> ecore(原作)
</TD></TR>
<TR>
<TD align=middle height=5></TD>
<TD align=middle width=500></TD></TR>
<TR>
<TD align=middle bgColor=#003399><FONT color=#ffffff>关键字</FONT></TD>
<TD
width=500> 怎样在一个一般窗口或是Dialog上面使用分割窗口.</TD></TR>
<TR>
<TD align=middle height=5></TD>
<TD align=middle width=500></TD></TR></TBODY></TABLE><!--文章说明信息结束//-->
<TABLE border=0 width=600>
<TBODY>
<TR>
<TD align=left><BR>
<P> 小弟初次贴文,水平不高,希望不要丢东西.呵呵.</P>
<P>
大家都知道可以在一个CFrameWnd上面使用CSplitterWnd以做出分割窗口的效果(呵呵,顺便,分割窗口可是MFC程序的一大特色.原来(Delphi没有加上这个的支持之前),你只要看到了分割窗口,几乎可以肯定是MFC的.(哈哈,当然,也有人用SDK做一个出来,有这种闲的家伙么?呵呵,好象废话太多了点).</P>
<P>
可是现实中的情况是,有的时候我们要在一个一般的CWnd上面做一个SplitterWnd的效果.怎么办呢?MS的SplitterWnd只可以用于CFrameWnd(好像也可以用于CView类,MS的文档里说的).之所以有这个限制是因为TMD狗屎MS在SplitterWnd里面把所有要取Parent窗口的地方都设为CFrameWnd了.但实际上,它又没有用到CFrameWnd的任何特性.所以我们应该怎么做,好像是很明显的了.就是去翻MS的SplitterWnd的源码,把所有的用到了Parent的地方都改掉.啊!!!不是的,这还叫狗屁OOP?应该是重载一个我们自己的.</P>
<P>头文件:</P>
<P>// SplitWnd.h : implementation file<BR>// <BR>class CxSplitterWnd
: public CSplitterWnd<BR>{<BR> //
Construction<BR> public:<BR> CxSplitterWnd()
{};<BR> virtual ~CxSplitterWnd() {}; </P>
<P> // Operations<BR> public: <BR> //
Overrides<BR> // ClassWizard generated virtual function
overrides<BR> <A
href="file://{{/">file://{{/</A>AFX_VIRTUAL(CxSplitterWnd)<BR> <A
href="file://}}/">file://}}/</A>AFX_VIRTUAL </P>
<P> // Implementation<BR> public: <BR> // These are
the methods to be overridden<BR> virtual void StartTracking(int
ht); <BR> virtual CWnd* GetActivePane(int* pRow = NULL, int*
pCol = NULL);<BR> virtual void SetActivePane( int row, int col,
CWnd* pWnd = NULL ); <BR> virtual BOOL OnCommand(WPARAM wParam,
LPARAM lParam);<BR> virtual BOOL OnNotify( WPARAM wParam,
LPARAM lParam, LRESULT* pResult );<BR> virtual BOOL OnWndMsg(
UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult ); </P>
<P> // Generated message map
functions<BR> protected:<BR> <A
href="file://}}AFX_MSG/">file://}}AFX_MSG/</A>(CxSplitterWnd)<BR> //
NOTE - the ClassWizard will add and remove member functions
here.<BR> <A
href="file://}}/">file://}}/</A>AFX_MSG<BR> DECLARE_MESSAGE_MAP()<BR>};<BR></P>
<P>还有实现文件:</P>
<P><BR>// SplitWnd.cpp : implementation file<BR>// <BR>#include
"stdafx.h"<BR>#include "SplitWnd.h" </P>
<P>#ifdef _DEBUG<BR>#define new DEBUG_NEW<BR>#undef
THIS_FILE<BR>static char THIS_FILE[] = __FILE__;<BR>#endif </P>
<P>// HitTest return values (values and spacing between values is
important)<BR>// Had to adopt this because it has module scope
<BR>enum HitTestValue<BR>{<BR> noHit = 0,<BR> vSplitterBox
= 1,<BR> hSplitterBox = 2,<BR> bothSplitterBox = 3, //
just for keyboard<BR> vSplitterBar1 =
101,<BR> vSplitterBar15 = 115,<BR> hSplitterBar1 =
201,<BR> hSplitterBar15 = 215,<BR> splitterIntersection1 =
301,<BR> splitterIntersection225 = 525<BR>}; </P>
<P>/////////////////////////////////////////////////////////////////////////////<BR>//
CxSplitterWnd </P>
<P>BEGIN_MESSAGE_MAP(CxSplitterWnd, CSplitterWnd)<BR><A
href="file://{{/">file://{{/</A>AFX_MSG_MAP(CxSplitterWnd)<BR>//
NOTE - the ClassWizard will add and remove mapping macros
here.<BR><A
href="file://}}/">file://}}/</A>AFX_MSG_MAP<BR>END_MESSAGE_MAP()
</P>
<P>CWnd* CxSplitterWnd::GetActivePane(int* pRow, int*
pCol)<BR>{<BR> ASSERT_VALID(this); <BR> CWnd* pView =
GetFocus();<BR> // make sure the pane is a child pane of the
splitter<BR> if (pView != NULL && !IsChildPane(pView,
pRow, pCol))<BR> pView = NULL; <BR> return pView;<BR>}
</P>
<P>void CxSplitterWnd::SetActivePane( int row, int col, CWnd*
pWnd)<BR>{<BR> // set the focus to the pane<BR> CWnd*
pPane = pWnd == NULL ? GetPane(row, col) :
pWnd;<BR> pPane->SetFocus();<BR>} </P>
<P>void CxSplitterWnd::StartTracking(int
ht)<BR>{<BR>ASSERT_VALID(this);<BR> if (ht ==
noHit)<BR> return; <BR> // GetHitRect will restrict
'm_rectLimit' as appropriate<BR> GetInsideRect(m_rectLimit);
<BR> if (ht >= splitterIntersection1 && ht <=
splitterIntersection225)<BR> {<BR> // split two
directions (two tracking rectangles)<BR> int row = (ht -
splitterIntersection1) / 15;<BR> int col = (ht -
splitterIntersection1) % 15; <BR> GetHitRect(row +
vSplitterBar1, m_rectTracker);<BR> int yTrackOffset =
m_ptTrackOffset.y;<BR> m_bTracking2 =
TRUE;<BR> GetHitRect(col + hSplitterBar1,
m_rectTracker2);<BR> m_ptTrackOffset.y =
yTrackOffset;<BR> }<BR> else if (ht ==
bothSplitterBox)<BR> {<BR> // hit on splitter boxes
(for keyboard)<BR> GetHitRect(vSplitterBox,
m_rectTracker);<BR> int yTrackOffset =
m_ptTrackOffset.y;<BR> m_bTracking2 =
TRUE;<BR> GetHitRect(hSplitterBox,
m_rectTracker2);<BR> m_ptTrackOffset.y = yTrackOffset;
<BR> // center
it<BR> m_rectTracker.OffsetRect(0,
m_rectLimit.Height()/2);<BR> m_rectTracker2.OffsetRect(m_rectLimit.Width()/2,
0);<BR> }<BR> else<BR> {<BR> // only hit
one bar<BR> GetHitRect(ht, m_rectTracker);<BR> }
</P>
<P> // steal focus and
capture<BR> SetCapture();<BR> SetFocus(); <BR> //
make sure no updates are pending<BR> RedrawWindow(NULL, NULL,
RDW_ALLCHILDREN | RDW_UPDATENOW); <BR> // set tracking state
and appropriate cursor<BR> m_bTracking =
TRUE;<BR> OnInvertTracker(m_rectTracker);<BR> if
(m_bTracking2)<BR> OnInvertTracker(m_rectTracker2);<BR> m_htTrack
= ht;<BR> SetSplitCursor(ht);<BR>} </P>
<P>/////////////////////////////////////////////////////////////////////////////<BR>//
CSplitterWnd command routing <BR>BOOL
CxSplitterWnd::OnCommand(WPARAM wParam, LPARAM
lParam)<BR>{<BR> if (CWnd::OnCommand(wParam,
lParam))<BR> return TRUE; <BR> // route commands to the
splitter to the parent frame window<BR> return
GetParent()->SendMessage(WM_COMMAND, wParam, lParam);<BR>} </P>
<P>BOOL CxSplitterWnd::OnNotify( WPARAM wParam, LPARAM lParam,
LRESULT* pResult )<BR>{<BR> if (CWnd::OnNotify(wParam, lParam,
pResult))<BR> return TRUE; <BR> // route commands to the
splitter to the parent frame window<BR> *pResult =
GetParent()->SendMessage(WM_NOTIFY, wParam,
lParam);<BR> return TRUE;<BR>} </P>
<P>BOOL CxSplitterWnd::OnWndMsg(UINT message, WPARAM wParam, LPARAM
lParam, LRESULT* pResult)<BR>{ <BR> // The code line below is
necessary if using CxSplitterWnd in a regular dll<BR> //
AFX_MANAGE_STATE(AfxGetStaticModuleState()); <BR> return
CWnd::OnWndMsg(message, wParam, lParam, pResult);<BR>}<BR></P>
<P>把这个文件给包含进你的工程,就可以用CxSplitterWnd了.</P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center bgColor=#006699 border=0 cellPadding=0 cellSpacing=0
width=770>
<TBODY>
<TR bgColor=#006699>
<TD align=middle bgColor=#006699 id=white><FONT
color=#ffffff>对该文的评论</FONT></TD>
<TD align=middle>
<SCRIPT
src="CSDN_文档中心_怎样在一个一般窗口或是Dialog上面使用分割窗口.files/readnum.htm"></SCRIPT>
</TD></TR></TBODY></TABLE><BR>
<DIV align=center>
<TABLE align=center bgColor=#cccccc border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TH bgColor=#006699 id=white><FONT
color=#ffffff>我要评论</FONT></TH></TR></TBODY></TABLE></DIV>
<DIV align=center>
<TABLE border=0 width=770>
<TBODY>
<TR>
<TD>你没有登陆,无法发表评论。 请先<A
href="http://www.csdn.net/member/login.asp?from=/Develop/read_article.asp?id=2516">登陆</A>
<A
href="http://www.csdn.net/expert/zc.asp">我要注册</A><BR></TD></TR></TBODY></TABLE></DIV><BR>
<HR noShade SIZE=1 width=770>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=500>
<TBODY>
<TR align=middle>
<TD height=10 vAlign=bottom><A
href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A
href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A
href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> - <A
href="http://www.csdn.net/english">English</A> </TD>
<TD align=middle rowSpan=3><A
href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG
border=0 height=48
src="CSDN_文档中心_怎样在一个一般窗口或是Dialog上面使用分割窗口.files/biaoshi.gif"
width=40></A></TD></TR>
<TR align=middle>
<TD vAlign=top>百联美达美公司 版权所有 京ICP证020026号</TD></TR>
<TR align=middle>
<TD vAlign=top><FONT face=Verdana>Copyright © CSDN.net, Inc. All rights
reserved</FONT></TD></TR>
<TR>
<TD height=15></TD>
<TD></TD></TR></TBODY></TABLE></DIV>
<DIV></DIV><!--内容结束//--><!--结束//--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -