MFC technology accumulation-based on the MFC dialog box

Source: Internet
Author: User

MFC technology accumulation-based on the MFC dialog box

1.Create dialog box class

(1)Open the VC ++ 6.0 environment and click:FileNew;

(2)In the pop-up dialog box, select:EngineeringMFC AppWizard (exe)→ InputProject name(For example, function debugging) → saving the projectPath NameOK(All other options are checked by default );

(3)In the pop-up MFC AppWizard-Step1 dialog box, select (your favorite application type ?) ClickBasic dialog box→ (Language used ?) SelectChinese→ ClickNext;

(4)In the pop-up MFC AppWizard-Step2 of 4 dialog box, select: here the default selection is basically maintained, one of the more useful isEnter the title DialogIn the edit box, enter the expected title (Function Debugging) → clickNext;

(5)In the pop-up MFC AppWizard-Step3 of 4 dialog box, select: here, one of the useful items is"UseMFC libraryOptionThen, you can keep the created. exeprogram running on the current PC. If you want to port the. exe program to another PC, you can select another program (static connection ). The hosts file is in the path.

(6)In the pop-up MFC AppWizard-Step4 of 4 dialog box, select: here you can modify the class name in some edit boxes, and then click Finish. In this example, the class name is changed to CFDlg and CFDApp.

(7)Now the dialog box class has been created. ClickCompileRun!Function debugging. ExeClick the button to run the newly created dialog box program named Function Debugging.

2.Modify dialog box title

2.1Modify the title of the Main Dialog Box

InBOOL CFDlg: OnInitDialog ()Use functions in FunctionsVoid SetWindowText ( LPCTSTR LpszString);

In the left-click dialog box, a drop-down menu is displayed. The third item of the menu does not match the title name. The modification method is as follows:

2.2Modify the dialog box title

After modifying the third item in the drop-down menu, clickMy title (& )...The dialog box appears. to modify the title of the dialog box, follow these steps:

2.3Modify message dialog box title

The AfxMessageBox function is often used as the message confirmation dialog box during program running. The application name is used by default for the title of the message dialog box generated by the AfxMessageBox function. Therefore, to modify the title of the dialog box generated by the function AfxMessageBox, you must modify the application name. The method is as follows:

Method 1: OpenString Table→ Add and edit string ResourcesAFX_IDS_APP_TITLE,

Method 2: Open MSDN to view the CWinApp ::M_pszAppNameThe Remarks translation for this topic is as follows ::M_pszAppNameSpecifies the name of the application. The Application name comes from the parameter passed by the CWinApp constructor, that isM_pszAppNameSpecifies the name, or comes from the string resource ID (AFX_IDS_APP_TITLE). If the application name is not specified in the serial resource, it will be specified by the program .exe file name.M_pszAppNameIs a public variable in the CWinApp class and the type is const char *. Therefore, in the default project, if we do not (AFX_IDS_APP_TITLE).M_pszAppNameThe Application name is the file name of cmd.exe. How to modifyM_pszAppNameTo change the application name? The method is shown in the MSDN example:

//First free the string allocated by MFC at CWinApp startup.//The string is allocated before InitInstance is called.free((void*)m_pszAppName);//Change the name of the application file.//The CWinApp destructor will free the memory.m_pszAppName=_tcsdup(_T(“my title”)); 

Copy the source code to the CFDApp constructor.

To use the message dialog box, in addition to the global function AfxMessageBox, you can also use the member function MessageBox in the CWnd class. The declaration of this function is:

IntMessageBox (LPCTSTRLpszText, LPCTSTRLpszCaption= NULL, UINTNType= MB_ OK );

LpszText:Point to a CString object or a string ending with '\ 0'. this parameter is used to display the message content.

LpszCaption:Point to a CString object or a string ending with '\ 0'. this parameter is used to display the title of the message dialog box.

NType:Indicates the type of the message dialog box. For more information about the types, see the CWnd: MessageBox topic of MSDN. Click the Message-Box Styles link to obtain the required types.

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.