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