(Translation) Programming windows-1

zhaozj2021-02-16  45

My words: This is just a few partial parts, please post it first. Translation is very rough, not a set, really have a lot of mistakes!

Author notes

To update information about this book, including possible error reports and new code lists, visit our website www.ceptzold.com. You can also put the problems in this book to Chartains@cpetzold.com. Although I will try to answer every simple question you asked, I can't make any guarantee. I usually have a very busy room, and my cat refuses to learn Windows API.

I would like to thank the Microsoft Press to make every person for this book as other great work. I think this "10th Anniversary Edition" is the best version in Programming Windows (Windows programming). Others in Microsoft (including some Microsoft Windows early developers) also gave me a lot when I wrote the early versions. And the list of these good people is listed in those versions. Thank you for your family and friends, especially those closest friends (you know who you are!). Your support makes it possible to publish this book. Dedicated to you by this book.

Charles Petzold

October 5, 1998

First chapter entry

This book shows you how to write programs running on Microsoft Windows 98, Windows NT4.0, and Windows NT5.0. These programs are written in the C programming language and use the original Windows Application Programming Interface (API). This is as discussed later in this chapter, this is not the only way to write the Windows program. However, no matter what you finally use to write your code, understanding the Windows APIS is important.

As you may know, Windows is a 32-bit Intel microprocessor (such as 486 and Pentium) IBM compatible machine personal computer actually standard graphics operating system, and Windows98 is its last special period. Windows NT is a Windows version that is running on a PC compatible machine and some RISCC thin instructions.

There are three prerequisites using this book. First, you have to familiarize yourself with Windows 98 from a user. You can't expect you to write applications for Windows without understanding its user interface. For this reason, I suggest you use Windows applications to make your program development work (and other work) on Windows-based machines.

Second, you should know C. If you don't understand C, Windows programming may not be a good start. I recommend you learn C in a character environment such as, for example, Windows 98. Windows programming is also included in the character mode programming. In this case, I will make some necessary discussions. But for most, you should be familiar with the language, especially the structure and pointers of C. Some standard C runtime knowledge is helpful, but it is not necessary.

Third, you should install a 32-bit C compiler on your machine and a development environment that is suitable for Windows programming. In this book, I assume that you are using Microsoft Visual C 6.0. It can be purchased separately or as part of Visual Stuido6.0.

This is all, I don't assume what you have experience in graphical interfaces (such as Windows programming).

Windows environment

Windows is almost not included. However, it is easy to forget that Windows brings tremendous changes to the office, how home desktop computers. Windows has a rugged course in its early days, and almost not considered to be destined to conquer the entire desktop market.

History of Windows

Soon after IBM PC introduced, the advantage of the Spring in 1981, the advantage of the PC (and its compatible machine) is MS-DOS to become obvious. It originally represented Microsoft Disk operating systems. MS-DOS is a small operating system. For users, MS-DOS provides a command line for issuing commands such as DIR or TYPE and commands such as loading a program. For programmers, MS-DOS provides a set of functional commands for file input / output (I / O). For other tasks-especially display text, sometimes images to video now devices - the program is to directly control the hardware of the PC. Depending on the limitations of memory and hardware, the complex graphics environment is very slow on a small computer. Apple has a replacement of a character mode environment, which released his more Lisa in January 1983. Then in January 1984, standards were set up with Macintosh as the graphic environment. Although the MAC market share is declining, it is still considered standard when measuring other graphics environments. All graphics environments, including Macintosh and Windows, you have to thank the Xerox Palo Alto Research Center (PARC) early in the middle of the 1970s.

Windows announced by Microsoft in November 1983 (after LISA and Macintosh) and after two years, it was 1985 Your November was officially released. After Microsoft Windows 1.0, there are several updates to support the international market and provide more video devices and printer drivers.

Windows 2.0 is released in November 1987. This version includes changes on several user interfaces. The most meaningful in these changes is to develop overlapping windows to replace the tile windows in Windows 1.0. Windows 2.0 also includes improvements on the keyboard and mouse interface, especially menus and dialogs.

Until this time, Windows also only needs Intel8086 or 8088 microprocessor to run in "real mode", access 1M memory. Windows / 386 (released shortly after Windows 2.0) uses Intel386 microprocessor "virtual 86" mode and multiple tasks of multiple DOS programs that directly access hardware. To comment, Windows2.1 is renamed for Windows / 286.

Windows 3.0 is introduced on May 22, 1990. Previous Windows / 286 and Windows / 386 were integrated in this release. The biggest change in Windows 3.0 is support for the 16-bit protection mode of Intel286, 386, and 486 microprocessors. This allows Windows and Windows applications to access more than 16M memory. Windows uses the "shell" program for running the program and the maintenance of the file is thoroughly changed. Windows3.0 is the first Windows version in the family and office.

Saying Windows history has to mention OS / 2, another option outside of DOS and Windows, developed by Microsoft and IBM. OS / 2 1.0 (only character mode), running on a 286 (or higher) microprocessor and is released in 1987. In October 1988, OS / 2 1.1 has a graphic rendering manager (PM). PM is originally considered to be Windows's protection mode version, but the graphic API has a great change in the degree of change, so that software developers are difficult to support two platforms.

By September 1990, the conflict between IBM and Microsoft reached a climax and requires two companies to take each road. IBM adopted OS / 2 and Microsoft clearly explicitly put Windows as the center of its operating system strategy. When OS / 2 still has some fiery followers, it is still not close to the popularity of Windows.

Microsoft Windows version 3.1 was released in March 1992. Several important features include TrueType font technology (which brings unpolatically zoom fonts to Windows, multimedia (sound and music), object links, and insert (OLE), and standardized general dialogs. Windows3.1 can only run in the protection mode and require at least 286 or 386 of MB memory. WindowsNT is introduced in July 1993 and is the first Windows version that supports Intel386, 486 and Pentium microprocessor 32-bit mode. Programs running under Windows can access a 32-bit flat address space and use a 32-bit instruction set. (I will talk more about the address space behind). WindowsNT is also designed to be portable to non-Intel processors, and have been run in several RISC-based workstations.

Windows95 is incorporated in August 1995. Like WindowsNT, Windows95 also supports 32-bit programming mode. Although it lacks some features of Windows, such as high security (translator Note: God knows!) And portability to the RISC machine. But Windows95 has the advantage of hardware requirements.

Windows98 is released in June 1998 and has a large number of improvements, including appearance, better hardware support, and better integration with the Internet.

Fang side of Windows

Windows98 and WindowsNT are 32-bit multitasking and multi-threaded graphics operating systems. Windows has a graphical user interface (GUI), sometimes referred to as "visual interface" or "graphical Windows environment", concept behind GUI to be traced back to the mid-1970s Xerox Parc is, for example, Alto and STAR machines and like Smalk The work made by the environment. These work outcomes are later brought into mainstream and spread by Apple Computer and Microsoft. Although there is a small period of debate, it is very obvious that the GUI is the most important "perfect decisive" of the personal computer industry (Microsoft Charles Simonyi) Personal Computer Industry.

All GUI utilizes graphics displayed on the display. The graph provides a better utilization of the screen real feature, a video display for querying information, and the video display of Wysiwyg (what you have gone), and you are ready for printing graphics and text.

In the early days, the video display device is just the text used to respond to the user's keyboard. In a graphical interface, the display itself becomes a source entered by the user. The display shows a variety of graphical objects and input methods such as buttons and scroll bars in the form of graphics. Using a keyboard (or, more direct point, a similar mouse pointing device), the user can directly operate the object on the screen. The graphic object can be dragged, the button can be pressed, and the scroll bar can scroll.

The interaction between users and programs is thus closer. It is no longer a path to the computer from the keyboard to the program to the display, and the user directly operates the object on the display.

Users are no longer willing to spend a long time to learn computers or master a new program. Windows helped busy because all applications have the same basic appearance and feel. The program typically takes up the window of a rectangular area on the screen. All windows are indicated by the title bar. Most of the program is called from the menu of the program. A user can view the display information because of the use of scroll bars because it is too large and cannot be placed in one screen. Some menu items open the dialog where users get additional information. A dialog box, specially used to open a file dialog, almost you can discover in every Windows large program. These dialogs appear like (or almost the same) in all Windows programs, and almost always select boot from the same menu item. Once you know how to use a Windows program, you can easily learn other things. The use of the menu and dialog box can go to test a new program and discover its feature. Most of the Windows programs can use the keyboard and use the mouse. Although most of the functionality of the Windows program can be controlled by the keyboard, it is often easier to use the mouse for sporadic transactions.

From the programmer's point of view, the consistent user interface is the result of the establishment method built by using Windows as the menu and dialog. Because it is Windows instead, all menus have the same keyboard and mouse operation methods.

In order to facilitate user operation procedures, it is easy to interact between the two, and Windows supports multitasking. Several Windows programs can run and display at the same time. Each program takes up a window on the screen. The user can drag the window on the screen, change its size, switch between different program, and transfer data from one program to another. Because these windows look like paper on the desktop (of course, before the desktop is dominated by the computer), Windows sometimes said that it is used to display multiple programs using "Betometers".

Early Windows versions use a multitasking mechanism called "No Drag". This means that Windows does not need the system clock to handle time slips between multiple runs between systems. The program itself has to take the initiative to abandon control, so that other programs can be run. Under WindowsNT and Windows 98, multitasking is predecessor and the program itself can clearly call multiple threads that look at the instantity. An operating system cannot implement multiple tasks without any management of memory. When the new program is started and the old program is terminated, the memory may become a fragment. The system must be able to reintertify memory space. This requires the system to put large pieces of code and data into memory.

Even Windows 1.0 running on the 8088 microprocessor can also perform this memory management. Affected by real mode, this ability is only seen as a shocking software engineering skill. In the case of any excess memory, 640 kilobytes (KB) PC architectures have been well slowed down in Windows 1.0. But Microsoft did not stop. Windows 2.0 gives the Windows application to access the ability to extend memory (EMS), and Windows 3.0 is run in the protection mode, which gives the Windows application to access more than 16MB extended memory capabilities. WindowsNT and Windows98 enables a full mature operating system through flat memory space, blowing these old restrictions into the Pacific!

The program running on Windows sharing function (Routine) is located in a file called "Dynamic Library". Windows has a graphical interface. And the Windows program makes full use of graphics and formatted text on the display and printer. A graphical interface is not only more attractive in the look and can distribute advanced information to users.

The programs on Windows do not directly access graphics hardware such as screens and printers. But Windows includes a graphics programming interface (called graphics device interface or GDI). It makes graphics and formatted text easily display. Windows is actually displayed. A program on a Windows can run on any display card with Windows device drivers and printers. The program does not need to manage which device is installed on the system. Place the graphical interface that is unrelated to the IBM PC, is not a relaxed job for Windows developers. The PC design is based on an open structure. Third-party hardware business development PC peripherals are supported, and there is a quite quantity. Although there are several standards, the old MS-DOS program has to support a variety of different hardware devices. Selling small files with one or two disks for a MS-DOS word handler to support various printers, are common things.

Dynamically connected

The center of Windows work is "dynamically connected". Windows provides a rich function that can be used with its feature. Most of them are used to implement its user interface and display text and graphics to the display. These functions are dynamically connected libraries, or in the DLL file. These files have a .dll extension or sometimes .exe, and most of the / windows / system (windows98) and / Windows / System32 (WindowsNT) subdirectory.

In the early days, so many features of Windows were just implemented in three dynamic connection libraries. This represents three major subsystems of Windows, which are kernel (core), user (users), and GDI (graphics device interface). When the trees of the subsystem are increasing in the near future, the function call made by a typical Windows program is still in these three modules. KERNEL (now consisting of 16-bit KRNL386.EXE and 32-bit kernel32.dll) Processes all elements-memory management, file I / O (input and output), and task management that the operating system is traditionally processed. User (implemented in the 16-bit USER.EXE and 32-bit user32.dll) refers to the user interface and all window logic. GDI (implemented in 16-bit GDI.exe and 32-bit GDI32.dll) refers to a graphical device interface that enables programs to display text and graphics to the screen or print onto the printer.

Windows98 supports a function of several applications to use. Each function has a description name. For example, CreateWindows. This function (as you may guess) creates a window for your program. All applications may be declared in the header file. In your Windows program, you use the WINDOWS function to use the C library function such as Strlen. The main difference is that the machine code of the C library function is linked into your program, but the code of the Windows function is in the DLL outside your program.

When you run a Windows program, it passes a process called "Dynamic Connection" with a Windows interface. A Windows .exe file includes a reference to multiple dynamic link libraries that use it. When a Windows marked in memory, the API call in the program is interpreted to point to the entry point of the DLL function. If it has not been loaded, it is also necessary to load memory.

When you link a Windows program, you generate an executable, you must link the "introduction library" provided by your programming environment. These introduction libraries contain a dynamic link library name and all Windows function calls. The linker uses this information to create a table (Table) that Windows is used to explain the Windows function call when the program is loaded in the program.

Other options for Windows programming

In order to illustrate the various techniques of Windows programming, this book has a large number of examples. These programs are written with C and use a simple Windows APIS. I think this approach is classic Windows programming. This is what we write in 1985, WINDOWS 1.0. This method is today, still a valid approach for Windows programming. APIS and memory modules

For a programmer, an operating system is defined by the API provided. The API contains all function calls and related types and structures definitions that can be made by an operating system. In Windows, the API also refers to a special program architecture we have to explore in later chapters.

Overall, Windows API has been stable since Windows 1.0. A programmer with Windows98 programming experience can find that the code on Windows 1.0 is also familiar. API is only improved in terms of performance. Windows1.0 only supports no more than 450 functions, and now there are thousands.

The maximum change in WindowsAPI and its grammar appears when the 16-bit architecture is transformed into a 32-bit architecture. 1.0 editions from version 3.1, Windows uses a 16-bit Intel8086, 8088, and 80286 microprocessor model called segmentation memory. To be compatible, this model is also supported from 32-bit Intel microprocessor starting from 386. The size of the microprocessor's register is 16 bits in this mode, so C's INT data type is also 16-bit wide. In segmentation memory mode, the memory address consists of a 16-bit segment pointer and another 16-bit OFFSET pointer. From a programmer's point of view, this is very chaotic and long and long-pointed (ie, the segment pointer and OFFSET pointer) distinguishes the difference and the shortementary pointer (including an Offset pointer to the segment pointer).

Starting with WindowsNT and Windows 95, Windows uses Intel386, 486 and 32-bit mode of the Pentium microprocessor to support 32-bit flat (FLAT) memory. C The int data type is developed into a 32-bit value. The program written for Windows 32 only needs to simply use a 32-bit pointer indicating a flat addressing space.

Windows16-bit version (Windows 1.0 to Windows 3.1) is called Win16. The API of Windows32-bit version (all versions of Windows95, Windows 98, and Windows) is called Win32. Many Win16's function call to Win32 is still the same, but some need some modifications. For example, the graphics coordinate point is changed from 16-bit values ​​in WIN16 to 32-bit values ​​in WIN32. At the same time, some Win16 functions returns a 32-bit value represented two-dimensional coordinate point. This is impossible in Win32, thus adding new functions working in different ways.

转载请注明原文地址:https://www.9cbs.com/read-26637.html

New Post(0)