Multiple methods of displaying images in dialogs (on)

zhaozj2021-02-16  61

Let's start with your simple start. First a class:

(1) Non-dynamometer display (ie, the picture is loaded through the resource manager, there is a fixed ID)

(2) Dynamically loaded pictures (ie, only need to specify the path to specify the image in the program, can be loaded)

For convenience, we have built a dialog-based project called TTest.

Dialog box class ctestdlg

(1) Non-dynamically loaded pictures.

Method 1. First from the simplest start, use the Picture control.

step:

First in the resource, IMPORT, ID is IDB_BITMAP2

Then add a Picture control on the dialog, right-click Open Properties,

Select bitmap in the Type drop-down box, follow the following, an Image drop-down box appears.

Pull open, you will see all the pictures already loaded.

Select the picture you want. You can see it when running the program.

Method 2. By background diagram

Also as above, first load a picture, ID is IDB_bitmap2

Testdlg.h

CBRUSH M_BRBK; // Definition in public

Testdlg.cpp

Add: in the initialization function onInitdialog ():

Bool ctestdlg :: oninitdialog ()

{

CDIALOG :: OnInitdialog ();

CBITMAP BMP;

Bmp.LoadBitmap (IDB_bitmap2);

M_BrBk.createPatternbrush (& BMP);

bmp.deleteObject ();

.

.

.

Return True; // Return True UnsS you set the focus to a control

}

In the open class wizard, find the WM_CTLCOLOR message, and then load the corresponding function onctlcolor (), add as follows:

Hbrush ctestdlg :: onCTLCOLOR (CDC * PDC, CWND * PWND, UINT NCTLCOLOR)

{

Hbrush Hbr = CDIALOG :: ONCTLCOLOR (PDC, PWND, NCTLCOLOR);

IF (PWND == this)

{

Return M_BRBK;

}

Return Hbr;

}

(2) Dynamic loading pictures.

Method 3 Image Control (this example uses KODAK image editing controls)

1. First, this control should be guaranteed. Note that it cannot be used alone, must be used with several other controls (especially imgcmn.dll). If not, you can come from other machines. These files are imgadmin.ocx, imgcmn.dll, imgedit.ocx, imgscan.ocx, imgshl.dll, imgthumb.ocx, imigutil.dll, put them in a Windows / System directory, then use regsvr32.exe to use them Register separately.

2. Open the project, enter the resource manager, right-click on the dialog box, click Insert ActiveX Control ... Select the Kodak image editing control, the size is arbitrary.

3. Select the control on the dialog to add variables: m_ctrlpicture. .

4. Add the following: OnInitDialog :: OnNitDialog () as follows:

Bool ctestdlg :: oninitdialog ()

{

CDIALOG :: OnInitdialog ();

m_ctrlpicture.setImage ("aa.jpg"); // guarantees that the image can also write an absolute path in the project directory.

m_cTrlPicture.disPlay ();

.

;

;

Return True; // Return True UnsS you set the focus to a control

// Exception: OCX Property Pages SHOULD RETURN FALSE}

The compilation operation is OK. The advantage of this method is that it is possible to make a variety of image formats.

The above four ways only Kodak can support multiple images, and other support BMP

If the reader is interested, you can ask all the routines of the above methods.

Mailbox: zhucde@jxfw.com

At the recommendation of the majority of friends, all routines are packaged, and the following is available for download:

http://www.7forever.com/c3d/study/pictest.rar

Among them, the program directly plotted is a dialog, it is adaptive to the picture size, not the static adaptive size in the article.

转载请注明原文地址:https://www.9cbs.com/read-23336.html

New Post(0)