DGI Related basic knowledge

Source: Internet
Author: User
Tags ellipse drawing textout

Original link: http://blog.csdn.net/poem_qianmo/article/details/7333886

The GDI (graphics device Interface) graphics devices Interface, which governs the image display and output functions of all imaging devices. The Windows system now has a graphical operating environment for which he has been credited.

Ⅰ. Coordinates with DC

* Create a window that displays a screen that divides three areas, that is, the screen area (screens), the window area (Windows), and the Internal window area (Client);

* Device context (equipment content) that is DC,DC is the place where the program can draw;

* to obtain a window DC outside of the processing wm_paint, if the GetDC () function is used to obtain the window DC, the DC must be freed using the ReleaseDC () function. Here's how:

HDC GetDC (HWND hwnd);//Get DC

Int ReleaseDC (HWND hwnd,hdc GETEDHDC);//release DC, if run successfully, return integer 1, if failed returns 0 GETEDHDC to be freed DC

II. Brushes and paint brushes

* brushes and brushes are graphical objects defined in GDI, and the brush is the style of the line. The paint brush is a style that encloses the inner fill of the drawing. You can customize the brush and brush style used for the drawing, the system preset brush style is Black_pen, and the brush style is null_brush.

* Custom brush or brush style, using the following 3 API functions:

Hpen CreatePen (int style, int width, colorref color);            Build Brush Hbrush Createhatchbrush (colorref color);         Build Shadow Brush hbrush CreateSolidBrush (colorref color); Create a monochrome paint brush

* The basic process used by GDI objects is: Create-choose-Delete, GDI objects are: brushes, brushes, bitmaps, fonts, regions and color palettes.

1. After creating a new brush and a new brush, you must select them in the DC that you want to draw to produce the desired brush and brush effect, and we use the SelectObject () function:

Hgdiobj SelectObject (HDC hdc,hgdiobj GDI object);//Select GDI object to return the previously used GDI object

2, GDI objects once established will occupy a portion of memory, once not used, it is necessary to use DeleteObject to delete them:

BOOL DeleteObject (hgdiobj Dgi object);//Delete GDI object Delete successfully returns Boolean "Ture" if Failed returns "FALSE"

Iii. GDI drawing functions

* virtual BOOL TextOut (

int x,//x coordinate of output string

int y,//y-coordinate of the output string

LPCTSTR lpszstring,//String pointer

int ncount//length of string

);

BOOL TextOut (  _in_ hdc hdc,  _in_ int nxstart,  _in_ int nystart,  _in_ lpctstr lpstring,  _in_ int C chstring);
TextOut function writes a character string at the specified location, using the currently selected font, Backgrou nd color, and text color.
* polygon function

Polygon () drawing closed polygons

PolyLine () Draw multilateral lines

Polybneto () Draws a multilateral line at the position of the current brush

Polypolygon () draw multiple closed polygons

Polypolyline () Draw multiple multilateral lines

BOOL Polygon (  _in_ hdc hdc,  _in_ Const point *lppoints,  _in_ int ncount);
Parameters
HDC [In]

A handle to the device context.

lpPoints [In]

A pointer to an array of point structures This specify the vertices of the polygon, in logical coordinates.

ncount [In]

The number of vertices in the array. This value must is greater than or equal to 2.

Return value

If The function succeeds, the return value is nonzero.

If The function fails, the return value is zero. Remarks

The polygon is closed automatically by drawing a line from the last vertex to the first.

* closed graph function

1. GDI functions for drawing rectangles

BOOL Rectangle (

int x1,

int Y1,

int x2,

int y2

);

BOOL Rectangle (

Lpcrect LpRect

);

2. GDI functions for Ellipse drawing

BOOL Ellipse (

int x1,

int Y1,

int x2,

int y2

);

BOOL Ellipse (

Lpcrect LpRect

);

3. Draw rounded rectangles

BOOL RoundRect (

int x1,

int Y1,

int x2,

int Y2,

int X3,

int Y3

);

BOOL RoundRect (

Lpcrect LpRect,

Point Point

);

4. Draw a fan

BOOL Pie (

int x1,

int Y1,

int x2,

int Y2,

int X3,

int Y3,

int X4,

int Y4

);

BOOL Pie (

Lpcrect LpRect,

Point Ptstart,

Point Ptend

);

5. Draw a Bow

BOOL Chord (

int x1,

int Y1,

int x2,

int Y2,

int X3,

int Y3,

int X4,

int Y4

);

BOOL Chord (

Lpcrect LpRect,

Point Ptstart,

Point Ptend

);

DGI Related basic knowledge

Related Article

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.