?? csdn_文檔中心_怎樣在一個(gè)一般窗口或是dialog上面使用分割窗口.htm
字號(hào):
<TD><B> 怎樣在一個(gè)一般窗口或是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>關(guān)鍵字</FONT></TD>
<TD
width=500> 怎樣在一個(gè)一般窗口或是Dialog上面使用分割窗口.</TD></TR>
<TR>
<TD align=middle height=5></TD>
<TD align=middle width=500></TD></TR></TBODY></TABLE><!--文章說明信息結(jié)束//-->
<TABLE border=0 width=600>
<TBODY>
<TR>
<TD align=left><BR>
<P> 小弟初次貼文,水平不高,希望不要丟東西.呵呵.</P>
<P>
大家都知道可以在一個(gè)CFrameWnd上面使用CSplitterWnd以做出分割窗口的效果(呵呵,順便,分割窗口可是MFC程序的一大特色.原來(Delphi沒有加上這個(gè)的支持之前),你只要看到了分割窗口,幾乎可以肯定是MFC的.(哈哈,當(dāng)然,也有人用SDK做一個(gè)出來,有這種閑的家伙么?呵呵,好象廢話太多了點(diǎn)).</P>
<P>
可是現(xiàn)實(shí)中的情況是,有的時(shí)候我們要在一個(gè)一般的CWnd上面做一個(gè)SplitterWnd的效果.怎么辦呢?MS的SplitterWnd只可以用于CFrameWnd(好像也可以用于CView類,MS的文檔里說的).之所以有這個(gè)限制是因?yàn)門MD狗屎MS在SplitterWnd里面把所有要取Parent窗口的地方都設(shè)為CFrameWnd了.但實(shí)際上,它又沒有用到CFrameWnd的任何特性.所以我們應(yīng)該怎么做,好像是很明顯的了.就是去翻MS的SplitterWnd的源碼,把所有的用到了Parent的地方都改掉.啊!!!不是的,這還叫狗屁OOP?應(yīng)該是重載一個(gè)我們自己的.</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>還有實(shí)現(xiàn)文件:</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>把這個(gè)文件給包含進(jìn)你的工程,就可以用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>對(duì)該文的評(píng)論</FONT></TD>
<TD align=middle>
<SCRIPT
src="CSDN_文檔中心_怎樣在一個(gè)一般窗口或是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>我要評(píng)論</FONT></TH></TR></TBODY></TABLE></DIV>
<DIV align=center>
<TABLE border=0 width=770>
<TBODY>
<TR>
<TD>你沒有登陸,無法發(fā)表評(píng)論。 請(qǐng)先<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">我要注冊(cè)</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">網(wǎng)站簡(jiǎn)介</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=5">廣告服務(wù)</A> - <A
href="http://www.csdn.net/map/map.shtm">網(wǎng)站地圖</A> - <A
href="http://www.csdn.net/help/help.asp">幫助信息</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=2">聯(lián)系方式</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_文檔中心_怎樣在一個(gè)一般窗口或是Dialog上面使用分割窗口.files/biaoshi.gif"
width=40></A></TD></TR>
<TR align=middle>
<TD vAlign=top>百聯(lián)美達(dá)美公司 版權(quán)所有 京ICP證020026號(hào)</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><!--內(nèi)容結(jié)束//--><!--結(jié)束//--></BODY></HTML>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -