Several ways to draw straight lines-xinxin Sun C + + notes

Source: Internet
Author: User

//HDC Draw Straight lineCPoint M_ptorigin;voidCdrawview::onlbuttondown (UINT nflags, CPoint point) {m_ptorigin=Point ; Cview::onlbuttondown (nflags, point);}voidCdrawview::onlbuttonup (UINT nflags, CPoint point) {HDC hdc; HDC=:: GetDC (M_hwnd);  Movetoex (hdc, m_ptorigin.x, M_PTORIGIN.Y, NULL);  LineTo (hdc, Point.x, POINT.Y);  :: ReleaseDC (M_hwnd, HDC); Cview::onlbuttonup (nflags, point);}//CDC Draw LinevoidCdrawview::onlbuttondown (UINT nflags, CPoint point) {m_ptorigin=Point ; Cview::onlbuttondown (nflags, point);}voidCdrawview::onlbuttonup (UINT nflags, CPoint point) {CDC*PDC =GetDC (); PDC-MoveTo (M_ptorigin); PDC-LineTo (point);  ReleaseDC (PDC); Cview::onlbuttonup (nflags, point);}//CClientDC, CWINDOWDC draw straight linevoidCdrawview::onlbuttondown (UINT nflags, CPoint point) {m_ptorigin=Point ; Cview::onlbuttondown (nflags, point);}voidCdrawview::onlbuttonup (UINT nflags, CPoint point) {cclientdc DC ( This);//draw to Customer areaCCLIENTDC DC (GetParent ());//draw to the customer area + toolbarsCWINDOWDC DC ( This);//draw to Customer areaCWINDOWDC DC (GetParent ());//draw to client area + Toolbar + menu bar + title barCWINDOWDC DC (GetDesktopWindow ());//Draw the entire screen windowDC.  MoveTo (M_ptorigin); dc.  LineTo (point); Cview::onlbuttonup (nflags, point);}//a colored linevoidCdrawview::onlbuttondown (UINT nflags, CPoint point) {m_ptorigin=Point ; Cview::onlbuttondown (nflags, point);}voidCdrawview::onlbuttonup (UINT nflags, CPoint point) {CPen pen (ps_solid,1, RGB (255,0,0)); CCLIENTDC DC ( This); CPen*poldpen = DC. SelectObject (&pen); dc.  MoveTo (M_ptorigin); dc.  LineTo (point); dc.  SelectObject (Poldpen); Cview::onlbuttonup (nflags, point);}//painting BrushesvoidCdrawview::onlbuttondown (UINT nflags, CPoint point) {m_ptorigin=Point ; Cview::onlbuttondown (nflags, point);}voidCdrawview::onlbuttonup (UINT nflags, CPoint point) {CBrush brush (RGB (255,0,0)); CCLIENTDC DC ( This); dc. FillRect (CRect (M_ptorigin, point),&brush); Cview::onlbuttonup (nflags, point);}//bit drawing BrushvoidCdrawview::onlbuttondown (UINT nflags, CPoint point) {m_ptorigin=Point ; Cview::onlbuttondown (nflags, point);}voidCdrawview::onlbuttonup (UINT nflags, CPoint point) {CBitmap bitmap; Bitmap.  LoadBitmap (IDB_BITMAP1); CBrush Brush (&bitmap); CCLIENTDC DC ( This); dc. FillRect (CRect (M_ptorigin, point),&brush); Cview::onlbuttonup (nflags, point);}//Transparent painting BrushvoidCdrawview::onlbuttondown (UINT nflags, CPoint point) {m_ptorigin=Point ; Cview::onlbuttondown (nflags, point);}voidCdrawview::onlbuttonup (UINT nflags, CPoint point) {cclientdc DC ( This); //DC. Rectangle (CRect (M_ptorigin, point)); //not transparentCBrush *pbrush =Cbrush::fromhandle ((hbrush) Getstockobject (Null_brush)); CBrush*poldbrush =DC.  SelectObject (Pbrush); dc.  Rectangle (CRect (M_ptorigin, point)); dc.    SelectObject (Poldbrush); //TransparentCview::onlbuttonup (nflags, point);}//write with a brushvoidCdrawview::onlbuttondown (UINT nflags, CPoint point) {m_ptorigin=Point ; M_bdraw=TRUE; Cview::onlbuttondown (nflags, point);}voidCdrawview::onlbuttonup (UINT nflags, CPoint point) {M_bdraw=FALSE; Cview::onlbuttonup (nflags, point);}voidCdrawview::onmousemove (UINT nflags, CPoint point) {cclientdc DC ( This); CPen Pen (ps_solid,1, RGB (255,0,0)); CPen*poldpen = DC. SelectObject (&pen); if(M_bdraw = =TRUE) {DC.    MoveTo (M_ptorigin); dc.    LineTo (point); M_ptorigin=Point ; } DC.    SelectObject (Poldpen); Cview::onmousemove (nflags, point);}//Draw FanCPoint M_ptold;voidCdrawview::onlbuttondown (UINT nflags, CPoint point) {m_ptorigin= M_ptold =Point ; M_bdraw=TRUE; Cview::onlbuttondown (nflags, point);}voidCdrawview::onlbuttonup (UINT nflags, CPoint point) {M_bdraw=FALSE; Cview::onlbuttonup (nflags, point);}voidCdrawview::onmousemove (UINT nflags, CPoint point) {cclientdc DC ( This); CPen Pen (ps_solid,1, RGB (255,0,0)); CPen*poldpen = DC. SelectObject (&pen); if(M_bdraw = =TRUE) {DC.    MoveTo (M_ptorigin); dc.    LineTo (M_ptold); //DC. MoveTo (M_ptorigin); //with no edgesdc. MoveTo (M_ptold);//with edgesDC.    LineTo (point); M_ptold=Point ; } DC.  SelectObject (Poldpen); Cview::onmousemove (nflags, point);}

Several ways to draw straight lines-xinxin Sun C + + notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.