C # getting started with Windows Graphics Development

Source: Internet
Author: User
Tags ftp file xslt web database
C # getting started with Windows Graphics Development

Yuan Yongfu

Course Series

To help you better understand and use C #, we will begin this series of technical lectures on the "C # discovery Journey. Considering that most of you are engaged in WEB database development, the so-called discovery is to discover areas we are not familiar with, so the content of this series of lectures will be C # applications other than WEB database development. Currently, the main content of the plan is graphic development and XML development, and multiple courses are planned and arranged. In the future C # discovery journey, we will explore and discover other unknown fields of C # in a step-by-step manner, more in-depth understanding and understanding of using C # for software development, broaden our horizons, and enhance our comprehensive software development capabilities.

The Demo code for this series of courses is http://files.cnblogs.com/xdesigner/cs_discovery.zip.

Articles published in this series of courses include:
C # discovery tour lecture C #-XML Development
C # Journey to Discovery C #-XSLT Development
C # Journey to Discovery Lecture 3 use C # To develop XSLT-based code generators
C # getting started with Windows Graphics Development
C # journey of discovery Part 5 basics of graph Development
C # discovery tour lecture 6 C # intermediate level of graph Development
C # discovery journey Lecture 7 C # advanced graphic development
C # Journey to Discovery lecture 8 ASP. NET graphic development with hyperlink pie chart
C # Learning ASP. NET Verification Code Technology
C # discovery journey Article 10 Object Model

BenCourse description

This course is an introduction to Windows Graphics development. It is a graphic development knowledge literacy. It mainly introduces some basic theoretical knowledge of Graphic programming and does not provide supporting demonstration source code. Including

  1. Comparison Between WEB database development and graph Development
  2. Basic Principles of Windows Graphics Subsystem
  3. Graphical device context
  4. Vector Graphics and bitmap
  5. Graphic Coordinate System
  6. Basic graphic interface elements
  7. User Interface events

I assume that you have a certain degree of Computer Software Development basics and basic knowledge about computer software and hardware, but you are not familiar with Windows Graphics development. Therefore, we will introduce the basic principles of Windows Graphics development, which does not involve actual development. In future serial training, we will use C # To demonstrate the actual development of Windows Graphics Based on this training.

Comparison Between WEB database development and graph Development

Now let's talk about the comparison between WEB database development and graph development. Most of us are engaged in WEB database development. Their user interfaces are basically described based on HTML. In fact, desktop development is also very promising, and a very important part of desktop development is graphic development. Compared with Web development, graph development is quite different. Its development ideas, technical means, and debugging skills are quite different. The following describes how to develop graph development.

Target Fields

There is a big difference between Web Database Programming and graph development. Most Web database programming is for engineering development, which is full of various business data structures and business logic processing. In contrast, graphic development has more technical factors, and is more specialized and underlying in the field. For those who want to make breakthroughs in pure technology, graph development is a good choice.

Difficulty

It is difficult to learn and master graph development. Therefore, developers who are familiar with graph development are relatively few, and various software skills training institutions provide WEB database development training, however, training on graphic development is rare. As there are few people and few people compete, the graphic software development capability becomes a distinctive software development capability.

Relationship with databases

Web database application systems depend on relational databases, which are the most important part of their systems. However, graphics development focuses on user interfaces and graphic document output. Therefore, there is less dependency on the database, and databases are not required for the normal operation of many graphic software.

Software Design and Development

Complex graphic development requires a lot of software design patterns, and sometimes requires document object models, such as advanced software design models, these complex software design patterns are rarely used in the development of conventional small and medium-sized WEB databases. Therefore, in-depth study of graphic development will significantly enhance developers' software design capabilities.

Compared with Web Database Programming, graph development is quite different in development, debugging, and optimization methods. In some cases, it is quite difficult to debug graphics programs, however, the graphic program's unique anti-Flicker optimization process is quite difficult, which tests developers' software development capabilities.

Application

In the current enterprise information and e-government, the WEB database development model occupies the mainstream, but the graphic development still has a wide range of applications, and many are relatively low-level, basic software development. For example, WEB browser,. NET development environment, and even the Windows operating system itself are graphical development products, WEB software charts, curves and other HTML difficult to display user interfaces, generally rely on Graphic programming to achieve.

Outlook

For many people, graphic development is a brand new development field and requires new software design verification and development modes. However, graphic development is also a rich and colorful world, there are a lot of technologies waiting for everyone to explore. Although it is difficult to develop graphics, it is still worth learning and using. It is a high-quality software development capability because it is difficult to develop images and has a high technical level. If you want to explore new technical fields and gain distinctive development capabilities, you can learn about Windows Graphics development from now on.

Basic Principles of Windows Graphics Subsystem

A Windows operating system has a graphical user interface, which greatly improves the user experience and allows a large number of common users to conveniently learn and use Windows operating systems, this is an important factor for Microsoft's great success.

The Windows operating system also provides powerful programming interfaces for graphic development, allowing developers to easily develop professional graphic user interface software on Windows. Before Windows, developers needed a lot of computer hardware knowledge to implement graphical user interfaces, and the computer software industry had a slow progress in graphical user interfaces, windows provides a very convenient graphic development platform, which enables the rapid emergence of a large number of graphical user interface software, thus promoting the overall rapid development of computer software.

The Windows operating system contains a graphics subsystem that is used to manage a variety of graphics output devices, including displays, printers, and mappers. Because the Windows system enables the protection mode, applications do not have the permission to directly access computer hardware, so you must call the Windows Graphics subsystem to operate graphics devices. Is the basic principle of Windows environment software.

Windows provides a GDI32.DLL. Anyone who knows about graph development knows about this DLL. It contains the API functions of most Windows Graphics subsystems. Various development languages, including VB, VC, C #, and Delphi, can call these API functions for graphic development.

After Windows obtains the graphic operation request of the application system through these APIs, it processes the request internally and calls the corresponding Device Driver Based on the target graphic hardware.

If the application system requests to display the graphics on the display, Windows will first set the computer to display the graphics, and then be busy with other things, while an independent processor in the video card can access the video memory, set the content displayed on the monitor based on the data. The video card is fixed to access the video memory every time, refreshing the display, so it has a frequency parameter. For example, if the frequency is 50 HZ, It accesses the video memory every 20 milliseconds and refreshes the display. The video card has its own processor to perform such operations. This operation is a hardware operation and its process is not perceived and controlled by the operating system. Understanding this principle is of great help to understand and eliminate user interface flashes.

If the application system requests to print the output, Windows first prints the print style to the print task queue, and then calls the printer driver to print the document, therefore, multiple software can print the output at the same time without waiting for the printer hardware to be idle. In Windows or later versions, there is a service named "Print Spooler", which is used to manage the Print task queue. if the service is stopped, the system cannot print the output even if it is connected to a printer.

Graphical device context

After learning about the basic principles of the Windows Graphics subsystem, we can start to understand Windows Graphics development. A very important concept in Windows Graphics development is the graphics device context.

Handle

If you have some knowledge about Windows programming, you should know that Windows API is a C-language function, and applications access most of the operating system resources through an integer data type called a handle. For example, when a program accesses files, network resources, images, and forms, it will call the API function in advance to obtain a handle. The handle can be understood as the unique number of system resources. The application should keep the handle properly, make proper use of the service and use the API function to release it when not in use.

Graphical device context handle

When the application software performs graphical operations, it also needs to use the API function to apply for a graphical device context handle. In the future, all graphic operations will be performed on this handle, after the graphic operation is completed, the application software must use the API to release the context handle of the graphic device.

The context of a graphic device is an abstract concept, not limited to specific hardware. Therefore, the context handle of a graphic device can be pointed to a display in Windows, it can also point to a printer or other graphic hardware. This process is transparent to the application software. Therefore, the application system can easily implement WYSIWYG functions. A graphic operation code can be used to output graphics to the computer screen or to control the output Graphics of the printer, which facilitates graphic development.

Software Design Model

This abstract concept is applied to different specific applications and is a software design pattern. For example, there is an abstract class System in C. IO. stream, which represents the concept of an abstract Stream, and. NET framework implements various specific streams in the stream of this abstract concept, such as for files, HTTP resources, and memory. As long as the application software writes code to save the data to an abstract stream, the same code can save the data to a local file, HTTP file, FTP file or memory. This facilitates program development and expansion.

Vector Graphics and bitmap

Concept

There are two important concepts in graph development: vector graphics and bitmap.

Vector Graphics describe graphs using abstract concepts such as point and line planes in plane ry. Bitmap uses a large number of dense two-dimensional arrays of pixels to describe the image.

For the computer, vector images are complex, but the data size is small and can be scaled without any changes. The bitmap display process is simple, but the data size is large and the display effect is poor.

Example

There are many examples of vector and bitmap in our computer. The watermark file is large and the display quality is poor when it is enlarged.

For example, Windows Font. Windows fonts include bitmap fonts and TrueType fonts. Bitmap fonts are based on the concept of bitmap, while TrueType fonts are based on vector fonts. Currently, most fonts are TrueType fonts. We can set the style and size of these fonts. Even if the text with TrueType fonts is displayed very large, its text contour lines are clear. Currently, a few fonts are bitmap fonts. The most common one is the Fixedsys font used by default in Windows notepad. This font is obviously jagged when being enlarged. The output quality is not high.

Graphic Coordinate System

Cardinar Cartesian coordinates

A coordinate system is required to describe and display vector images. Currently, cardinar coordinates are used, that is, Cartesian coordinates with X-Y axes. Each Graphic Element in the drawing is determined by several X-Y coordinate values and width height values. For example, a point uses a pair of XY values to determine the position, while a line segment uses two XY values to locate the position, while a rectangle uses a XY value and a width height value to locate the position. A circle or an elliptic is determined by an excircle.

Measurement Unit

You also need to specify the measurement unit in the coordinate system. The measurement unit can be in centimeters or inches. For graphic user interface software, pixel units are often used.

Centimeter, inch, and so on are abstract measurement units, and the image uses this abstract unit measurement is absolutely accurate. The pixel measurement unit is related to the graphic hardware. Generally, the length of a display pixel is 96 pixels and 1 inch, while that of a printer is hundreds or even thousands of pixels. Therefore, if the pixel size is used for the same image, the difference between the display size and the actual printing size is very large. In this case, measures such as centimeters and inches should be used to achieve what you see is what you get.

This situation has been taken into account in. NET. The Enumeration type System. Drawing. GraphicsUnit lists some standard coordinate measurement units.

Coordinate Transformation-Matrix (Matrix ?)

The coordinate system can also be converted. The conversion types mainly include translation, rotation, and scaling. Translation refers to moving up, down, left, and right of the coordinate origin (points with XY values all 0) without changing attributes such as the coordinate measurement unit. Rotation refers to the center of the coordinate system as a whole, clockwise rotation of a certain angle, while scaling is to zoom in or out the X or Y axis, the zooming in the X and Y directions can be independent.

As we all know, the movie "Matrix" has an English name. the. NET Framework also provides a Matrix, which is a coordinate conversion object for ease of use. It is a 3x3 matrix, and the translation rotation and scaling of the coordinate system are implemented through a matrix operation. Using the coordinate conversion object, the. NET program can easily implement certain special effects, such as vertical display of text, text stretching or compression display, etc.

Basic graphic interface elements

Most of the images we develop operate on vector graphics. In plane ry, a vector image consists of a dot and a line. Therefore, a line or a plane is the basic element of a vector image. In actual graphic development, the main basic elements of the graphic interface include text, straight line segments, rectangles, rectangles (including positive circles), elliptical arcs (including arcs), and some other curves. Basic Drawing operations include drawing lines and filling areas. The above method can be used to plot the vast majority of images.

On the Windows graphic user interface, the most commonly used basic graphic elements are text and rectangle. Various Forms, controls, and their outlines are rectangles. The text can be a single row and multiple rows, which can be divided into left-aligned, center-aligned, and right-aligned. Drawing text and rectangles is the simplest and most basic graphic operation.

User Interface events

Most graphical user interfaces need to respond to user interface events for interactive user experience. User Interface events mainly include window weight painting events, mouse and keyboard events, Timer events, and OLE drag events, the most important is the window weight painting and mouse and keyboard events.

The underlying Windows layer uses Windows messages to notify applications of various events, while the. NET Framework encapsulates the message processing and provides some scalable programming interfaces to facilitate event response programming. For example, we can mount the MouseDown event of the control, or rewrite the OnMouseDown method of the control to handle the mouse button pressing event.

Window weight painting event

The event that must be processed in the user interface event is a window weight painting event. Windows is a multi-task operating system that allows multiple forms to be displayed on the display at the same time, So forms are inevitably overwritten. Some or all of a form may be overwritten and re-displayed. When the control is hidden to display, the application software needs to re-draw the control's user interface.

, Form 2 overwrites Form 1, and some of my controls are overwritten. When you set the front display of Form 1, the section of my control that was previously overwritten by Form 2 is displayed. At this time, a cut rectangle is formed, and the program needs to re-draw the user interface of my control. Obviously, the program only needs to plot the part included in the cut rectangle, and the other part does not need to be displayed, so that we can use this cut rectangle to optimize our program and reduce the drawing workload.

My control does not need to determine when the user interface will be re-drawn when the form is re-displayed. the Windows operating system will judge this situation and then notify my control through a message to re-draw the user interface, in addition, the position and size of the cut rectangle are indicated during the notification.

On the. NET platform, the. NET Framework has encapsulated the underlying message processing and provided programming interfaces for the Paint event or OnPaint method. We need to mount the Paint event of the control, or rewrite the OnPaint method to re-draw the user interface. In this event, the system provides two parameters: Graphics, a graphical Drawing Object, ClipRectangle, a cut rectangle object, that is, the border of the area to be re-drawn. ClipRectangle is the basis for optimizing drawing operations.

Mouse events

In most cases, users must be able to use mouse operations for processing. In this case, the graphic software must respond to users' mouse operations for some processing. in C # graphics software development, we need to respond to the mouse event of the control. We need to mount the MouseDown of the control or override the OnMouseDown method to handle the mouse press event. We can use the MouseMove or override OnMouseMove method to handle the mouse movement event, use the MouseUp event or override the OnMouseUp method to handle the mouse button release event.

Keyboard Events

Users often need to use the keyboard for operations. For example, for a text editor, users need to use the keyboard to input a large number of text characters and move the cursor. In this case, the graphic software must respond to users' keyboard operations for some processing. in C # graphics software development, we need to respond to the keyboard events of the control, we need to use the KeyDown or override OnKeyDown method to handle keyboard press events, use the KeyUp event or override the OnKeyUp method to handle keyboard press release events, and use the KeyPress or OnKeyPress method to handle keyboard character events.

Other events

In C #, we can also handle other events. For example, if we place a timer control in the form, we can process its timer events to perform operations at a fixed interval. We drag a file from Windows Resource Manager to our program. We can respond to the OLE drag event of the control to accept the data of the drag-and-drop files.

Through a variety of events, we can achieve a variety of Dynamic Operation Features of the graphic user interface. In this way, the graphic software runs normally and provides an interactive user experience.

Summary

This course mainly describes the basic principles of Windows Graphics development and some theoretical knowledge of graphics development. Graph development is a big topic, with a wide range of theoretical knowledge involved. This course cannot be described one by one. In future training, we will begin to use C # To practice graph development, the various software development knowledge involved in the development process should be supplemented.

If you plan to study graph Development carefully, you can take advantage of your initiative and learn from each other. I am familiar with ASP. NET and are unfamiliar with graph programming. From the next course, we will discover C # graph development together.

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.