⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csdn_文档中心_怎样在一个一般窗口或是dialog上面使用分割窗口.htm

📁 csdn10年中间经典帖子
💻 HTM
📖 第 1 页 / 共 2 页
字号:
          <TD><B>&nbsp;&nbsp;&nbsp;&nbsp;怎样在一个一般窗口或是Dialog上面使用分割窗口.</B>&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;怎样在一个一般窗口或是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>&nbsp;&nbsp;&nbsp; 小弟初次贴文,水平不高,希望不要丢东西.呵呵.</P>
            <P>&nbsp;&nbsp;&nbsp; 
            大家都知道可以在一个CFrameWnd上面使用CSplitterWnd以做出分割窗口的效果(呵呵,顺便,分割窗口可是MFC程序的一大特色.原来(Delphi没有加上这个的支持之前),你只要看到了分割窗口,几乎可以肯定是MFC的.(哈哈,当然,也有人用SDK做一个出来,有这种闲的家伙么?呵呵,好象废话太多了点).</P>
            <P>&nbsp;&nbsp;&nbsp; 
            可是现实中的情况是,有的时候我们要在一个一般的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>&nbsp;// 
            Construction<BR>&nbsp;public:<BR>&nbsp;CxSplitterWnd() 
            {};<BR>&nbsp;virtual ~CxSplitterWnd() {}; </P>
            <P>&nbsp;// Operations<BR>&nbsp;public: <BR>&nbsp;// 
            Overrides<BR>&nbsp;// ClassWizard generated virtual function 
            overrides<BR>&nbsp;<A 
            href="file://{{/">file://{{/</A>AFX_VIRTUAL(CxSplitterWnd)<BR>&nbsp;<A 
            href="file://}}/">file://}}/</A>AFX_VIRTUAL </P>
            <P>&nbsp;// Implementation<BR>&nbsp;public: <BR>&nbsp;// These are 
            the methods to be overridden<BR>&nbsp;virtual void StartTracking(int 
            ht); <BR>&nbsp;virtual CWnd* GetActivePane(int* pRow = NULL, int* 
            pCol = NULL);<BR>&nbsp;virtual void SetActivePane( int row, int col, 
            CWnd* pWnd = NULL ); <BR>&nbsp;virtual BOOL OnCommand(WPARAM wParam, 
            LPARAM lParam);<BR>&nbsp;virtual BOOL OnNotify( WPARAM wParam, 
            LPARAM lParam, LRESULT* pResult );<BR>&nbsp;virtual BOOL OnWndMsg( 
            UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult ); </P>
            <P>&nbsp;// Generated message map 
            functions<BR>&nbsp;protected:<BR>&nbsp;<A 
            href="file://}}AFX_MSG/">file://}}AFX_MSG/</A>(CxSplitterWnd)<BR>&nbsp;// 
            NOTE - the ClassWizard will add and remove member functions 
            here.<BR>&nbsp;<A 
            href="file://}}/">file://}}/</A>AFX_MSG<BR>&nbsp;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>&nbsp;noHit = 0,<BR>&nbsp;vSplitterBox 
            = 1,<BR>&nbsp;hSplitterBox = 2,<BR>&nbsp;bothSplitterBox = 3, // 
            just for keyboard<BR>&nbsp;vSplitterBar1 = 
            101,<BR>&nbsp;vSplitterBar15 = 115,<BR>&nbsp;hSplitterBar1 = 
            201,<BR>&nbsp;hSplitterBar15 = 215,<BR>&nbsp;splitterIntersection1 = 
            301,<BR>&nbsp;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>&nbsp;ASSERT_VALID(this); <BR>&nbsp;CWnd* pView = 
            GetFocus();<BR>&nbsp;// make sure the pane is a child pane of the 
            splitter<BR>&nbsp;if (pView != NULL &amp;&amp; !IsChildPane(pView, 
            pRow, pCol))<BR>&nbsp;pView = NULL; <BR>&nbsp;return pView;<BR>} 
</P>
            <P>void CxSplitterWnd::SetActivePane( int row, int col, CWnd* 
            pWnd)<BR>{<BR>&nbsp;// set the focus to the pane<BR>&nbsp;CWnd* 
            pPane = pWnd == NULL ? GetPane(row, col) : 
            pWnd;<BR>&nbsp;pPane-&gt;SetFocus();<BR>} </P>
            <P>void CxSplitterWnd::StartTracking(int 
            ht)<BR>{<BR>ASSERT_VALID(this);<BR>&nbsp;if (ht == 
            noHit)<BR>&nbsp;&nbsp;return; <BR>&nbsp;// GetHitRect will restrict 
            'm_rectLimit' as appropriate<BR>&nbsp;GetInsideRect(m_rectLimit); 
            <BR>&nbsp;if (ht &gt;= splitterIntersection1 &amp;&amp; ht &lt;= 
            splitterIntersection225)<BR>&nbsp;{<BR>&nbsp;&nbsp;// split two 
            directions (two tracking rectangles)<BR>&nbsp;&nbsp;int row = (ht - 
            splitterIntersection1) / 15;<BR>&nbsp;&nbsp;int col = (ht - 
            splitterIntersection1) % 15; <BR>&nbsp;&nbsp;GetHitRect(row + 
            vSplitterBar1, m_rectTracker);<BR>&nbsp;&nbsp;int yTrackOffset = 
            m_ptTrackOffset.y;<BR>&nbsp;&nbsp;m_bTracking2 = 
            TRUE;<BR>&nbsp;&nbsp;GetHitRect(col + hSplitterBar1, 
            m_rectTracker2);<BR>&nbsp;&nbsp;m_ptTrackOffset.y = 
            yTrackOffset;<BR>&nbsp;}<BR>&nbsp;else if (ht == 
            bothSplitterBox)<BR>&nbsp;{<BR>&nbsp;&nbsp;// hit on splitter boxes 
            (for keyboard)<BR>&nbsp;&nbsp;GetHitRect(vSplitterBox, 
            m_rectTracker);<BR>&nbsp;&nbsp;int yTrackOffset = 
            m_ptTrackOffset.y;<BR>&nbsp;&nbsp;m_bTracking2 = 
            TRUE;<BR>&nbsp;&nbsp;GetHitRect(hSplitterBox, 
            m_rectTracker2);<BR>&nbsp;&nbsp;m_ptTrackOffset.y = yTrackOffset; 
            <BR>&nbsp;&nbsp;// center 
            it<BR>&nbsp;&nbsp;m_rectTracker.OffsetRect(0, 
            m_rectLimit.Height()/2);<BR>&nbsp;&nbsp;m_rectTracker2.OffsetRect(m_rectLimit.Width()/2, 
            0);<BR>&nbsp;}<BR>&nbsp;else<BR>&nbsp;{<BR>&nbsp;&nbsp;// only hit 
            one bar<BR>&nbsp;&nbsp;GetHitRect(ht, m_rectTracker);<BR>&nbsp;} 
</P>
            <P>&nbsp;// steal focus and 
            capture<BR>&nbsp;SetCapture();<BR>&nbsp;SetFocus(); <BR>&nbsp;// 
            make sure no updates are pending<BR>&nbsp;RedrawWindow(NULL, NULL, 
            RDW_ALLCHILDREN | RDW_UPDATENOW); <BR>&nbsp;// set tracking state 
            and appropriate cursor<BR>&nbsp;m_bTracking = 
            TRUE;<BR>&nbsp;OnInvertTracker(m_rectTracker);<BR>&nbsp;if 
            (m_bTracking2)<BR>&nbsp;OnInvertTracker(m_rectTracker2);<BR>&nbsp;m_htTrack 
            = ht;<BR>&nbsp;SetSplitCursor(ht);<BR>} </P>
            <P>/////////////////////////////////////////////////////////////////////////////<BR>// 
            CSplitterWnd command routing <BR>BOOL 
            CxSplitterWnd::OnCommand(WPARAM wParam, LPARAM 
            lParam)<BR>{<BR>&nbsp;if (CWnd::OnCommand(wParam, 
            lParam))<BR>&nbsp;return TRUE; <BR>&nbsp;// route commands to the 
            splitter to the parent frame window<BR>&nbsp;return 
            GetParent()-&gt;SendMessage(WM_COMMAND, wParam, lParam);<BR>} </P>
            <P>BOOL CxSplitterWnd::OnNotify( WPARAM wParam, LPARAM lParam, 
            LRESULT* pResult )<BR>{<BR>&nbsp;if (CWnd::OnNotify(wParam, lParam, 
            pResult))<BR>&nbsp;return TRUE; <BR>&nbsp;// route commands to the 
            splitter to the parent frame window<BR>&nbsp;*pResult = 
            GetParent()-&gt;SendMessage(WM_NOTIFY, wParam, 
            lParam);<BR>&nbsp;return TRUE;<BR>} </P>
            <P>BOOL CxSplitterWnd::OnWndMsg(UINT message, WPARAM wParam, LPARAM 
            lParam, LRESULT* pResult)<BR>{ <BR>&nbsp;// The code line below is 
            necessary if using CxSplitterWnd in a regular dll<BR>&nbsp;// 
            AFX_MANAGE_STATE(AfxGetStaticModuleState()); <BR>&nbsp;return 
            CWnd::OnWndMsg(message, wParam, lParam, pResult);<BR>}<BR></P>
            <P>把这个文件给包含进你的工程,就可以用CxSplitterWnd了.</P>
            <P>&nbsp;</P>
            <P>&nbsp;</P>
            <P>&nbsp;</P>
            <P>&nbsp;</P>
            <P>&nbsp;</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 &copy; 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 + -