Introduction to the Picture Control
|
|
|
A static control is an object that displays information
to the user without his direct intervention. A static control can be used to
display text, a geometric shape, or a picture such as an icon, a bitmap, or
an animation. Normally, a user cannot change the value of a static control.
For example, if a static control displays text, the user cannot directly
change it.
|
In the same way, if a static control is used to show a
picture, the user cannot inherently change the picture.
One of the most common static controls used in MFC is
the picture control.
Creating a Picture Control
|
|
To create a picture control, in the Toolbox, click the
Picture button
and click the dialog box. To programmatically create a static control,
declare a pointer to CStatic using the new
operator. Then call its Create() member function to
initialize it.
Practical
Learning: Introducing the Picture Control
|
|
-
Start Microsoft Visual Studio
-
To create a new application, in the main menu,
click File -> New Project...
-
In the left list, click Visual C++. In the right
list, click MFC Application
-
Change the Name to PictureViewer1
-
Click OK
-
Enlarge the dialog box and keep its buttons to the
lower-right section
Characteristics of a Picture Control
|
|
To create a static control, the MFC library provides
the CStatic class. Like any other control, there are
various ways you can create this control. During design, you can add a
Picture control to a form or a dialog box:
The Picture control is the most classic static control
of the MFC library. To exploit a static control, you can manipulate some
of its characteristics. These characteristics are referred to as its
styles.
You can surround the borders of the control with a
black, a gray or a white color. During design, specify the Type as Frame
and set the color accordingly using the Color combo box:
These characteristics are set as SS_BLACKFRAME,
SS_GRAYFRAME, and SS_WHITEFRAME
respectively.
You can fill the control with either a black, a gray,
or a white color. At design time, set the Type combo box to Rectangle and
select one of these colors in the Color combo box:
These characteristics are based on the
SS_BLACKRECT, SS_GRAYRECT, and
SS_WHITERECT values respectively.