1. Graphic Output devices are divided into optical shed devices and vector devices. Most PC output devices are optical devices, indicating images in dot mode. A vector device uses a line to draw an image, such as a plotter. Vector programs are abstracted on top of hardware.
2. Classification of GDI functions.
Functions for obtaining (creating) and releasing (clearing) device description tables, such as getdc and releasedc; functions for obtaining device description table information, such as gettextmetrics and drawing functions, such as textout; set and obtain the parameters of the device description table, for example, settextcolor controls the color of the output text in textout, and uses functions of the GDI object, such as createpen.
3. elements. Line and curve, drawn by pen; Filled Area; bitmap; text;
4. How to obtain the device description table:
1) HDC = beginpaint (hwnd, & PS );
Endpaint (hwnd, & PS );
2) HDC = getdc (hwnd); // Note: getdc (null) gets the DC of the entire Screen
Releasedc (hwnd, HDC );
3) hwd = getwindowdc (hwnd );
Releasedc (hwnd, HDC );
4) HDC = createdc (lpszdrivername, lpszdevicename, lpszoutput, lpinitdata); // Note: createdc (_ T ("display"), null) Get the entire screen DC
Deletedc (HDC );
5) hdcmem = createcompatibledc (HDC); // available memory device description table when using bitmap
Deletedc (hdcmem );
6) hdcmeta = createmetafile (pszfilename); // obtain the device description table of the Metafile.
Hmf = closemetafile (hdcmeta );
5. A device description table is usually a physical display device.
Ivalue = getdevicecaps (HDC, iindex); // obtain the DC Attributes Based on iindex.
6. Save the device description table.
Wndclass. Style = cs_owndc; // you can create your own DC for the window. After the DC is modified, the DC will remain valid until endpaint or releasedc.
Idsaved = savedc (HDC );
// Modify DC attributes
Restoredc (HDC, idsaved); // restore the saved DC
The preceding statement is equivalent to savedc (HDC );
Restoredc (HDC,-1 );
7. Draw a line.
DC properties that affect the draw line: current paint brush position, paint brush, background mode, background color, and drawing mode.
Draw a straight line:
Movetoex (HDC, xbeg, ybeg, null );
Lineto (HDC, xend, yend );
Getcurrentpositionex (HDC, & pt); // get the current location
8. paint brush.
Hpen, hpenold;
Hpen = getstockobject (white_pen); // obtain the existing paint brush handle
Hpenold = SelectObject (HDC, Hpen); // select the paint brush from the device description table. hpenold records the old paint brush.
// Createownpen
Hpen = createpen (ipenstyle, ipenwidth, crcolor); // A Method
Logpen;
Hpen = createpenindirect (& logpen); // ANOTHER METHOD
Delectobject (SelectObject (HDC, Hpen); // Delete the paint brush in time to save resources
// Obtain the paint brush Information
GetObject (Hpen, sizeof (logpen), (lpvoid) & logpen); // obtain the Hpen attribute
Hpen = getcurrenobject (HDC, obj_pen); // obtain the Hpen in the current DC
// Fill gaps between the dotted line and dotted line, affected by the background mode and background color of DC
Setbkcolor (HDC, crcolor); // you can specify the background color.
Setbkmode (HDC, trasparent); // The transparent tissue fills the background, and the opaque mode fills the gaps with the background color
// Drawing Method
// Bitwise operation between the paint brush pixel and the original pixel at the target position is called the "grating operation" drop. The draw line is only two-dimensional and is called ROP2. It is interesting.
Setrop2 (HDC, idrawmode );
Idrawmode = getrop2 (HDC); // The default value is r2_copypen. The paint color replaces the background.
9. Fill area.
Rectangle, ellipse, roundrect, Chord, pie, polygon, polypolygon
The boundary frame painting method is the same as the draw line method, and the closed area is filled with hbrush.
Hbrush = getstockobject (white_bursh );
SelectObject (HDC, hbrush );
SelectObject (HDC, getstockobject (null_pen); // draw a borderless frame.
SelectObject (HDC, getstockobject (null_brush); // do not fill the area
// There are two ways to fill a polygon: Alternate and winding. The difference is amazing.
10. paint brush.
Hbrush = createsolidbrush (crcolor); // create a paint brush
Hbrush = createhatchbrush (ihatchstyle, crcolor); // create an oblique shadow image brush
Hbrush = createpatternbrush/* createdibpatternbrushpt */; // create a bitmap-based image brush
Logbrush;
Hbrush = createbrushindirect (& logbrush );
// Other operations are similar to Hpen
11. GDI ing mode.
Setmapmode (HDC, imapmode );
Imapmode = getmapmode (HDC );
// For other related ing methods, I personally think it is very unlikely to be used.
12. rectangle, area, and clipping.
Fillrect (HDC, & rect, hbrush); // you do not need to select hbrush into HDC.
Framerect (HDC, & rect, hbrush); // draw a rectangular box with a brush, but do not fill it
Invertrect (HDC, & rect); // flip all pixels in the rectangle
Setrect (& rect, xleft, ytop, xright, ybottom );
Offsetrect (& rect, x, y); // move the rectangle to several units.
Inflaterect (& rect, x, y); // increase or decrease the size of the rectangle
Setrectempty (& rect); // The rectangle is 0.
Copyrect (& rcdest, & rcsrc); // copy
Intersectrect (& rcdest, & rcsrc1, & rcsrc2); // returns the intersection of two rectangles.
Unionrect (& rcdest, & rcsrc1, & rcsrc2); // returns the union of two rectangles.
Bempty = isrectempty (& rect); // determine whether it is empty
Binrect = ptinrect (& rect, point); // whether the vertex is inside the rectangle
13. peekmessage (& MSG, null, 0, 0, pm_remove); // large guy, worth noting
ThePeekmessageFunction normally does not remove
Wm_paintMessages from the queue.Wm_paintMessages remain in the queue until they are processed. However, if
Wm_paintMessage has a null update region,PeekmessageDoes remove it from the queue.
-- The excerpt from msdn seems to be different from what I mentioned in the book. Please note that
14. Region
Hrgn = createrectrgn (xleft, ytop, xright, ybottom );
Hrgn = createrectrgnindirect (& rect );
Hrgn = createellipticrgn (xleft, ytop, xright, ybottom );
Hrgn = createellipticrgnindirect (& rect );
Irgntype = combinergn (hdestrgn, hsrcrgn1, hsrcrgn2, icombine );
// The region filling parameter is similar to the rect
Summary:
Recently, a large number of drawing operations have been used in the company's projects, mainly Designing Self-painting interfaces, repeatedly pasting bitmap to specific rect, and setting transparent colors. As a Windows program design, it will inevitably involve the development of self-painting controls. A major part of the work of Self-painting controls is to change the control UI, drawing can help you better understand the code,