MFC technology accumulation--the things that are based on MFC dialog box classes

Source: Internet
Author: User

1. Create a dialog box class

(1) Open vc++6.0 Environment, click: filenew ;

(2) in the Popup New dialog box, select: projectMFC AppWizard (exe)→ enter project name (ex: function debugging) → Project Save path nameOK (all other tick options are default);

(3) in the MFC Appwizard-step1 dialog box that pops up, select: (What type of application do you like to create?) Click the Basic dialog → (use language?) Select Chinese → Click next ;

(4) in the pop-up MFC APPWIZARD-STEP2 of 4 dialog box select: Here basically keep the default selection, the more useful one is to enter the title dialog , in the edit box to enter the title you want (Function debugging) → Click next ;

(5) in the popup MFC APPWIZARD-STEP3 of 4 dialog box, select: Here is a useful one is " using the MFC library options ", You can leave the default option for creating a generated. exe program to run on this PC, and you can tick another item (that is, a static connection) if you want to port the. exe to a different PC. Of course, if the project has been established according to the default option, it is generally possible to run across the PC under the Windows system, and if the program cannot run and you are prompted not to find some. dll files, simply copy the required. dll files to the same path as the. exe file.

(6) in the pop-up MFC APPWIZARD-STEP4 of 4 dialog box, select: Here you can modify the class name in some edit boxes, then click Done, the class name in this case to Cfdlg, Cfdapp.

(7) The system completes the creation of the dialog box class, click compileexecute ! Functional Commissioning . exe button to run the newly created dialog box, with the dialog caption named function debugging

2. Modify the dialog box title

2.1 Modify the main dialog box title

Use the function void setwindowtext ( lpctstr ) in the BOOL Cfdlg::oninitdialog () function Lpszstring );

Left click the dialog box icon pop-up drop-down menu, found that the third item of the menu and the title name does not match, modify the method as follows:

2.2 Modify the title of the dialog box

When the third name of the drop-down menu is modified, click About "my title (&a)..." Pop-up about the dialog box, if you want to modify the title of the dialog box, the method is as follows:

2.3 Modify Message dialog box title

A message dialog box that is often used as a afxmessagebox function in the run of a program, and the name of the message dialog box generated by the AfxMessageBox function is used by default. Therefore, the title method of modifying the dialog box generated by the function AfxMessageBox is to modify the application program name. Here's how:

The first method: Open string Table→ add and edit string resource Afx_ids_app_title,

The second method: Open MSDN View CWinApp:: m_pszappname topic, remarks translation of the topic is as follows, CWINAPP:: m_pszappname The specifies the name of the application. The application name comes from a parameter passed by the CWinApp constructor, specifying a name for M_pszappname , or from a string resource ID ( afx_ids_app_title ). If the application name is not specified in the string resource, it is specified by the program. exe file name. M_pszappname is a public variable in the CWinApp class, and the type is const char*. Therefore, in project engineering that is established by default, if we do not edit the string resource ID ( afx_ids_app_title ) and do not modify m_pszappname , Then the application name defaults to the. exe file name. How do I change the application name by modifying the M_pszappname ? method as 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 would free the memory.

Copy the above source code into the Cfdapp constructor.

Of course you want to use a message dialog box in addition to the global function AfxMessageBox, you can also use the member function MessageBox in the class CWnd, which declares:

int MessageBox (LPCTSTR lpszText, lpctstr lpszcaption = NULL, UINT nType = MB_OK);

LpszText : point to a CString object or a string that ends with '/', which is used to display the message content.

lpszcaption : A string that points to an CString object or to the end of ' \ \ ', which is used to display the caption of the message dialog box.

nType: represents the type of message dialog box. Specifically want what type by looking at the MSDN Cwnd::messagebox theme, click on the link Message-box styles to get the desired type.

MFC technology accumulation--the things that are based on MFC dialog box classes

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.