windows_programming_notes.nbk: Home | Index | Next Page: STN_CLICKED | Previous Page: SIZE


 Static Controls

Abstract

Static controls are child windows used in Microsoft® Windows™-based applications to display text, to draw frames or lines separating other controls, or to display icons. Static controls do not accept user input and do not send notification messages to their parent windows. This article describes how developers can define different types of static controls and can use text styles, frame styles, and rectangle styles to modify the appearance of these controls.

Introduction

Static controls are used to display text, to draw frames and rectangles, and to display icons. Despite the name static, the information in a static control can be changed while the control exists. For example, an application can use a static control to display the amount of disk space that it is using. A static control is a good choice for this information because the user cannot change the amount of disk space used without performing some other operation. When the user performs another operation, such as deleting a file, the application updates the amount of disk space used.

The application can change the information within a static control by sending a WM_SETTEXT message to the control. If the static control displays text, a pointer to the text must be sent in the lParam of the SendMessage function (or of the SetDlgItemText function if the control is in a dialog box). In the Microsoft® Windows™ version 3.1 graphical environment, a static control that displays an icon can change it by sending an STM_SETICON message to the control with a handle to an icon resource (HICON) in the wParam of SendMessage. An application obtains the handle to the icon by calling [LoadIcon]. Static controls that do not display text or icons have no user-supplied information to change, so a WM_SETTEXT message sent to the static control will be ignored.

Static controls might be called "no input controls" because they accept no input from the user. If the user moves the mouse over a static control, Windows sends the control a WM_NCHITTEST message. The static control returns an HTTRANSPARENT value to Windows, which then sends the WM_NCHITTEST message to the static control's parent window. As a result of this processing, the parent window of the static control receives all mouse events. Static controls do not provide any notifications to their parent windows; in other words, they do not send any WM_COMMAND messages.

Control styles for the static class include text styles, frame styles, rectangle styles, and an icon style.

Text Styles and Modifiers

The five basic text styles for static controls are:

The SS_NOPREFIX style can modify a static control that has any of these text styles. Although SS_NOPREFIX is called a style, it is really a modifier to the text styles.

or

    LTEXT   "This is Left Text with No &Prefix", 104, 33, 91, 94, 13,
         SS_NOPREFIX

Frame Styles

Static controls can be used to draw frames (boxes that are not filled). Frame-style static controls do not display text. The three frame-style static controls are:

Rectangle Styles

Static controls can be used to draw rectangles (boxes that are filled). Rectangle-style static controls do not display text. The three rectangle-style static controls are:

Icon Styles

Static controls can be used to display icons by using the SS_ICON style. Icon-style static controls are sized to fit the icon when it is displayed; the width and height that the application specifies are ignored. When defining an SS_ICON static control in a resource file, the icon must be defined elsewhere in the resource file, and the icon resource name must be specified as the text for the control. The icon name cannot be a file name. An ICON statement in a resource script file creates this static control:

    SampleIcon   ICON  sample.ico
    ICON   "SampleIcon", 104, 33, 91, 94, 13 

In Windows version 3.1, an application can change the icon displayed by an SS_ICON static control. An application can send the STM_SETICON message to an SS_ICON control with a handle to an icon (HICON) in the wParam. SendMessage returns the handle to the previously displayed icon. The Windows version 3.1 STM_GETICON message causes SendMessage to return the handle to the currently displayed icon when sent to an SS_ICON static control.


windows_programming_notes.nbk: Home | Index | Next Page: STN_CLICKED | Previous Page: SIZE


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time