Getting Started with MFC (III)--MFC Picture/Text control (a small program that loops through text and pictures)

Source: Internet
Author: User
Tags bmp image

Conventions include links to the previous blogs:

Introduction to MFC (a) simple configuration: http://blog.csdn.net/zmdsjtu/article/details/52311107

Getting Started with MFC (ii) reading input characters: http://blog.csdn.net/zmdsjtu/article/details/52315088

Body///////////////////////////////////////////////////

First, create a new MFC project and habitually select the static library



Right click mfc_picture.rc Select Add resources, add the BMP image file to add to the resources, this article in order to scroll to display two pictures, so only two BMP, of course, you can also three four Zhang, in the code section to be mentioned in the later to modify.

Will default to generate two bitmap, the name of the default BITMAP1 and BITMAP2, in the Code section can be corresponding to see.



Select Bitmap Import, select all the files in the corresponding directory, select two BMP files to import.


Now we have two bitmap that we can use.

Then we build the interface as follows:

The icon of the little cactus that we haven't seen in the picture is the one we're going to use today. Bitmap control, select the left side of the toolbar to drag to the right, and then change the type in the property to the bitmap of this article, and the name renamed to Idc_show (because the default is static, there is a problem when adding the display picture variable, so you have to change it here.) )

Then right-click on the small cactus to add a variable m_show for a moment to animate the picture ~

The m_show in the picture is black because it has been added before, do not care, it is good to play up

Then is the critical code phase, double-click the Next button to drop to the specified code location, copy the code as follows:

int i = 0; Variable i is used to toggle pictures and text

void Cmfc_picturedlg::onbnclickedok ()

{

CString txt_show;

CBitmap bitmap; CBitmap object, for loading bitmaps

Hbitmap hbmp; To save a handle to a cbitmap loaded bitmap

if (i = = 0) {

Bitmap.  LoadBitmap (IDB_BITMAP1); Load bitmap idb_bitmap1 into bitmap

Txt_show. Format (_t ("What are you doing?") ")); Setdlgitemtext (Idc_edit1, txt_show);

}

if (i = = 1) {

Bitmap. LoadBitmap (IDB_BITMAP2);

Txt_show. Format (_t ("Try again.") ")); Setdlgitemtext (Idc_edit1, txt_show);

}

i++;

if (i = = 2) i = 0;

hbmp = (hbitmap) bitmap.  Getsafehandle (); Gets the handle of the bitmap loaded bitmap

M_show.    SetBitmap (hbmp); Set the picture control m_jzmpicture bitmap picture to Idb_bitmap1

}

The following two modules are the most critical:

The first is the part that shows the BMP file:

Bitmap. LoadBitmap (IDB_BITMAP1); After loading a picture

hbmp = (hbitmap) bitmap.  Getsafehandle (); Gets the handle of the bitmap loaded bitmap

M_show.   SetBitmap (hbmp); Last display of the picture to the previous variable on the newly created picture control

The second block is the text display module:

New CString txt_show;

Txt_show. Format (_t ("What are you doing?") ")); Assigning Values to Txt_show

Setdlgitemtext (Idc_edit1, txt_show); displayed on a text control with ID idc_edit1

Finally the results show ~ ~ ~//Not mental pollution


Finally I wish you a happy programming ~ ~

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.