亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? chap8_3.htm

?? VC++編程實例。非常詳細
?? HTM
?? 第 1 頁 / 共 3 頁
字號:
          <p>void CDrawView::OnDraw(CDC* pDC)</p>
          <p>{</p>
          <p>CDrawDoc* pDoc = GetDocument();</p>
          <p>ASSERT_VALID(pDoc);</p>
          
          <p><b> </b></p>
          <b> 
          <p>// Get the invalidated rectangle of the view, or in the case</p>
          <p>// of printing, the clipping region of the printer dc.</p>
          <p>CRect rectClip;</p>
          <p>CRect rectStroke;</p>
          <p>pDC-&gt;GetClipBox(&amp;rectClip);</p>
          <p>pDC-&gt;LPtoDP(&amp;rectClip);</p>
          <p>rectClip.InflateRect(1, 1); // avoid rounding to nothing</p>
          <p>// Note: CScrollView::OnPaint() will have already adjusted the</p>
          <p>// viewport origin before calling OnDraw(), to reflect the</p>
          <p>// currently scrolled position.</p>
          <p>// The view delegates the drawing of individual strokes to</p>
          <p>// CStroke::DrawStroke().</p>
          <p>CTypedPtrList&lt;CObList,CStroke*&gt;&amp; strokeList = pDoc-&gt;m_strokeList;</p>
          <p>POSITION pos = strokeList.GetHeadPosition();</p>
          <p>while (pos != NULL)</p>
          <p>{</p>
          <p>CStroke* pStroke = strokeList.GetNext(pos);</p>
          <p>rectStroke = pStroke-&gt;GetBoundingRect();</p>
          <p>pDC-&gt;LPtoDP(&amp;rectStroke);</p>
          <p>rectStroke.InflateRect(1, 1); // avoid rounding to nothing</p>
          <p>if (!rectStroke.IntersectRect(&amp;rectStroke, &amp;rectClip))</p>
          <p>continue;</p>
          <p>pStroke-&gt;DrawStroke(pDC);</p>
          <p>}</p>
          </b> 
          <p>// TODO: add draw code for native data here</p>
          <p>}</p>
          
          <p>OnDraw首先調用GetClipBox取得當前被剪裁區域(無效矩形區域),它把矩形復制導GetClipBox的參數rectClip中。然后將rectClip的坐標由邏輯坐標轉換為設備坐標。為了防止該矩形太小而無法包圍其他內容,上下各放大一個單位。然后OnDraw遍歷筆劃鏈表中的所有筆劃,獲取它們的最小矩形,用IntersectRect看它是否與無效矩形相交。如果相交,說明筆劃的部分或全部落在無效矩形中,此時調用筆劃的DrawStroke方法畫出該筆劃。</p>
          <p> <b>圖8-6</b> 
            根據包圍筆劃 的矩形是否與無效</p>
          <p> 矩形相交 
            ,判斷筆劃是否落入無效矩形中 </p>
          <p> 為了獲得筆劃的最小包圍矩形,需要在結束筆劃時計算出包圍筆劃的最小矩形。因此為筆劃提供兩個方法:一個是FinishStroke(),用于在筆劃結束時計算最小矩形,見清單8.7。</p>
          
          <p> <b>清單</b><b>8.7 
            CStroke::FinishStroke()成員函數</b></p>
           
          <p>void CStroke::FinishStroke()</p>
          <p>{</p>
          <p>// Calculate the bounding rectangle. It's needed for smart</p>
          <p>// repainting.</p>
          <p>if (m_pointArray.GetSize()==0)</p>
          <p>{</p>
          <p>m_rectBounding.SetRectEmpty();</p>
          <p>return;</p>
          <p>}</p>
          <p>CPoint pt = m_pointArray[0];</p>
          <p>m_rectBounding = CRect(pt.x, pt.y, pt.x, pt.y);</p>
          <p>for (int i=1; i &lt; m_pointArray.GetSize(); i++)</p>
          <p>{</p>
          <p>// If the point lies outside of the accumulated bounding</p>
          <p>// rectangle, then inflate the bounding rect to include it.</p>
          <p>pt = m_pointArray[i];</p>
          <p>m_rectBounding.left = min(m_rectBounding.left, pt.x);</p>
          <p>m_rectBounding.right = max(m_rectBounding.right, pt.x);</p>
          <p>m_rectBounding.top = max(m_rectBounding.top, pt.y);</p>
          <p>m_rectBounding.bottom = min(m_rectBounding.bottom, pt.y);</p>
          <p>}</p>
          <p>// Add the pen width to the bounding rectangle. This is necessary</p>
          <p>// to account for the width of the stroke when invalidating</p>
          <p>// the screen.</p>
          <p>m_rectBounding.InflateRect(CSize(m_nPenWidth, -(int)m_nPenWidth));</p>
          <p>return;</p>
          <p>}</p>
          
          <p>另一個是DrawStroke(),用于繪制筆劃:</p>
           
          <p>BOOL CStroke::DrawStroke(CDC* pDC)</p>
          <p>{</p>
          <p>CPen penStroke;</p>
          <p>if (!penStroke.CreatePen(PS_SOLID, m_nPenWidth, RGB(0,0,0)))</p>
          <p>return FALSE;</p>
          <p>CPen* pOldPen = pDC-&gt;SelectObject(&amp;penStroke);</p>
          <p>pDC-&gt;MoveTo(m_pointArray[0]);</p>
          <p>for (int i=1; i &lt; m_pointArray.GetSize(); i++)</p>
          <p>{</p>
          <p>pDC-&gt;LineTo(m_pointArray[i]);</p>
          <p>}</p>
          <p>pDC-&gt;SelectObject(pOldPen);</p>
          <p>return TRUE;</p>
          <p>}</p>
          
          <p>鼠標繪圖</p>
          <p align="JUSTIFY"> 鼠標繪圖基本過程是:用戶按下鼠標左鍵時開始繪圖,在鼠標左鍵按下且移動過程中不斷畫線跟蹤鼠標位置,當松開鼠標左鍵結束繪圖。因此,需要處理三個消息:WM_LBUTTONDOWN、WM_MOUSEMOVE、WM_LBUTTONUP。用ClassWizard為上述三個消息生成消息處理函數,并在其中手工加入代碼,修改后的成員函數如下:</p>
          <p align="JUSTIFY"> <b> </b></p>
          <b>
          <p align="JUSTIFY"> 清單8.8 
            鼠標消息處理函數OnLButtonDown()</p>
          </b> 
          <p>void CDrawView::OnLButtonDown(UINT nFlags, CPoint point) </p>
          <p>{</p>
          <p>// TODO: Add your message handler code here and/or call default</p>
          <p>// Pressing the mouse button in the view window starts a new stroke</p>
          <p>// CScrollView changes the viewport origin and mapping mode.</p>
          <p>// It's necessary to convert the point from device coordinates</p>
          <p>// to logical coordinates, such as are stored in the document.</p>
          <p>CClientDC dc(this);</p>
          <p>OnPrepareDC(&amp;dc);</p>
          <p>dc.DPtoLP(&amp;point);</p>
          <p>m_pStrokeCur = GetDocument()-&gt;NewStroke();</p>
          <p>// Add first point to the new stroke</p>
          <p>m_pStrokeCur-&gt;m_pointArray.Add(point);</p>
          <p>SetCapture(); // Capture the mouse until button up.</p>
          <p>m_ptPrev = point; // Serves as the MoveTo() anchor point for the</p>
          <p>// LineTo() the next point, as the user drags the</p>
          <p>// mouse.</p>
          <p>return;</p>
          <p>}</p>
          
          <p> </p>
          <p> 在鼠標左鍵按下,首先獲得鼠標按下的位置坐標。由于它是設備坐標,因此先用DPToLP將它轉換為邏輯坐標。在此之前,要用OnPrepareDC()對視圖坐標原點進行調整。然后用CDrawDoc的NewStroke()成員函數創建一個筆劃對象,并將筆劃對象加入到筆劃鏈表中。然后,將當前點坐標加入道筆劃對象內部的點數組中。以后,當鼠標移動時,OnMouseMove就不斷修改該筆劃對象的內部數據成員(加入新的點到筆劃對象的數組中)。另外,為了用LineTo畫出線條,需要將當前鼠標位置保存到m_ptPrev中,以便出現一個新的點時,畫一條從m_ptPrev到新的點的直線。</p>
          <p> 但是,由于用戶的鼠標可以在屏幕上任意移動。當鼠標移出窗口外時,窗口無法收到鼠標消息。此時,如果松開了鼠標左鍵,應用程序由于無法接受到該條消息而不會終止當前筆劃,這樣就造成了錯誤。如何避免這種情況發生呢?解決的辦法是要讓窗口在鼠標移出窗口外時仍然能接受到鼠標消息。幸好,Windows提供了一個API函數SetCapture()解決了這一問題。</p>
          <p> CWnd::SetCapture()用于捕獲鼠標:無論鼠標光標位置在何處,都會將鼠標消息送給調用它的那一個窗口。在用完后,需要用ReleaseCapture()釋放窗口對鼠標的控制,否則其他窗口將無法接收到鼠標消息。這一工作當然最好在鼠標左鍵松開OnLButtonUp()時來做。</p>
          
          <p> <b>清單</b><b>8.9 
            OnLButtonUp消息處理函數</b></p>
           
          <p>void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) </p>
          <p>{</p>
          <p>// TODO: Add your message handler code here and/or call default</p>
          
          <p> </p>
           
          <p>// Mouse button up is interesting in the draw application</p>
          <p>// only if the user is currently drawing a new stroke by dragging</p>
          <p>// the captured mouse.</p>
          <p>if (GetCapture() != this)</p>
          <p>return; // If this window (view) didn't capture the mouse,</p>
          <p>// then the user isn't drawing in this window.</p>
          <p>CDrawDoc* pDoc = GetDocument();</p>
          <p>CClientDC dc(this);</p>
          <p>// CScrollView changes the viewport origin and mapping mode.</p>
          <p>// It's necessary to convert the point from device coordinates</p>
          <p>// to logical coordinates, such as are stored in the document.</p>
          <p>OnPrepareDC(&amp;dc); // set up mapping mode and viewport origin</p>
          <p>dc.DPtoLP(&amp;point);</p>
          <p>CPen* pOldPen = dc.SelectObject(pDoc-&gt;GetCurrentPen());</p>
          <p>dc.MoveTo(m_ptPrev);</p>
          <p>dc.LineTo(point);</p>
          <p>dc.SelectObject(pOldPen);</p>
          <p>m_pStrokeCur-&gt;m_pointArray.Add(point);</p>
          <p>// Tell the stroke item that we're done adding points to it.</p>
          <p>// This is so it can finish computing its bounding rectangle.</p>
          <p>m_pStrokeCur-&gt;FinishStroke();</p>
          <p>// Tell the other views that this stroke has been added</p>
          <p>// so that they can invalidate this stroke's area in their</p>
          <p>// client area.</p>
          <p>pDoc-&gt;UpdateAllViews(this, 0L, m_pStrokeCur);</p>
          <p>ReleaseCapture(); // Release the mouse capture established at</p>
          <p>// the beginning of the mouse drag.</p>
          <p>return;</p>
          <p>}</p>
          
          <p> </p>
          <p> OnLButtonUp首先檢查鼠標是否被當前窗口所捕獲,如果不是則返回。然后畫出筆劃最后兩點之間的極短的直線段。接著,調用CStroke::FinishStroke(),請求CStroke對象計算它的最小矩形。然后調用pDoc-&gt;UpdateAllViews(this, 
            0L, m_pStrokeCur)通知其他視圖更新顯示。</p>
          <p> 當一個視圖修改了文檔內容并更新顯示時,一般的其它的對應于同一文檔的視圖也需要相應更新,這通過調用文檔的成員函數UpdateAllViews完成。</p>
           
          <blockquote> 
            <blockquote> 
              <p>void UpdateAllViews( CView* pSender, LPARAM lHint = 0L, CObject* 
                pHint = </p>
              <p>NULL );</p>
            </blockquote>
          </blockquote>
          
          <p> UpdateAllViews帶三個參數:pSender指向修改文檔的視圖。由于該視圖已經作了更新,所以不再需要更新。比如,在上面的例子中,OnLButtonUp已經繪制了視圖,因此不需要再次更新。如果為NULL,則文檔對應的所有視圖都被更新。</p>
          <p> lHint和pHint包含了更新視圖時所需的附加信息。在本例中,其他視圖只需要重畫當前繪制中的筆劃,因此OnLButtonUp把當前筆劃指針傳給UpdateAllViews函數。該函數調用文檔所對應的除pSender外的所有視圖的OnUpdate函數,并將lHint和pHint傳給OnUpdate函數通知更新附加信息。</p>
          <p> OnLButtonUp最后釋放對鼠標的控制,這樣別的應用程序窗口就可以獲得鼠標消息了。</p>
          <p> 結合上面講到的知識,讀者不難自行理解下面的OnMouseMove函數。</p>
           
          <p>void CDrawView::OnMouseMove(UINT nFlags, CPoint point) </p>
          <p>{</p>
          <p>// TODO: Add your message handler code here and/or call default</p>
          <p>// Mouse movement is interesting in the Scribble application</p>
          <p>// only if the user is currently drawing a new stroke by dragging</p>
          <p>// the captured mouse.</p>
          <p>if (GetCapture() != this)</p>
          <p>return; // If this window (view) didn't capture the mouse,</p>
          <p>// then the user isn't drawing in this window.</p>
          <p>CClientDC dc(this);</p>
          <p>// CScrollView changes the viewport origin and mapping mode.</p>
          <p>// It's necessary to convert the point from device coordinates</p>
          <p>// to logical coordinates, such as are stored in the document.</p>
          <p>OnPrepareDC(&amp;dc);</p>
          <p>dc.DPtoLP(&amp;point);</p>
          <p>m_pStrokeCur-&gt;m_pointArray.Add(point);</p>
          <p>// Draw a line from the previous detected point in the mouse</p>
          <p>// drag to the current point.</p>
          <p>CPen* pOldPen = dc.SelectObject(GetDocument()-&gt;GetCurrentPen());</p>
          <p>dc.MoveTo(m_ptPrev);</p>
          <p>dc.LineTo(point);</p>
          <p>dc.SelectObject(pOldPen);</p>
          <p>m_ptPrev = point;</p>
          <p>return;</p>
          <p>}</p>
          
          <p>至此,繪圖程序的文檔、視圖全部設計完了,現在編譯運行程序。程序啟動后,在空白窗口中徒手繪圖,如圖8-7所示。</p>
          <p align="center"> <img src="T8_7.gif" alt="T8_7.tif (267124 bytes)" width="470" height="335"></p>
          <p align="center">圖8-7 
            多文檔繪圖程序窗口</p>
          <div align="center"> 
            <table border="0" cellpadding="0" cellspacing="0" width="615">
              <tr> 
                <td><a href="chap8_2.htm">上一頁</a></td>
                <td> 
                  <p align="right"><a href="chap8_4.htm">下一頁</a> 
                </td>
              </tr>
            </table>
            <p><a href="http://www.cpcw.com">電腦報首頁</a> <a href="../../index.htm">網絡學院首頁</a></p>
          </div>
          <hr noshade color="#3973DE" size="1">
          
          <p align="center">本教程由<a href="http://vcdynasty.yeah.net">Visual C++王朝(Where 
            programmers come together)</a>協助制作<br>
            未經許可,請勿以任何形式復制
        </td>
      </tr>
    </table>
    <p>&nbsp;</p>
  </center>
</div>

</body>
</html>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99国产精品久久| 中文字幕在线视频一区| 在线看日韩精品电影| 欧美视频完全免费看| 91久久精品午夜一区二区| 欧美视频日韩视频| 日韩三级伦理片妻子的秘密按摩| 欧美最猛性xxxxx直播| 欧美理论在线播放| 国产欧美日韩中文久久| 尤物av一区二区| 日韩中文字幕91| 国内精品久久久久影院色| 国产一区二区伦理片| av电影在线观看不卡| 欧美日韩亚洲高清一区二区| 日韩一区二区三区高清免费看看 | 国产精品人妖ts系列视频| 中文字幕不卡在线播放| 国产日韩精品一区二区三区| 日本91福利区| 亚洲精品一区二区三区蜜桃下载| 狠狠色伊人亚洲综合成人| 国产精品美女久久福利网站| 成人福利视频在线| 日韩精品一区二区三区四区视频| 自拍偷拍国产精品| 成人国产电影网| 国产欧美1区2区3区| 免费精品视频在线| 欧美一区国产二区| 日本三级韩国三级欧美三级| 91亚洲精品久久久蜜桃| 日韩理论电影院| 国产成人精品一区二| 欧美一区二区三区免费大片| 亚洲午夜在线观看视频在线| 欧美性大战久久久久久久蜜臀| 久久久www成人免费毛片麻豆| 精品一区二区三区日韩| 欧美日韩一区国产| 亚洲超碰精品一区二区| 777久久久精品| 国产精品一区三区| 欧美tickling挠脚心丨vk| 麻豆成人免费电影| 久久女同精品一区二区| av电影在线观看一区| 亚洲成人在线网站| 欧美喷潮久久久xxxxx| 美女免费视频一区| 国产精品婷婷午夜在线观看| 色综合欧美在线| 亚洲午夜私人影院| 欧美一卡二卡三卡| 国产91对白在线观看九色| 国产精品二三区| 日韩亚洲欧美综合| 大胆亚洲人体视频| 日日夜夜精品视频天天综合网| 日韩免费看网站| av成人免费在线| 老司机精品视频线观看86| 中文字幕一区二区三区不卡| 欧美日韩色综合| 国产精品88av| 午夜精品免费在线观看| 国产精品丝袜久久久久久app| 欧美日韩午夜影院| 99久久久精品| 久久99国产精品麻豆| 老汉av免费一区二区三区| 日韩成人午夜电影| 久久精品国产久精国产爱| 免费在线视频一区| 日韩精品乱码免费| 韩国精品免费视频| 色综合天天综合网国产成人综合天 | 看片网站欧美日韩| 中文字幕第一区二区| 欧美在线三级电影| 欧洲在线/亚洲| 欧美日韩中文国产| 欧美日韩一卡二卡| 9191国产精品| 久久综合99re88久久爱| 久久综合色之久久综合| 日本一区二区在线不卡| 成人欧美一区二区三区黑人麻豆| 国产精品久久一卡二卡| 亚洲日本va午夜在线影院| 亚洲午夜久久久久久久久电影网| 日本aⅴ亚洲精品中文乱码| 国产精品一区二区在线看| 91亚洲精品久久久蜜桃网站| 91精品久久久久久蜜臀| 国产午夜精品理论片a级大结局| 亚洲欧美日韩在线| 韩国av一区二区三区| 一本一道波多野结衣一区二区| 欧美日韩中文另类| 中文字幕欧美日本乱码一线二线| 一区二区三区在线视频免费观看 | 欧美影视一区在线| 国产亚洲精久久久久久| 综合色天天鬼久久鬼色| 日韩av一区二区三区四区| 成人精品在线视频观看| 欧美一区二区三级| 亚洲一区二区在线免费观看视频 | 99久久婷婷国产综合精品电影| 国产激情视频一区二区三区欧美| 高清不卡在线观看| 日韩一区二区三区免费看| 亚洲黄色片在线观看| av一本久道久久综合久久鬼色| 欧美性视频一区二区三区| 久久久美女毛片| 国模套图日韩精品一区二区| 欧美一区二区在线观看| 亚洲图片一区二区| 欧美日本乱大交xxxxx| 视频一区二区中文字幕| 色狠狠桃花综合| 一区二区三区国产豹纹内裤在线| eeuss鲁片一区二区三区在线看| 精品捆绑美女sm三区| 久久激情五月婷婷| 久久夜色精品一区| 不卡视频在线观看| 亚洲精品成人天堂一二三| 欧美综合欧美视频| 亚洲国产成人av网| 日韩久久精品一区| 国产一区 二区| 亚洲视频在线一区观看| 欧美日精品一区视频| 日韩精品91亚洲二区在线观看| 在线不卡的av| 国产高清在线观看免费不卡| 欧美国产日产图区| 在线观看亚洲精品| 国产一区二区三区在线看麻豆| 国产欧美中文在线| 欧美午夜精品一区二区蜜桃| 粉嫩av一区二区三区在线播放| 一区二区三区免费网站| 精品国产1区2区3区| 色婷婷综合在线| 裸体歌舞表演一区二区| 亚洲图片另类小说| 日韩欧美www| 色噜噜狠狠色综合中国| 国产自产v一区二区三区c| 亚洲成人一区在线| 亚洲色图制服丝袜| 久久精品视频免费| www.亚洲在线| 国产一区二区三区综合| 亚洲成在线观看| 亚洲欧美日本在线| 国产精品久久午夜| 精品成人a区在线观看| 欧美亚洲免费在线一区| 一本大道久久a久久综合婷婷| 国产精品亚洲综合一区在线观看| 美女视频黄久久| 婷婷六月综合亚洲| 日韩在线观看一区二区| 午夜久久久久久久久久一区二区| 国产精品久久久久久久浪潮网站| 久久精品视频一区二区三区| 亚洲精品一区二区三区蜜桃下载 | 欧美bbbbb| 久久激情五月婷婷| 国内精品不卡在线| 国产成人精品影院| 欧洲视频一区二区| 日韩一区二区免费在线观看| 日韩一区二区三区在线视频| 日韩欧美一级在线播放| 久久这里只精品最新地址| 中文字幕国产精品一区二区| 国产欧美日韩在线| 亚洲免费色视频| 麻豆久久久久久| 成人免费视频播放| 欧美日韩高清一区二区不卡| 日韩欧美国产电影| 中文字幕日韩一区| 日韩国产成人精品| 国产成人精品免费看| 欧美精品成人一区二区三区四区| 欧美mv和日韩mv的网站| 一区二区三区四区国产精品| 韩国v欧美v日本v亚洲v| 欧美卡1卡2卡| 亚洲免费大片在线观看| 精品中文字幕一区二区| 欧美日韩久久久一区|