Summary of MFC

Source: Internet
Author: User

1. Project Creation
When you create a project with Win32. Want to use MFC's way. Just change one place.


2. Change the entry function (provided that you handle those functions before the main function yourself)


3. Creating MFC is typically based on a dialog box

4. The default generated macro description.

 Here is the generated type corresponding to the Idd_mfcapplication1_dialog resource Idcmfcapplication1dlg::cmfcapplication1dlg (cwnd* pparent/*=NULL*/): CDialogEx (Idd_mfcapplication1_dialog, pparent) {m_hicon = AfxGetApp ()->loadicon (IDR_MAINFRAME);} This macro represents the binding resource void Cmfcapplication1dlg::D odataexchange (cdataexchange* pdx) {cdialogex::D odataexchange (PDX);} These macros correspond to events corresponding to the event in this binding Begin_message_map (Cmfcapplication1dlg, CDialogEx) On_wm_syscommand () On_wm_paint () on_wm_query DragIcon () End_message_map ()//Dialog initialization function in general here do the corresponding initialization of bool Cmfcapplication1dlg::oninitdialog () {Cdialogex::o    Ninitdialog ();    Add the "About ..." menu item to the System menu.    Idm_aboutbox must be within the scope of the system command.    ASSERT ((Idm_aboutbox & 0xfff0) = = Idm_aboutbox);    ASSERT (Idm_aboutbox < 0xf000);    cmenu* Psysmenu = GetSystemMenu (FALSE);        if (psysmenu! = NULL) {BOOL bnamevalid;        CString Straboutmenu;        Bnamevalid = straboutmenu.loadstring (Ids_aboutbox);        ASSERT (Bnamevalid); if (!straboutmenu.isempty ()) {psysmenu-&Gt            AppendMenu (Mf_separator);        Psysmenu->appendmenu (mf_string, Idm_aboutbox, Straboutmenu);  }}//Set the icon for this dialog box.         When the application main window is not a dialog box, the framework automatically//performs this operation SetIcon (M_hicon, TRUE);        Set Large icon SetIcon (M_hicon, FALSE);  Set small icon//TODO: Add extra initialization code here to return TRUE; Returns TRUE unless focus is set to the control

5. Toolbox

6. View the Code

7. Resource View (view resource ID, etc.)

8. View

9. Use of controls

10. Properties of the control

11. Response Events for controls

12. Add to parent window here to note that there is currently no bound control just add the event click No use

Only events are bound (only if you want the event)

13. Binding Controls

Hook control variable ID to select the

This is really binding and automatically initializing the control to you at the same time (this can be understood as the initialization of the control)

 void CMFCApplication1Dlg::DoDataExchange(CDataExchange* pDX){    CDialogEx::DoDataExchange(pDX);    DDX_Control(pDX, IDC_BUTTON1, mybtn);}


If you want to put the control also generated class can also right click here Control do not use Add class because the inheriting class is incomplete

Use the Class wizard don't make a mistake. MFC class

Select base class click on a

Generating classes

There's a hole in here. Because your parent window has been added to add this control as a variable. At the same time you now have the control generated class so you have to manually change the

 包含头文件  改变量名

It is important to remember which control generated the class because MFC does not know what control added the generic naming to distinguish the other ways to add controls here.

Some controls cannot be added so that only code is written

Like this, you can only add it yourself.

http://blog.51cto.com/haidragon/20878401. 新建2. 在想要添加这个控件的类里包含对应的控件头文件3. 声名一个变量4. 父窗口在初始化函数初始化控件用 create(this)等5.同时要加上对应的显示函数 如:toolbarRepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);

Use of the control remember:
1. Display properties that are not what you want to see property changes
2. Different controls have a fixed usage in MFC like radio is relatively low
3. Different controls initialize different like toolbar and finally a god-like operation.
4. View ID There is no MFC very sore place is sometimes not help you add ID in the resource file also not.
5. Check that the ID is not repeated this has to say MFC God-like operation.
6. Check if ID is not the default generated ID it is possible that this ID was used like the image ID of the MFC project already has that ID. However, MFC still generates that ID by default.
7. Check two important macros
8. Do not appear in the control's constructor to regulate the widget. Because none of the initializations are initialized this is null like this-> Will go wrong.
9. There is no function to invoke the control's own implementation. It is possible that the control generated the class without changing it in the parent window. Instead, use the default.

Summary of MFC

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.