Windows program design: no basic self-study _ 5_gdi Basics

Source: Internet
Author: User
Tags textout

A few days ago, I learned about the message processing mechanism of Windows program design, followed by how to process wm_paint messages, and briefly discussed in Lesson 4th.

The processing of the scroll bar is not very tired after work today, so I looked at the basic content of Windows's GDI and posted the summary of the study at night.

Man criticized and corrected.

Haha, I feel that the more I learn from the beginning, the smoother I will learn, and the more difficult I will feel. I hope I can finish reading the book as soon as possible.

Core programming books .....

I still don't know how to use the IDE programming environment of window to draw the application interface, but it doesn't matter. I think I should understand it when I look at the instance .....

Let's talk less about it. Let's take a look at my summary today:

5. GDI graphics Basics
The graphical device interface (GDI: Graphics Device Interface) is a Windows subsystem that displays graphics on standard output devices and printers.
1) The application displays visual information through GDI
2) the Windows system uses GDI to display user interface objects, such as menus, scroll bars, icons, and cursors.
5.1 structure of GDI
From the perspective of applications, GDI consists of a large number of system function calls and related data types, macros, and structures.
5.1.1 principle of GDI
Bytes
Dynamic Link Library to execute many functions, while in ntmedium, 16-bit gdi.exe is only used to implement 16-bit programs.

During the display process, the dynamic link library calls the driver routine of the monitor or printer to display the driver access control hardware and printer driver.
Convert the GDI Command to the code or command that the printer can understand. Therefore, different types of monitors or printers require different device drivers.

The main purpose of GDI is to support device-independent graphic design and output. Windows programs should be able to correctly run on any output devices supported by windows.
1) classification of graphics devices:
Bit imaging device: an array of image points to represent images, such as display cards, dot matrix printers, and laser printers.
Vector devices: draw images using lines
2) Windows graphic element coordinate system
By default, the graphic element coordinate system is used in windows.
Traditional graphic languages use virtual coordinate systems: the horizontal and vertical ranges from 0 ~ 32767
Windowsgdi allows one of two coordinate systems: a virtual coordinate system that is independent of hardware.
Use the device coordinate system to fully adapt to the programming environment provided by hardware devices
5.1.2 call of the GDI Function
GDI function category:
1) function for obtaining (or establishing), releasing (or clearing) device content
Getdc, releasedc
Beginpaint and endpaint
2) functions for obtaining device content information
Getsystemmetrics
Gettextmetrics
3) Plotting Functions
Textout
4) function for setting and obtaining device content parameters
The properties of the device content determine how the plotting function works.
Settextcolor to specify the color of the text drawn by the textout Function
Settextalign specifies that the start position of the string in the textout function should be on the right or the left of the string by default.
5) functions using the GDI object
Exp:
By default, all straight lines drawn by using GDI are solid lines with a standard width.
And line type, you cannot change the properties of the device content, but you can only use a logical paint brush.
To change the line type and line width, you can specify these in the createpen, createpenindirect, or extcreatepen functions.
Feature to create a logical brush, these functions return a logical brush handle. To use this paint brush, select the paint brush handle to the device content.
. It is generally considered that the selected paint brush in the device content is an attribute of the device content, so that you can use this paint brush to draw any line.
You can cancel the paint brush in the device content and clear the paint brush object.
It is necessary to clear the paint brush when it is not needed, but it is not necessary because it occupies the allocated memory space.
In addition to the paint brush, the GDI object is also used to create the painting brush, Font, bitmap, and other aspects of the GDI that fill in the closed area.
GDI basic graphics
Line and curve: line is the basis for drawing all vector Images
Supported by GDI: Straight Line, rectangle, elliptic, circle, arc, besell curve, and line
A line is drawn by the selected paint brush in the device content.
Fill in the Area:
When a series of straight lines or curves close a region, the region can be mapped using the current GDI paint brush object.
It can be a solid color, pattern, or a vertical or horizontal repeating bitmap image in the area.
Bitmap:
Bitmap is a rectangle array of bits. These bits correspond to the elements on the display device. They are basic tools for bit image.
Bitmap:
Used to display complex images on a display or printer
Displays small images, cursors, icons, and buttons that must be quickly drawn on the toolbar.
Text:
Text is one of the most complex objects in the display system.
Other parts of GDI
Image mode and Transformation:
By default, Windows draws in units of pixels and supports drawing in units of inches and millimeters.
Metafile
A set of GDI commands stored in binary format, used to pass graphics through the clipboard
Drawing area:
A drawing area is a complex area and is usually defined as a combination of relatively simple drawing areas.
Path:
It is a set of lines and curves stored in GDI. paths can be used for drawing, filling in graphics, cropping, and converting to drawing areas.
Cropping:
A drawing can be restricted to a certain part of the display area. This is called cropping. The cropping area can be a rectangle or a rectangle.
It is usually defined by region or path.
Color Palette:
Custom color palette is usually limited to 256-Color Display
Print:
5.2 device content
To draw a graph on a graphic output device, you must first obtain the handle of the device content and send the handle back to the program to obtain the permission to use the device.
Drawing.
The windowsgdi function uses the returned device content handle as a parameter to identify the device on which you want to draw.
The device content contains many current attributes that determine how the GDI function works on the device. These attributes allow the parameters passed to the GDI function to only contain the starting coordinates.
Or dimension information, without including all other information about the device content.
To change the device content attributes, you must use the device content attribute setting function.
5.2.1 get device content handle
Windows provides multiple methods to get device content handles. If a device content handle is obtained when processing a message
(Exit the window function). Once the handle is released, it is not valid.
Method 1:
Use the beginpaint function to get the device content handle when processing the wm_paint message.
Exp:
HDC = beginpaint (hwnd, & PS );
Other Program
Endpaint (hwnd, & PS );
Tip:
The variable PS is a paintstruct structure variable. The HDC field of this structure is the device content handle returned by beginpaint,
The paintstruct structure also contains a rect structure named rcpaint. rcpaint defines a rectangle that contains an invalid range in the display area of the window,
The device content handle obtained using beginpaint can only be drawn in this area. The beginpaint function calls to make the invalid region valid.
Method 2:
Get the device content handle when processing non-wm_paint messages
Exp:
HDC = getdc (hwnd );
Other Program
Releasedc (hwnd, HDC );
Tip:
The device content handle obtained in this way allows plotting in the entire display area, and this function call does not make the invalid area of the display area valid.
Method 3:
Obtains the device content handle of the entire window.
Exp:
HDC = getwindowdc (hwnd );
Other Program
Releasedc (hwnd, HDC );
Tip:
In addition to the display area, the content processing area of the device also includes the title column, menu, scroll bar, and frame of the window.
If you want to use this function call, you must intercept and process the wm_ncpaint message. Windows uses this message to draw in a non-display area.
Method 4:
Beginpaint, getdc, and getwindowdc are related to specific windows.
You can obtain the device content handle that is not first closed with a specific window, and use the createdc Function
Exp:
HDC = createdc (pszdriver, pszdevice, pszoutput, pdata );
Other Program
Deletedc (HDC );
For example, you can use:
HDC = createdc (text ("display"), null );

Writing a screen outside a window is usually inappropriate, but it is very convenient for some unusual programs.

When you only need to obtain the device content information of a device without drawing it, you can use createc to obtain a handle of the information content,
The parameters of the createc function are the same as those of createdc.
Exp:
HDC = createc (text ("display"), null); // Of course, this information cannot be used to put shoes on the device content.

It is sometimes useful to obtain the content of a memory device when bitmap is used:
Exp:
Hdcmem = createcompatibledc (HDC );
Other Program
Deletedc (hdcmem );
Tip:
You can select the memory device content as the bitmap, and then use the GDI function to draw a map in place.

Metafile:
Metafile is a set of GDI calls, which are binary encoded. You can create Metafile by obtaining the Metafile device content:
Exp:
Hdcmeta = createmetafile (pszfilename );
Other Program
Hmf = closemetafile (hdcmeta );
Tip:
When the content of the Metafile device is valid, any GDI call made with hdcmeta becomes part of the Metafile and will not be displayed.
After closemetafile is called, the device content handle becomes invalid, and the closemetafile function returns a handle that executes Metafile (hmf.
5.2.2 obtain device content information
The content of a device usually refers to an actual display device that can obtain information about the device, such as the display size and color display capability. You can use
The getdevicecaps function is used to obtain these messages.
Exp:
Ivalue = getdevicecaps (HDC, iindex );
Tip:
Iindex is one of the 29 macros defined in the wingdi. h header file.
For example:
If iindex is horzres, getdevicecaps will be sent back to the device in width (in the unit of pixels). If iindex is vertres, getdevicecaps will
Returns the height of the device. If HDC is the content handle of the printer device, getdevicecaps returns the height and width (unit:
Is a graphic element ).

The above content is just a bit of an eye. You are welcome to bend over and find the bricks ....................

The more I build the house, the better I can collect and build the bricks myself. Now the house price is so high, it is a good choice to build the house .....

Haha ...............

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.