Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 16: Text-Based Controls Visual C++ and MFC Fundamentals


15.1 Static Controls..............................................................................................


15.1.1..Introduction..........................................................................................


A static control is an object that displays information to the user without his or her 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.

Visual C++ (along with MFC) offers various types of static controls: the Picture control,
the Static Text control, and the Group Box control. In the strict sense of the current
context, to add a static control to your application, from the Controls toolbox, click the

Picture button and click the parent. To programmatically create a static control,
declare a pointer to CStatic using the new operator. Then call its Create() method to
initialize it.

15.1.2..Static Control Properties....................................................................


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 style. The styles applicable on a static control are:
Free download pdf