• <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>

            love in C++, live on MFC

            to get ready...

            C++博客 首頁 新隨筆 聯系 聚合 管理
              47 Posts :: 0 Stories :: 97 Comments :: 0 Trackbacks
            在重載CSplitterWnd中,重載了OnPaint(),
            默認的代碼如下:
            void?CHideSplitterWnd::OnPaint()?
            {
            ????CPaintDC?dc(
            this);?//
            ?device?context?for?painting
            ????
            //
            ?TODO:?Add?your?message?handler?code?here
            ????
            //?Do?not?call?CSplitterWnd::OnPaint()?for?painting?messages

            }
            wizard添加的代碼居然有這樣一行://?Do?not?call?CSplitterWnd::OnPaint()?for?painting?messages,后面有個猜測。
            然后我繼續寫我的函數:
            void?CHideSplitterWnd::OnPaint()?
            {
            ????CPaintDC?dc(
            this);?//
            ?device?context?for?painting
            ????
            ????
            //?調用基類,先

            ????CSplitterWnd::OnPaint();
            ????
            ?????//
            利用dc畫一些別的東西,但是實際上,它們永遠不會被畫出來
            ???//除非不調用基類的OnPaint()

            ????m_rectButton.DrawButton(&dc);
            }
            結果我添加的東西怎么也不會被畫出來,為什么會這樣?

            看了CSplitterWnd::OnPaint()的代碼,發現它也用了一個CPaintDC,而且也是個臨時變量
            void?CSplitterWnd::OnPaint()
            {
            ????ASSERT_VALID(
            this
            );
            ????CPaintDC?dc(
            this);
            而關鍵的地方就在CPaintDC的ctor和dtor中了:在CPaintDC的ctor中調用了
            ::BeginPaint(m_hWnd?=?pWnd->m_hWnd,?&m_ps)
            而在CPaintDC的dtor中調用了
            ::EndPaint(m_hWnd,?&m_ps);
            而:BeginPaint是開始根據當前的cliprect來畫,EndPaint則會清空當前的cliprect。

            所以,前面調用基類的OnPaint的過程結束后,當前的cliprect為NULL,所以,第二個CPaintDC在視圖畫點什么時,cliprect已經為NULL,當然什么也畫不上去了 :)

            如果我一定想再用CPaintDC畫點什么,怎么辦?再次調用InvalidateRect,使得cliprect不為空。
            void?CHideSplitterWnd::OnPaint()?
            {
            ??? //注意臨時變量聲明的順序,因為BeginPaint/EndPaint是不支持嵌套的
            ????//CPaintDC?dc(
            this);?//
            ?device?context?for?painting
            ????
            ????
            //?TODO:?Add?your?message?handler?code?here

            ????CSplitterWnd::OnPaint();
            ????
            ??? //第二此調用
            ????InvalidateRect(
            &
            m_rectButton,FALSE);
            ????CPaintDC?dc(
            this);?//?在這里,device?context?for?painting

            ????m_rectButton.DrawButton(&dc);
            ????
            ????
            //?Do?not?call?CSplitterWnd::OnPaint()?for?painting?messages

            }
            所以,我猜測,所有用了CPaintDC的地方,MFC都會加一句:不要調用基類的函數啦~

            呵呵,不知道我講清楚沒有
            posted on 2006-05-22 23:39 flyingxu 閱讀(3451) 評論(3)  編輯 收藏 引用 所屬分類: VC/MFCBug of Today

            Feedback

            # re: 在OnPaint()使用兩次CPaintDC,關于::BeginPaint()/::EndPaint() 2006-05-23 08:36 cmdn
            請教一下,你那個代碼不是圖片,是怎么貼上去的?  回復  更多評論
              

            # re: 在OnPaint()使用兩次CPaintDC,關于::BeginPaint()/::EndPaint() 2006-06-08 23:17 flyingxu
            @cmdn
            是cppblog編輯時選的“代碼段”格式。  回復  更多評論
              

            # re: 在OnPaint()使用兩次CPaintDC,關于::BeginPaint()/::EndPaint() 2007-04-27 09:55 困惑于OnPaint的人
            void CMyView::OnPaint()
            {

            CPaintDC dc(this); // device context for painting

            // TODO: Add your message handler code here
            CView::OnPaint();

            dc.TextOut(0,0,"hello"); //這個能在屏幕顯示出來,為什么?
            // Do not call CView::OnPaint() for painting messages
            }

            我上面的這段代碼能正常運行,且能在屏幕上正確顯示"hello"字符串  回復  更多評論
              

            亚洲av成人无码久久精品| 91秦先生久久久久久久| 色综合色天天久久婷婷基地| 婷婷久久久亚洲欧洲日产国码AV | 伊人热热久久原色播放www| 久久精品国产亚洲综合色| 久久精品国产亚洲一区二区| 久久这里只有精品久久| 国产亚洲精午夜久久久久久| 99久久综合国产精品二区| 国产成人综合久久精品尤物| 精品人妻伦九区久久AAA片69| 久久精品国产精品青草| 久久青青国产| 久久国产精品无| 久久久久av无码免费网| 日产精品99久久久久久| 久久久无码人妻精品无码| 99精品国产在热久久| 国产亚州精品女人久久久久久| 国产精品gz久久久| 久久精品一本到99热免费| 久久人人爽人人爽人人AV东京热 | 久久综合久久综合九色| 欧美精品丝袜久久久中文字幕| 亚洲欧美日韩精品久久亚洲区 | 国产精品亚洲综合专区片高清久久久| 嫩草影院久久99| 亚洲国产综合久久天堂| 久久久久亚洲AV无码永不| 国产农村妇女毛片精品久久| 思思久久99热只有频精品66| 久久精品国产亚洲AV高清热| 超级碰久久免费公开视频| 久久久久久精品免费看SSS| 免费观看久久精彩视频| 欧美日韩精品久久免费| 久久青草国产精品一区| 日本强好片久久久久久AAA| 99热精品久久只有精品| 少妇人妻88久久中文字幕|