MFC learning fragments and mfc fragments
Zookeeper
(1) dialog box in the MFC program:
MessageBox (str, _ T ("program running result"), MB_ OK); AfxMessageBox ("Hello ");
(2) MFC obtains the value of Edit Control:
CEdit * edit1, * edit2; // Add * edit1 = (CEdit *) GetDlgItem (IDC_EDIT_USERNAME) and edit2 = (CEdit *) to the values of the two controls *) getDlgItem (IDC_EDIT_PWD); // obtain the value of Edit Control: edit1-> GetWindowText (m_csName); edit2-> GetWindowText (m_csPwd); m_csName.ReleaseBuffer (); merge (); // set the value of Edit Control: edit1-> SetWindowText ("Hello! ");
(3)Socket transfer struct:
// Defines the macro of the message. It mainly defines the struct type # define MSG_TYPE_LOGIN 1 # define MSG_TYPE_LOGIN_RST 2 struct StrMsg {int m_nMsgType; // identifies the struct type. union // different structs are defined in a union. {struct Strlogin m_strLogin; struct StrloginRst m_strLoginRst ;}}; struct StrLogin {char m_szUID [20]; char m_szPWD [20] ;}; struct StrLoginRst {int m_nLoginRst ;}; // The CString csName = "HELLO"; CString csPwd = "123456"; StrMag msgToSend; msgToSend. m_nMagType = MAG_TYPE_LOGIN; // sets the Message Type memset (msgToSend. m_strLogin.m_szUID, '\ 0', 20); // initialize the character array strcpy (msgToSend. m_strLogin.m_szUID, csName); // assign memset (msgToSend) to the character array. m_strLogin.m_szPWD, '\ 0', 20); strcpy (msgToSend. m_strLogin.m_szPWD, csPwd); pSocket-> Send (& msgToSend, sizeof (StrMsg); // socket sending struct // receiving struct StrMsg * pMsg = (StrMsg *) pBuf; // force type conversion switch (pMsg-> m_nMsgType) {case MSG_TYPE_LOGIN: {StrLogin login = pMsg-> m_strLogin; // The sent struct can be used here. * you can add a handler for accessing StrLogin ******* */StrMsg msgResult; // After receiving the message, you can reply to the recipient msgResult. m_nMsgType = MSG_TYPE_LOGINRST; msgResult. m_strLoginRst.m_nLoginRst = 0; pChatSocket-> Send (& msgResult, sizeof (StrMsg); // reply message} break; case MSG_TYPE_REG: break ;}
MFC learning problems
It's enough!
To be honest, I did not contact MFC three months ago. Now I am working on a project with MFC ~
My only teaching material is the video teaching of Sun Xin's old man. This is easy to understand and there are still many others that have not been seen yet. The experts cannot calculate it, but this programming is really convenient -_-! Although it is object-oriented, the Code encapsulated at the underlying layer is not often met. It feels like a programmer is writing a program in C ~~~
First look at win32 programming, understand the message driver, this is a must, at this point, MFC is getting started. In the future, MFC will be a small case. Help me with class wizard, ctrl + w... compared with the past, you will find that MFC programming is very pleasant and you want to do everything. -_-! The younger brother just learned the MFC. In those days, I was glad to see the computer ....!
The MFC class library is huge, but there are only a few common class libraries. After learning from Sun Xin's video, you will soon be able to get started.
Www.sunxin.org/video/vc.htm video address environment VC ++ 6.0
What about books? I don't need to buy books. I want to buy books in the computer department published by Tsinghua University Press ~ The name is missing. As for the thick "VC ++ in-depth explanation", I admit that it is a good book, but it is a gray layer on my desk. I still like baidu, haha!
Note: If you want to be a master, you will learn more about the underlying code! Good luck!
How to Learn MFC
First, I learned the basic knowledge of c ++, then read the code automatically added by the system after the new mfc Program was created, and finally learned about the basic methods for each control, almost completed the entry, you can write some small programs. By the way, there are a lot of mfc function libraries on the Internet. You need to download one and then figure out the methods.
When I learned c ++, I spent a week to complete the above problems and finally wrote a simple music player.