Visual C ++MFC Guide (4): Brief Guide

zhaozj2021-02-11  139

Visual C / MFC Guide Fourth Lesson: MFC Brief Guide

Already ready to start writing procedures? No, not yet. Don't say you want to teach you to write a stupid 'Hello World' program. If you want to use Visual C , you will have Microsoft Foundation Classes (MFC). These classes are very good, it contains all our benefits that we discussed in the second lesson. The most important thing for you is now the CWND class. It encapsulates those functions that require window handles. Remember the PostMessage function I have mentioned?

Postmessage (Your_hWnd, WM_Paint, 0, 0);

Now we can have a window class and call the member function:

MycWnd.PostMessage (wm_paint, 0, 0);

This statement has done the same thing, we don't have to care about the window handle. But don't be cheated, they are still there, we are still using them. They are now only a member variable of class. There is a window handle m_hwnd in the CWND class. We are now calling old send message functions:

:: PostMessage (mycwnd.m_hwnd, wm_paint, 0, 0);

Two colons (: :) used to tell MFC we call the old version of the function. Usually you don't need to use this, but I am confused when you say that you see other code.

The CWND class is some other class base class. Like CButton and CDIALOG, with interpretive names. You can also access the window handle from CButton. (You will surprise how much things in Windows .. Rolling Bar, Edit Box, Tree Window, Desktop ....).

Another important class is a CWINAPP class, although you will not use it in the future. This class is the backbone of the MFC, which has made a lot of hard work behind the scenes. Each of your programs has a CWINAPP object. When it is built, the program will start running. The main function called when the CWINAPP object is created is initInstance (). In this function, your program is established and started. You can think that initInstance () is very similar to the main () function in c.

Let us finally look at a class in MFC, you will definitely use: CString class. This is one of Microsoft's support, which is used to simplify the operation of the string. The CSTRING class has heavy loaded most commonly used operators, such as = and , where do you use this:

Cstring strmystring;

Strmystring = "May the force be with you";

Strmystring = "Young jedi."

Printf ("% s", strmystring;

// Output Will Be "May the force be with you";

(7 of the original tutorials, the top four is not bad, I feel that the author has a little experience in the method of beginner VC, the last three talks about the dialog file, it is better to see the textbooks everywhere, will not continue Babyman.

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

New Post(0)