Adding a background image to your dialog-based application (Microsoft Visual C++ 6.0)

Though not entirely required, adding a background image can sometimes improve the look and feel of your application.

To add a background image to your dialog-based application, simply follow these simple steps:

1. Start Microsoft Visual C++ 6.0

2. Click File>New>Click the project tab then select MFC AppWizard (exe)> type the project name>Ok.

3. Select Dialog-based among the “What application would you like to create?” radio buttons>Finish.

4. Your dialog-box should now appear in the screen.

5. Click project>Add To project>Components and controls.

6. The components and gallery dialog should then come into view.

7. Double-click the Registered ActiveX Controls folder.

8. Locate and double-click Microsoft Forms 2.0 Image from the ActiveX control list.

9. A message box containing “Insert this component?” prompt with OK and Cancel button should then come into sight.

10. Click the Ok button. The Confirm classes dialog box will then appear. Displaying the class specification associated with the Image object. Click the Ok button to accept the class selections.

11. An image control will be added to the toolbox. Click the close button of the components and gallery dialog to clear your view of your dialog.

12. Click and drag the newly inserted image control from the toolbox to your dialog.

13. Resize your image control. To achieve this, click and drag the selection handles [the square around the image control]. Just make sure that it covers the whole area of your dialog box except the title bar.

14. Right-click your image control>properties.

15. Click the All tab.

16. Select the picture property then click the … button beside it. Locate and double-click the image that you wanted to assign as a background of your dialog.

17. Set the PictureSizeMode property to “stretch” so that the image size will automatically adapt and adjust to the image control size.

18. Press F5 to see the outcome of your effort.

Notice how your image acts as a background to your dialog though it’s partly a background because we just faked it. Nevertheless, it’s an easy substitute than using brushes and drawing rectangles. This trick also works on single document interfaces. In addition, you can also use Image control in adding background color; this could be done by assigning your desired color value to the backcolor property of the Image control. There are several other helpful properties of an Image control. The rest is up to you to play around.

Transferring a value to or from an MFC static text at runtime

By default, you cannot pass on a value to or from an MFC static text at runtime for the reason that it’s control ID doesn’t appear in the member variable’s tab when you activate the ClassWizard which precludes you to allocate a member variable to it. As you may know, the only way to pass a value to a control at runtime in MSVC++ is to map an instance variable to it. The following steps demonstrate how to make your static text control ID be made available in the ClassWizard ID list:


1. Add a static text control to your dialog-box by clicking on the Static text (Aa icon) and dragging it onto your dialog-box;


2. Your static text should now appear on your dialog with a default caption “Static”.



3. Right-click your static text>properties.


4.In the general tab, you will see the default ID of your Static text as IDC_STATIC.

STATIC in laypersons term means “unchanging” or “fixed” that’s why you cannot change its value at runtime. To be able to change its value, you’ll need to rename its ID from IDC_STATIC to IDC_WHATEVERDESCRIPTIVENAME, for instance IDC_NameLabel.


After changing its value from IDC_STATIC to IDC_WHATEVERDESCRIPTIVENAME, your Static text control should now appear in the ClassWizard ID lists, all you need to do is allocate a member variable to it so that you will be able to transfer a value to or from it at runtime. Same principle applies to Picturebox control.