"MFC" for Dialog Program optimization and to create a chart for the program

Source: Internet
Author: User
Tags delete key

This article is based on the previous "MFC" Helloworld (click the Open link) written by the dialog box was optimized,

This time to do a better dialog box program.

I. BASIC OBJECTIVES

1. Add your own icons for this dialog box, such as:


2, is no longer only a user to click on the dialog box, and after the user click on the OK and Cancel button can be judged

For example, when a user clicks OK, a popup user clicks on a certain hint


If the user clicks Cancel, the user clicks the cancel prompt.



Second, the production process

1, first, like the "MFC" Helloworld (click on the Open link), create a simple Win32 project, and then write the following code:

Messagebox.cpp:Defines the entry point for the application.//#include "stdafx.h" int apientry WinMain (hinstance Hinsta NCE,                     hinstance hprevinstance,                     LPSTR     lpcmdline,                     int       ncmdshow) {//Todo:place code here.//above for specified action , no tube, really useful, is the following code://or the last pop-up dialog function, but the last parameter changed, mb_okcancel means to pop up a confirmation and cancel the dialog box//And this dialog box also has a question mark icon//This statement is a return value of int mbret= MessageBox (NULL, "Please click OK and Cancel", "I am your title", mb_okcancel| mb_iconquestion);//If its return value is the same as IDOK or idcancel, then the corresponding dialog box if (Mbret==idok) MessageBox (NULL, "You clicked the OK button", " I was the title that could be ignored, "mb_ok| Mb_iconexclamation); if (Mbret==idcancel) MessageBox (NULL, "You clicked the Cancel button", "I am the title that can be ignored", mb_ok| mb_iconexclamation);//The following is the specified action return 0;}
The fourth parameter of the MessageBox can also be filled with many variables, and multiple variables are represented by a bitwise OR | operator, which is the following table:

The return value of the MessageBox is the following table, which can be used to write the conditional structure according to the return value, either write the value or write the macro name

You can use this to set the dialog box you want.

The following icon is added for this program

2, file-new, in the default "File" tab, select "Resource Script", part of the VC6 is called Resourcescript, enter the file name, generally the same as the project, complete the creation


3, close the small pop-up window, and then right-click on the Resource View tab in the folder, select "Insert", and then create a new icon object, such as:



4, at this time, your work space is as follows, in the left more than a icon1, double-click to open, in the most right to draw the icon you need to


You can also right-click on the icon to select the introduction, find the system already exist icons as icons for your program,

Finish the direct compilation, run it,

Open Debug in your project folder and you can clearly see that your project is already a program with icons!



Done here, the whole program is done,

If you accidentally create more than one ICON2, you can delete it in the following way:

1, double-click this ICON2, you will find in the menu bar more "image" menu, click on the "Image" menu, choose to delete the image device


Then, in the lower left corner of the FileView page to find Icon2.ico, press the DELETE key to remove the keyboard, while finding your project folder, found in the ICON2 delete


This method is quite covert, the author looked for a long time to find.

MFC optimizes dialog box programs and creates charts for programs

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.