Chapter III-windows Procedures

Source: Internet
Author: User

This chapter I do not know how to write, hehe ~ ~
After all, Win32 is a very esoteric system, but I am not allowed to this kind of junior here judge, but I am to write to those who are in the entry stage of the friends to see, and not to those who do programming veteran see, So, I do not need to be afraid of being accused of the name of this chapter called " Windows program instead of Windows programming so, I'm just talking about how Windows programs work:
Why Windows is called Windows, believe that all used friends can understand, the desktop of a window, is the origin of its name. That is, the appearance of one window after another, so that the use of the computer suddenly a lot easier. A few years ago, friends who have contacted the computer must know DOS bar, do not know, to ask for the download version of the moderator old brother, let him explain you also remember the DOS under the Black window bar, have not seen the Buddies can find out in the Start menu to see. DOS through a series of commands to do the corresponding operation, such as entering a directory, delete a directory, and so on. The way you work is called the command prompt, which is the command line.
Now the people in the country do not understand the computer is still old Love said to want to learn computer, must be English clearance. (That's it, scaring off a few friends who just want to learn some basic things) may be the reason for the DOS.
Later, with the support of hardware and technical improvement, of course, there are also to make the computer more convenient service and people, and slowly have the so-called view operating system, from now on, you do not have to remember those large piles of instructions, and operation, there is a big improvement, you can say that the operating system developed to today, The operation has been simple enough, to see those in the Internet cafes a little snot of the children ...
Of course, like the dos of the command prompt line, today's windows is still the same as that of the year, occupying most of the user base.
(Out of the field: An audience throws a rotten persimmon, you are Tang's monk ah, so much nonsense)
Immediately to the point, Windows is easy to use, in addition to not back more than n commands, one reason is because it itself provides a large number of standard Windows GUI functions. So for users, the same set of standard Windows, the operation of these windows are the same, so the use of different applications without re-learning operations. Do not like in the same year under DOS as the installation of new programs, it is necessary to see the help immediately, see the instructions.
Windows GUI functions, however, are only a small part of the API (application programming Interface application programming Interface) that Microsoft provides to developers of programs. Windows API is a large set of powerful functions that are themselves stationed in Windows for people to call at any time. Most of these functions are contained in several dynamic-link libraries (DLLs), such as Kernel32.dll, User32.dll, and Gdi32.dll. The functions in Kernel32.dll mainly handle the memory management and process scheduling, the functions in User32.dll mainly control the user interface, and the functions in Gdi32.dll are responsible for the operation of graphics and so on.
You may have heard more or less about API functions, and if you don't know exactly what's going on, I'll try to explain it to you clearly.
I wonder if you ever thought about how the window in Windows was drawn again? Oh, you may use VB, Delphi program, you have not thought of the program you write how those windows are formed? Is the control's turn. Pour ... Oh, I believe you learned VB or Delphi when, the book read must be a visual programming environment to praise A, is not also mentioned more than VC how convenient? How not to spend a lot of useless time to build the interface of the program and so on.
(Taiwan down a northeast migrant workers: Boy, you look for smoke ah, also talk about it)
Immediately came David, actually I just want to tell you, all you use the windows of the program, all by calling one after another Windows API to perform the corresponding task, no API, your program can do nothing. With VB, Delphi and MFC friends may say I did not call what API Ah! In fact, these APIs are automatically converted by the development environment you use. For example, you use Delphi to create a new program, nothing to move directly press F9 to run it, is there a blank form? This is a standard Windows program, it has all the characteristics of Windows programs, such as Maximize button, minimize button, Close button ... You can move it with the mouse.
But if you want to use VC + + or MASM32 to write such a program, then you have two ways, in VC + +, you can use MFC or directly invoke the API, and in MASM32, you only call the API directly. The so-called direct call API means that all operations are done through the most primitive APIs. By invoking the API directly to generate such a program, you must first register the window class (unless you use Windows predefined window classes, such as the MessageBox or dialog box), then generate the window, and then display the window on the desktop (unless you do not want to display it immediately); Then refresh the window client area;
Trouble, if you want to really let the program to run properly, but also to add the following steps:
1. You want to get a handle to your application. 2. When the form is displayed, it enters the infinite loop that gets the window message. 3. If a message arrives, it is handled by the window callback function responsible for the window. 4. If the user closes the window, exit processing.
Above this step, we need to call the appropriate API to complete. For example, get the handle of the program with GetModuleHandle Register window class with RegisterClass or RegisterClassEx, after registering, also use CreateWindowEx function to generate the corresponding window, and then use ShowWindow to display it , and then use UpdateWindow to update the customer area and so on. None of this counts, and if you really write a slightly larger program by calling the API directly, you'll find that's a very unpleasant thing to do.
These are just a small little tiny little bit of the API ... part, this is just a few, there are hundreds of real APIs, including operations on all aspects of the system. Without the API, your program can do nothing. For example, your program has an edit control, VB should be called the text control, you want to put the user input into a variable in the information, then Delphi can be implemented with Str:=edit1.text. VB should be str=text1.text, but if you use the API, want to get the text content of the edit input box, it is necessary to call Getdlgitemint (the value entered in the edit as a value) GetDlgItemText, Getdlgitemtexta (the value entered in edit is used as a string). And the above I said VB, Delphi to get the input content of the edit box method, and eventually compiled into an executable file, it will be automatically converted by the compiler. You just need to understand one thing, that is the program you use, all the way to invoke the system in the various API functions.
In fact, the API in Windows is equivalent to the system function calls in the current DOS system, and interrupts 21. Only in quantitative and functional, is not the DOS system function calls.
If you still can not understand, then I do not blame you, may be I speak unclear, so, or give you recommend Lao Niu write book. Push "Windows Programming", you will see after the internal force greatly increased, then you know the knowledge is more than the API.
In fact, I did not teach you to program this article, so about the principle of Windows program, there is no need to say so much, I tell you the API, is to let you know the Windows program running mechanism. No time to use the debugger when the breakpoint when asked what is the API. (The crowd (very angrily) rushed to the station: "Pull down pk! What do we think we are! ”)
(I came to the stage again, the lens cut to the side of the face, a close-up.) I can see that there are several wounds of different sizes and there may be some areas of focus I did not mention, please correct me. If you have something that you do not understand, welcome keep abreast to ask questions. Just not too much, say, "Can you list all the APIs for me to go back to my back?" ”
Attach a few common API functions. I believe you have a general understanding of the API at this time.
MessageBox displays a message dialog box
Messageboxex Display a message dialog box
Messageboxindirect Display a Certain Information dialog box
(above these three, can be used to interrupt those error prompts, such as your registration code input error, the program may pass through one of these functions, to prompt you for error)
Getdlgitemint to specify an integer value for the input box
GetDlgItemText to specify input box input string
Getdlgitemtexta to specify input box input string
(The software can use these three to get the user entered the registration code)
Getlocaltime Current local time
GetSystemTime Current system time
(software can use these two to determine whether the software expires)
Regqueryvaluea gets the setting value of an item
Regqueryvalueexa gets the setting value of an item
Regsetvaluea setting the value of the specified item or subkey
Regsetvalueexa setting the value of the specified item
(These may be useful if the software uses the registry to store registration information)
Above, just a few more common, see the previous tutorials or the Windows Developer Manual.
Finally, we're going to introduce a heavyweight function, you probably don't know what the API is, but you just have to use the debugger and you'll know its name. You may not know who the current President of the United States is, but you must know this function. Although I know that the current President of the United States is Powell, I also know who this function is.
It's----ng man tat! (Director: NG) to say again. It is hmemcpy.
What is this function for?
It is a very simple function. Just one very, very basic task is to copy data from one place to another. The application itself does not invoke it, for the simple reason that it is low (assembly: Who dares to say the same as me?) )。 However, most API functions call it very frequently. So, it is also called the Universal function. You probably don't know anything about this at ordinary times, but it's very useful to break the program. But at present to the 2K with XP, but there is no such function, and it is a function called memcpy, although the function of the same, but basically is a wreck of the total know, you use memcpy simply can not cut anything. Therefore, such a function can only be used under 98. This is like the President of the United States, so that it can only make eight years, not to mention it. Maybe I'll kick him off next year.
I don't have much to say about anything else, this chapter you know what the API is.
If you feel there is something wrong or something wrong, and want to civilization a little surface generation, please in reply. If you want to be savage, throw the eggs at your monitor.
< end of this chapter >

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.