Chapter 5 Graphics Foundation (1) ---- Basic Knowledge
The previous chapters involve some knowledge and use of the window customer drawing graphics, this chapter is more detailed to explain the basic principles and use of graphics drawing. Windows offers hundreds of GDI functions, and we do a variety of drawing operations on Windows by calling the GDI function. GDI makes our drawing and equipment, that is, draws the characteristics of these devices that can be drawn in any of Windows support without considering the characteristics of these devices. Almost every GDI function requires a device environment (DC) handle as a parameter, including a number of determine how the GDI function works on the device, such as: font, text color, line color, cable thickness, etc. . To get this information in the device environment, you can use the getDeviceCaps () function. Each drawing process is performed in the order of the following: Get a device environment handle ----> Using the device environment handle and GDI function to draw ----> Release device Environment handle Windows provides several acquisitions and Method for releasing device environments: a) HDC = BeginPaint (HWND, & PS) during WM_PAINT; [Other Program Lines] Endpaint (HWND, & PS); (often used in front of the chapter) b) When processing non-WM_PAINT HDC = getDC (HWND); [Other Program Lines] ReleaseDC (HWND, HDC); C) Getting the device environment handle of the entire window HDC = getWindowDC (HWND); [Other Program Lines] ReleaseDC (HWND, HDC); D) Each screen of the device environment handle HDC = Createdc (Text ("Display", NULL, NULL, NULL); E) Ground only the device environment handle of the entire screen without drawing HDC = Createic (Text ("Display", NULL, NULL, NULL);
In some cases, we need to change the properties of certain device environments, draw the drawing with the changed properties, and then restore the original device environment. You can save the current device environment by the following function: idsaved = savedc (HDC); then restore the original device environment with the following function: rest-C (HDC, IDSaved); or use the following method: Savedc (HDC Restoredc (HDC, -1);
Windows offers some GDI objects (brush, brush, etc.), we can create these objects to select them in the device environment, and Windows can use these objects to draw a variety of graphics.