• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            VC 界面窗口,靜態(tài)分割后如何鎖定分隔條或限制分隔條的移動(dòng)范圍

                    來(lái)北航做畢業(yè)設(shè)計(jì)已經(jīng)有半個(gè)月了,由于實(shí)驗(yàn)室中,項(xiàng)目組用的是VC,昨天剛好遇到一個(gè)細(xì)節(jié)問(wèn)題:大家都知道,VC中可以動(dòng)態(tài)或者靜態(tài)的分割窗口(關(guān)于這點(diǎn)許多地方說(shuō)的已經(jīng)很清楚了,這里不做討論)但是實(shí)際上,很多時(shí)候我們想要的只是靜態(tài)的分割出窗口,并不想讓別人移動(dòng)改變這個(gè)比例,或者是需要限定某個(gè)分割出的窗口的范圍(比如是小到多少之后就不能再變小了),關(guān)于這個(gè)問(wèn)題許多書(shū)上都沒(méi)有解釋?zhuān)ǎ校樱耗鞘怯X(jué)得太簡(jiǎn)單了,直接忽略么?orz...)本人研究了一下,   關(guān)于鎖定分割大致有兩種方法,而如何限制移動(dòng)范圍也可已在此基礎(chǔ)上加,特此總結(jié)如下:
                    鎖定的話,其中一種方法是直接截獲一個(gè)消息,我們知道,其實(shí) CsplitterWnd 是從CWnd 派生出來(lái)的,所以其實(shí)很容易截獲Window的消息,在這里我們應(yīng)該關(guān)注的其實(shí)僅僅只有一個(gè)消息WM_NCHITTEST ,其作用大致就是當(dāng)你的鼠標(biāo)在這個(gè)劃分出的區(qū)域中移動(dòng)時(shí)為CWnd捕捉你的鼠標(biāo)輸入的,所以,換言之,如果我們截獲了這個(gè)消息,直接返回為HTNOWHERE(參考MSDN),那么當(dāng)你的鼠標(biāo)停留在Splitter上時(shí)就不會(huì)出現(xiàn)任何反應(yīng),從而鎖定的目的就達(dá)到了
                    另一種是重載:OnLButtonDown(UINT nFlags, CPoint point),OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 以及OnMouseMove(UINT nFlags, CPoint point)幾個(gè)函數(shù),前兩個(gè)函數(shù)的重載也可以達(dá)到鎖定的效果,第三個(gè)函數(shù)也就是OnMouseMove()的重載則是為了限定移動(dòng)的范圍(這種情況可能需要的更多一些)下面貼上這兩種方法的代碼:
                    兩種方法有一個(gè)共同點(diǎn)就是需要自己從CSplitterWnd類(lèi)中派生一個(gè)自己的類(lèi)就叫 MySplitterWnd 好了,先采用第一種方法,來(lái)鎖定,MySplitterWnd.h中代碼如下:

            #if !defined(AFX_MYSPLITTERWND_H__A2E77A4F_BB34_4622_8178_ED5FB394208E__INCLUDED_)
            #define AFX_MYSPLITTERWND_H__A2E77A4F_BB34_4622_8178_ED5FB394208E__INCLUDED_

            #if _MSC_VER > 1000
            #pragma once
            #endif // _MSC_VER > 1000
            // MySplitterWnd.h : header file
            //

            /////////////////////////////////////////////////////////////////////////////
            // MySplitterWnd frame with splitter

            #ifndef __AFXEXT_H__
            #include 
            <afxext.h>
            #endif

            class MySplitterWnd : public CSplitterWnd
            {
                DECLARE_DYNCREATE(MySplitterWnd)
            protected:
                    
            // protected constructor used by dynamic creation

            // Attributes
            protected:
                CSplitterWnd    m_wndSplitter;
            public:

                MySplitterWnd();   

            public:

            // Overrides
                
            // ClassWizard generated virtual function overrides
                
            //{{AFX_VIRTUAL(MySplitterWnd)
                protected:
                
            virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
                afx_msg UINT    OnNcHitTest(CPoint point);     
            //新加的

                
            //}}AFX_VIRTUAL

            // Implementation
            public:
                
            virtual ~MySplitterWnd();

                
            // Generated message map functions
                
            //{{AFX_MSG(MySplitterWnd)
                    
            // NOTE - the ClassWizard will add and remove member functions here.
                
            //}}AFX_MSG
                DECLARE_MESSAGE_MAP()
            }
            ;

            /////////////////////////////////////////////////////////////////////////////

            //{{AFX_INSERT_LOCATION}}
            // Microsoft Visual C++ will insert additional declarations immediately before the previous line.

            #endif // !defined(AFX_MYSPLITTERWND_H__A2E77A4F_BB34_4622_8178_ED5FB394208E__INCLUDED_)

            其中關(guān)鍵的語(yǔ)句就是 加一句  afx_msg UINT    OnNcHitTest(CPoint point)的定義,然后再在MySplitterWnd.cpp具體實(shí)現(xiàn)這個(gè)函數(shù),如下

            // MySplitterWnd.cpp : implementation file
            //

            #include 
            "stdafx.h"
            #include 
            "GL.h"
            #include 
            "MySplitterWnd.h"

            #ifdef _DEBUG
            #define new DEBUG_NEW
            #undef THIS_FILE
            static char THIS_FILE[] = __FILE__;
            #endif

            /////////////////////////////////////////////////////////////////////////////
            // MySplitterWnd

            IMPLEMENT_DYNCREATE(MySplitterWnd, CSplitterWnd)

            MySplitterWnd::MySplitterWnd()
            {
            }


            MySplitterWnd::
            ~MySplitterWnd()
            {
            }


            BOOL MySplitterWnd::OnCreateClient(LPCREATESTRUCT 
            /*lpcs*/, CCreateContext* pContext)
            {
                
            return m_wndSplitter.Create(this,
                    
            22,       // TODO: adjust the number of rows, columns
                    CSize(1010),  // TODO: adjust the minimum pane size
                    pContext);
            }


            afx_msg UINT MySplitterWnd::OnNcHitTest(CPoint 
            /*point*/)
            {
                
            return HTNOWHERE;
            }



            /*BEGIN_MESSAGE_MAP(MySplitterWnd, CSplitterWnd)
                //{{AFX_MSG_MAP(MySplitterWnd)
                    // NOTE - the ClassWizard will add and remove mapping macros here.
                //}}AFX_MSG_MAP
            END_MESSAGE_MAP()
            */



            BEGIN_MESSAGE_MAP(MySplitterWnd, CSplitterWnd)
            ON_WM_NCHITTEST()
            END_MESSAGE_MAP()


            /////////////////////////////////////////////////////////////////////////////
            // MySplitterWnd message handlers

            可以看到,具體實(shí)現(xiàn)就一句話,return HTNOWHERE。現(xiàn)在就OK了,我的表述已經(jīng)盡可能清楚了,如果實(shí)在不理解也沒(méi)關(guān)系,你們可以直接將上面的.h和.cpp直接復(fù)制過(guò)去,直接加入到你的工程中,到時(shí)候用的時(shí)候直接 定義用 MySplitterWnd這個(gè)類(lèi)定義 自己的變量,如  MySplitterWnd  XXX(自己隨便取名)

            下面介紹另一種方法,也是同上面一樣需要自己建立一個(gè)類(lèi),還是叫MySplitterWnd好了,基類(lèi)還是CSplitterWnd
            然后 在MySplitterWnd.h中添加如下代碼(位置 和添加OnNcHitTest(...)函數(shù)一樣)
            afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
            afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
            afx_msg void OnMouseMove(UINT nFlags, CPoint point);
            在MySplitterWnd.cpp中添加三個(gè)函數(shù)的具體實(shí)現(xiàn)代碼如下:

            void MySplitterWnd::OnLButtonDown(UINT nFlags, CPoint point)
            {    
                // 直接返回,不處理
             return;
            }

            BOOL MySplitterWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
            {  
                // 當(dāng)光標(biāo)進(jìn)入分割窗口時(shí),不允許改變樣子,不處理
             return FALSE;
            }

            void MySplitterWnd::OnMouseMove(UINT nFlags, CPoint point)
            {       
             //將CSplitter類(lèi)的處理改為由CWnd處理
             //CSplitterWnd::OnMouseMove(nFlags, point);

             if(point.x<250||point.x>500) CWnd::OnMouseMove(nFlags, point);
             else  CSplitterWnd::OnMouseMove(nFlags, point);

             }

            好了,其實(shí)到了這里還沒(méi)有完,剛說(shuō)到鎖定的問(wèn)題,大家可以發(fā)現(xiàn)如果三個(gè)函數(shù)這樣子寫(xiě)你的分隔條直接不能動(dòng)了,和剛才的截取消息的鎖定效果一摸一樣,但是關(guān)于第三個(gè)函數(shù)OnMouseMove()的實(shí)際作用其實(shí)是限定范圍,if(point.x<250||point.x>500) CWnd::OnMouseMove(nFlags, point);
             else  CSplitterWnd::OnMouseMove(nFlags, point); 這兩句的意思是說(shuō)將移動(dòng)范圍鎖定在250和500之間(這個(gè)數(shù)值大家可以隨便設(shè)置),為了要使得這個(gè)函數(shù)生效,大家可以把前面兩個(gè)也就是OnLButtonDown()和OnSetCursor()屏蔽掉,只留下第三個(gè)OnMouseMove()就可以達(dá)到限制范圍的效果了,當(dāng)然只屏蔽掉OnLButtonDown()函數(shù)也是可以的,因?yàn)镺nSetCursor()函數(shù)只是改變光標(biāo)樣子用的,(鎖定的另一個(gè)方法其實(shí)就是只用前面兩個(gè),既屏蔽掉OnMouseMove(),這個(gè)函數(shù),大家可以自己試試,分別屏蔽看會(huì)出現(xiàn)什么效果)

            MySplitterWnd.h和MySplitterWnd.cpp分別如下:

            MySplitterWnd.h:

            #if !defined(AFX_MYSPLITTERWND_H__7AA280DC_82F5_4FF5_95A6_036C8A20B50D__INCLUDED_)
            #define AFX_MYSPLITTERWND_H__7AA280DC_82F5_4FF5_95A6_036C8A20B50D__INCLUDED_

            #if _MSC_VER > 1000
            #pragma once
            #endif // _MSC_VER > 1000
            // MySplitterWnd.h : header file
            //

            /////////////////////////////////////////////////////////////////////////////
            // MySplitterWnd frame with splitter

            #ifndef __AFXEXT_H__
            #include 
            <afxext.h>
            #endif

            class MySplitterWnd : public CSplitterWnd
            {

              
            public:

                MySplitterWnd(); 
            // Operations
            public:

            // Overrides
                
            // ClassWizard generated virtual function overrides
                
            //{{AFX_VIRTUAL(MySplitterWnd)
                


                
            //}}AFX_VIRTUAL

            // Implementation
            public:
                
            virtual ~MySplitterWnd();
                

                    
                DECLARE_DYNCREATE(MySplitterWnd)

                
                afx_msg 
            void OnLButtonDown(UINT nFlags, CPoint point);     //新加的
                afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); //新加的
                afx_msg void OnMouseMove(UINT nFlags, CPoint point); //新加的
                
                DECLARE_MESSAGE_MAP()     
            //后加的


            }
            ;

            /////////////////////////////////////////////////////////////////////////////

            //{{AFX_INSERT_LOCATION}}
            // Microsoft Visual C++ will insert additional declarations immediately before the previous line.

            #endif // !defined(AFX_MYSPLITTERWND_H__7AA280DC_82F5_4FF5_95A6_036C8A20B50D__INCLUDED_)


            MySplitterWnd.cpp:

            // MySplitterWnd.cpp : implementation file
            //

            #include 
            "stdafx.h"
            #include 
            "GL.h"
            #include 
            "MySplitterWnd.h"

            #ifdef _DEBUG
            #define new DEBUG_NEW
            #undef THIS_FILE
            static char THIS_FILE[] = __FILE__;
            #endif

            /////////////////////////////////////////////////////////////////////////////
            // MySplitterWnd


            IMPLEMENT_DYNCREATE(MySplitterWnd, CSplitterWnd)


            BEGIN_MESSAGE_MAP(MySplitterWnd, CSplitterWnd)
            //ON_WM_LBUTTONDOWN()
            //ON_WM_SETCURSOR()
            ON_WM_MOUSEMOVE()

            END_MESSAGE_MAP()




            MySplitterWnd::MySplitterWnd()
            {
            }


            MySplitterWnd::
            ~MySplitterWnd()
            {
            }


            /*void MySplitterWnd::OnLButtonDown(UINT nFlags, CPoint point)
            {     
                // 直接返回,不處理
                return;
            }

            BOOL MySplitterWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
            {   
                // 當(dāng)光標(biāo)進(jìn)入分割窗口時(shí),不允許改變樣子,不處理
                return FALSE;
            }
            */


            void MySplitterWnd::OnMouseMove(UINT nFlags, CPoint point)
            {       
                
                
            //將CSplitter類(lèi)的處理改為由CWnd處理
                
            //CSplitterWnd::OnMouseMove(nFlags, point); 

                
            if(point.x<250||point.x>500) CWnd::OnMouseMove(nFlags, point); 
                
            else  CSplitterWnd::OnMouseMove(nFlags, point); 

            }





            /*
            BEGIN_MESSAGE_MAP(MySplitterWnd, CSplitterWnd)
                //{{AFX_MSG_MAP(MySplitterWnd)
                    // NOTE - the ClassWizard will add and remove mapping macros here.
                //}}AFX_MSG_MAP
            END_MESSAGE_MAP()
            */


            /////////////////////////////////////////////////////////////////////////////
            // MySplitterWnd message handlers

            說(shuō)的可能有些不清楚,不清楚的也沒(méi)關(guān)系,可以直接將上面的MySplitterWnd.h和MySplitterWnd.cpp導(dǎo)入到自己的工程中,直接用就行了,將你要鎖定或者限制移動(dòng)范圍的分割區(qū)域用MySplitterWnd定義,不做限制,鎖定的區(qū)域用CSplitterWnd類(lèi)定義,這樣子就可以做到有選擇的限制鎖定某幾個(gè)分割區(qū)域的效果.

            posted on 2010-03-29 15:09 蝸牛也Coding 閱讀(4335) 評(píng)論(5)  編輯 收藏 引用

            評(píng)論

            # re: VC 界面窗口,靜態(tài)分割后如何鎖定分隔條或限制分隔條的移動(dòng)范圍 2010-03-29 17:03 Jakcie

            和我想的辦法一樣。呵呵。
            不知道有沒(méi)有別的辦法。  回復(fù)  更多評(píng)論   

            # re: VC 界面窗口,靜態(tài)分割后如何鎖定分隔條或限制分隔條的移動(dòng)范圍 2010-03-29 18:46 MasterLuo

            都是畢業(yè)生,感覺(jué)與你差距很大啊。我連VC一點(diǎn)都不會(huì)。  回復(fù)  更多評(píng)論   

            # re: VC 界面窗口,靜態(tài)分割后如何鎖定分隔條或限制分隔條的移動(dòng)范圍 2010-03-29 19:43 蝸牛也Coding

            @MasterLuo
            呵呵,其實(shí)差不多了,我VC也是邊學(xué)邊用的,多多指教....  回復(fù)  更多評(píng)論   

            # re: VC 界面窗口,靜態(tài)分割后如何鎖定分隔條或限制分隔條的移動(dòng)范圍 2011-04-29 09:35 zhou

            非常感謝,網(wǎng)上雖然很多方法,但是都有問(wèn)題,這個(gè)好,一下子就解決了問(wèn)題。  回復(fù)  更多評(píng)論   

            # re: VC 界面窗口,靜態(tài)分割后如何鎖定分隔條或限制分隔條的移動(dòng)范圍 2013-03-18 16:36 zheng

            很不錯(cuò),版主慷慨  回復(fù)  更多評(píng)論   


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(8)

            隨筆檔案(78)

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            国产精品久久久香蕉| 老司机午夜网站国内精品久久久久久久久| 亚洲国产成人精品91久久久| 香港aa三级久久三级老师2021国产三级精品三级在 | 国产精品久久久久久久久免费 | 国产激情久久久久影院老熟女| 久久r热这里有精品视频| 久久精品嫩草影院| 91精品国产91久久久久久青草| 91亚洲国产成人久久精品| 欧美久久久久久午夜精品| 人妻丰满?V无码久久不卡| 少妇人妻综合久久中文字幕| 久久精品无码专区免费青青| 国产精品99久久久久久人| 麻豆国内精品久久久久久| 久久久久久精品免费看SSS| 久久无码精品一区二区三区| 久久久久久国产精品美女| 奇米影视7777久久精品| 99久久国产亚洲高清观看2024 | 很黄很污的网站久久mimi色| 伊人色综合久久天天网| MM131亚洲国产美女久久| 久久亚洲国产成人精品无码区| 无码精品久久久久久人妻中字| 香蕉久久夜色精品国产小说| 国产成年无码久久久免费| 2021国产成人精品久久| 一本一本久久a久久综合精品蜜桃 一本一道久久综合狠狠老 | 性做久久久久久免费观看| 日产精品99久久久久久| 伊人久久大香线蕉综合Av | 久久精品免费一区二区三区| 狠狠色丁香久久婷婷综合图片| 久久精品国产亚洲综合色| 久久精品一本到99热免费| 精品国产乱码久久久久久浪潮| 久久久久久毛片免费播放| 欧美久久久久久精选9999| 狠狠干狠狠久久|