Use line to introduce hdc cdc cclientdc cwindowdc usage

Source: Internet
Author: User

Create a project with a single document structure

HDC:

First, add windows message handler in the cyourclassview class. One is lbuttondown and the other is lbuttonup. Add the member variable m_ptorigin to record the initial vertex position.

Initialize the m_ptorigin variable in the view struct:

Cyourclassview: cyourclassview ()

{

// Todo: Add construction code here

M_ptorigin = 0;

}

Add the code to the lbuttondown function:

Void cyourclassview: onlbuttondown (uint nflags, cpoint point)

{

// Todo: add your message handler code here and/or call default

M_ptorigin = point;

Cview: onlbuttondown (nflags, point );

}

Add code in lbuttonup, first use HDC:

Void cyourclassview: onlbuttonup (uint nflags, cpoint point)

{

// Todo: add your message handler code here and/or call default

HDC;

HDC =: getwindowdc (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 );

}

Use CDC:

Void cyourclassview: onlbuttonup (uint nflags, cpoint point)

{

// Todo: add your message handler code here and/or call default

CDC * PDC = getdc ();

PDC-> moveTo (m_ptorigin );

PDC-> lineto (point );

Releasedc (PDC );

Cview: onlbuttonup (nflags, point );

}

Use cclientdc:

Void cyourclassview: onlbuttonup (uint nflags, cpoint point)

{

// Todo: add your message handler code here and/or call default

Cclientdc DC (this );

DC. moveTo (m_ptorigin );

DC. lineto (point );

Cview: onlbuttonup (nflags, point );

}

Use cwindowdc:

Void cyourclassview: onlbuttonup (uint nflags, cpoint point)

{

// Todo: add your message handler code here and/or call default

Cwindowdc DC (this );

DC. moveTo (m_ptorigin );

DC. lineto (point );

Cview: onlbuttonup (nflags, point );

}

 

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.