[VC ++ entry] enters the Hall of VC ++

Source: Internet
Author: User
Sometimes I need to use VC ++ for a small software, but I can only learn from new ones if I have never used it! Someone once said: "A lazy person learns VB, a smart person learns Delphi, and a real programmer learns VC ." Once I learned VB, I was too lazy, but I gave up learning C # in the middle. Now I feel that sometimes I have to make a small software, and not all computers are equipped with it. net Framework, for a program of several hundred K will also be.. NET Framework packaging, people who do not know the program can not be scared to death. Therefore, it is necessary to learn C ++. What's more, I want to enter the gaming industry? Too many! In fact, I can make up my mind to learn this. I also want to know how Windows has done it!

I read c ++ books for the first time. In the past, I went to ASP with my whole heart because I only liked to be a website. net (C #), here is just a note, there is nothing special, recording the following small things in life, it is also the beginning of the second advanced language, because VB has forgotten. Don't mention the C language for university studies. Haha, the script should not be counted. Let's get started, fighting!

In Windows, windows are marked with Windows handles (hwnd). That is to say, each window has a window handle and is unique. This should be related to memory allocation; of course, to operate a window, first obtain the handle of the window. Handle is an important concept in a Windows program and is frequently used. In a Windows program, there are various resources (Windows, icons, cursors, and so on). The system allocates memory for these resources and returns the ID number that identifies them, handle. In the following content, we will also see the icon handle (hicon), the cursor handle (hcursor) and the paint brush handle (hbrush ).

Message: This term is often heard, but I have never really known or applied it to Western Europe! In C ++, messages are expressed in the MSG structure:
 

1 typedef struct tagmsg {
2
3 hwnd;
4
5 uint message;
6
7 wparam;
8
9 lparam;
10
11 DWORD time;
12
13 point pt;
14
15} MSG;

The first member variable hwnd indicates the window to which the message belongs. The programs we usually develop are window applications, and a message is generally associated with a window. For example, if you press the left mouse button in an active window, the generated key message is sent to the window. In Windows, the hwnd type variables are used to identify the window.

The second member variable message specifies the message identifier. In Windows, messages are represented by a number. Different messages correspond to different values. However, because the values are not easy to remember, Windows defines the value of the message as the form of the wm_xxx macro (WM is the abbreviation of window message). xxx indicates the English spelling of a message in uppercase. For example, the left-click message is wm_lbuttondown, the keyboard press message is wm_keydown, and the character message is wm_char. In programs, we usually use messages in the form of a wm_xxx macro.

The third and fourth member variables wparam and lparam are used to specify additional message information. For example, when we receive a character message, the value of the message member variable is wm_char, But what character is entered by the user, it is described by wparam and lparam. The information represented by wparam and lparam varies with the message.

The last two variables indicate the time when the message is delivered to the message queue and the current cursor position.

Message Queue: Of course, messages must be queued. It should be in the order of CPU execution programs. Different queues have different execution orders! However, not all messages need to be queued up. Messages in Windows programs can be divided into "incoming messages" and "no incoming messages ". The system puts incoming messages into the application's message queue, and then the application extracts and sends them. Messages that do not enter the queue are directly sent to the window during the system call window. The system calls the window process function to process the message, whether it is a forward message or a non-Forward message.

Finally, let's take a look at the entry function of the program as the end of our class, because it's about to go to work!

1 int winapi winmain (
2
3 hinstance, // handle to current instance
4
5 hinstance hprevinstance, // handle to previous instance
6
7 lpstr lpcmdline, // command line
8
9 int ncmdshow // show state
10
11 );

The first hinstance parameter indicates the handle of the Instance currently running the program, which is a numerical value. When a program runs in Windows, it uniquely identifies the running instance (note that only the running program instance has an instance handle ). An application can run multiple instances. Each time an instance is run, the system will assign a handle value to the instance and pass it to the winmain function through the hinstance parameter.

The second parameter hprevinstance indicates the handle of the previous instance of the current instance. By viewing msdn, we can know that in Win32 environment, this parameter is always null, that is, in Win32 environment, this parameter no longer works.


The third parameter, lpcmdline, is a null termination string that specifies the command line parameter passed to the application.

The fourth parameter ncmdshow specifies how the window of the program should be displayed, such as maximization, minimization, and hiding. The value of this parameter is specified by the caller of the program. Generally, the application does not need to ignore the value of this parameter.

Learning is a process, but I believe that I have C # as my back-to-earth, and I am very confident in C ++ learning. Although I can't take it all at once, I am working hard! OK. I went to work every day. I should be able to use it!

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.