Drag-and-drop Stone: Everything starts from Windows Programming (4)

Source: Internet
Author: User

4 -- core functions of winodws Programming

In fact, I used the rad tool in Delphi to go to the Windows Programming path, so it was very simple to get started with windows programming. For a long time, I have never used Windows API functions in a real sense. The powerful VCL framework of Delphi shields everything. It gave me a one-sided and superficial understanding of Windows programming. I always thought that dragging several controls to write several event codes is Windows programming. Later, I saw a colleague using VC to write a program. I saw some code from the editor that I never saw before. That process caused me a burst of panic. If you are not familiar with the operating mechanism of windows, Windows programming is a tough nut to crack, in particular, I found this deficiency when I implemented multi-thread message communication programming and iocp programming.

But the most important thing is to understand the principle and how the Windows window processing mechanism works. Let's take a look at these core API functions! In those years, I often saw many people who are proficient in Windows programming in their resumes. In fact, there are several other people who are truly proficient in windows. However, a true understanding of Windows programming can be further understood through several functions, all of which are related to the operating system principles. With these functions as the starting point, you may find it easier. My new understanding of Windows begins with the solution process of my old account, and everything begins based on the status of the Windows system process. So I am very impressed with these functions.

Waitforsingleobject ()

The official explanation is: this function is used to detect the signal status of the hhandle event. When this function is called in a thread, the thread temporarily suspends. If the suspended dwmilliseconds is within milliseconds, if the waiting object of the thread changes to a signal state, the function returns immediately. If the timeout time has reached dwmilliseconds milliseconds, but the object indicated by hhandle has not become a signal state, the function returns the same result. The dwmilliseconds parameter has two special values: 0 and infinite. If the value is 0, the function returns immediately. If the value is infinite, the thread is suspended until the object indicated by hhandle changes to a signal state.

The official description is very professional, but it is easy to understand: in fact, this function is used when the wait time occurs, this function is to stop yourself, wait for the event to happen.

Gettickcount ()

The official explanation is: the number of milliseconds since the operating system was started (elapsed), and its return value is DWORD. This method is generally used for real-time control. Of course, if you think this method is not accurate enough, if you need to be more accurate, you need the queryperformancefrequency () and queryperformancecounter () Methods of Q, this method is applicable to the data needed for CPU conversion.

Finally, the sleep () method is used to sleep the current thread, which is also the suspension we usually talk about. In thread encoding, this method is frequently used, especially in loops. My reflection on what I learned begins with this small sleep. On the way to technology R & D, you may think that everything is very simple, but it is so simple that you sometimes cannot do anything.

(To be continued .........)

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.