Application of GDI + in Win32 (v) The difference between--gdi and GDI + programming models

Source: Internet
Author: User

In GDI, if you want to start your own drawing work, you must first obtain a device context handle, and then use this handle as a parameter of the drawing complex method to complete the task. Also, device context handle is bound to a certain drawing property, such as a brush, a brush, and so on, and you must create your own brush before you draw the line, and then use the SelectObject method to apply the brush to the already acquired device context Handle binding to start drawing lines using LineTo and other methods. Otherwise, you draw the line using the default properties: Width (1), Color (black).
However, in GDI +, the line drawing method drawline The brush pen directly as a parameter, so that a certain brush does not need to be directly bound to the device context handle.
Here is a demonstration of the line code for GDI and GDI +:

Gdi:

HDC          HDC; Paintstruct  PS; Hpen         Hpen; Hpen         hpenold;hdc = BeginPaint (hWnd, &ps); hpen = CreatePen (Ps_solid, 3, RGB (255, 0, 0)); hpenold = (Hpen) selectobje CT (hdc, hpen); Movetoex (hdc, +, NULL); LineTo (HDC, 200, 100); SelectObject (hdc, Hpenold);D eleteobject (Hpen); EndPaint (HWnd, &ps);

Gdi+:

HDC          HDC; Paintstruct  PS; pen*         Mypen; graphics*    mygraphics;hdc = BeginPaint (hWnd, &ps); mypen = new Pen (Color (255, 255, 0, 0), 3); mygraphics = new Graphi CS (HDC); Mygraphics->drawline (Mypen, elete, ten, max);d Mygraphics;delete Mypen; EndPaint (HWnd, &ps);

Reprint Address: http://www.cppblog.com/dingding/archive/2008/06/27/54797.html

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.