Principles of Windows Programming

Source: Internet
Author: User

Here is learning Network programming encountered in the programming of Windows, a little tidying up the principles of Windows programming, by the way review.

First, understand how Windows programs work: the interrelationships between Windows applications, operating systems, and computer hardware.

The downward arrow ③ indicates that the application can notify the operating system to perform a specific action, such as the operating system can control the sound of the sound card, but it does not know when to emit what sound, need the application to tell the operating system what kind of sound. This relationship is like having a robot capable of walking, but if people do not tell it which way to go, the robot will not take the initiative to walk. The robots here are operating systems, and people are applications.

So, how does an application tell the operating system to perform a function? Readers who have had programming experience should know that in order to complete a function in the application is implemented in the form of function calls, as well, the application is also a function call to inform the operating system to perform the corresponding functions. Every special function that the operating system can accomplish usually has a function that corresponds to it, that is, the operating system provides the functions it can perform as functions to the application, and the application calls the functions called system calls. A collection of these functions is the interface that the Windows operating system provides to application programming (application Programming Interface), or Windows API. If CreateWindow is an API function that calls this function in an application, the operating system generates a corresponding window according to the parameter information provided by the function.

The UP arrow ④ indicates that the operating system is able to pass changes to the input device to the application. If a user presses a keyboard while a program is active, the operating system can immediately perceive the event and be able to know which key the user is pressing, and the operating system does not decide how to respond to the event, but instead transfers the event to the application, which the application decides how to respond to. Like a mosquito bites us, our nerve endings (equivalent to the operating system) immediately perceive this event and pass it on to our brains (the equivalent of an application), and our brains ultimately decide how to react to the event, such as driving mosquitoes away or killing mosquitoes. The process of reacting to an event is a message response.

How does the operating system pass the perceived events to the application? This is done through the message mechanism (messages). The operating system wraps each event into a struct-body msg called a message to pass to the application, see MSDN. The MSG structure is defined as follows:

typedef struct TAGMSG

{

HWND hwnd; Window handle, the identity of the storage window

UINT message;//uses an integer to represent a message

WPARAM wparam;//Indicates additional information about the message

LPARAM lparam;//Ibid. (Unsigned integral type)

DWORD time;//message was posted out of time

The structure of point pt;//, the cursor position at which the message is posted

} MSG;

About handle: Handle (HANDLE), identification of the resource. To manage and manipulate these resources, the operating system finds the corresponding resources through a handle. By type of resource, the handle can be subdivided into the handle of various types, such as the icon handle (HICON), the cursor handle (hcursor), the window handle (HWND), the application instance handle (HINSTANCE), and so on. A unique identification number specified by the operating system for each window is the window handle.

The WinMain function is the entry function for Windows programs

int WINAPI WinMain (

HINSTANCE hinstance,//handle to current instance

HINSTANCE hprevinstance,//handle to previous instance

LPSTR lpcmdline,//Command line (char* argv[])

int nCmdShow//show State);

 

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.