You create a static child window control using ”static“ as the window class in the CreateWindow function. These are fairly benign child windows. They do not accept mouse or keyboard input, and they do not send WM_COMMAND messages back to the parent window. (When you move or click the mouse over a static child window, the child window traps the WM_NCHITTEST message and returns a value of HTTRANSPARENT to Windows. This causes Windows to send the same WM_NCHITTEST message to the underlying window, which is usually the parent. The parent usually passes the message to DefWindowProc, where it is converted into a client-area mouse message.)
The first six static window styles simply draw a rectangle or a frame in the client area of the child window. The three ”RECT“ static styles (left column below) are filled-in rectangles; the three ”FRAME“ styles (right column) are rectangular outlines that are not filled in:
SS_BLACKRECT | SS_BLACKFRAME | |
SS_GRAYRECT | SS_GRAYFRAME | |
SS_WHITERECT | SS_WHITEFRAME |
”BLACK,“ ”GRAY,“ and ”WHITE“ do not mean the colors are black, gray, and white. Rather, the colors are based on system colors as shown here:
Static Control | System Color |
BLACK | COLOR_WINDOWFRAME |
GRAY | COLOR_BACKGROUND |
WHITE | COLOR_WINDOW |
Most display drivers define default settings of black for COLOR_WINDOWFRAME and white for COLOR_WINDOW. (Of course, a user can change any of these colors using the Control Panel program in Windows.) The colors used in the ”RECT“ and ”FRAME“ static styles cannot be changed by trapping WM_CTLCOLOR messages. The window text field of the CreateWindow call is ignored for these styles. The upper left corner of the rectangle begins at the x position and y position coordinates relative to the parent window.
The static class also includes three text styles: SS_LEFT, SS_RIGHT, and SS_CENTER. These create left-justified, right-justified, and centered text. The text is given in the window text parameter of the CreateWindow call, and it can be changed later using SetWindowText. When the window procedure for static controls displays this text, it uses the DrawText function with DT_WORDBREAK, DT_NOCLIP, and DT_EXPANDTABS parameters. The text is wordwrapped within the rectangle of the child window. The background of these three text-style child windows is normally COLOR_WINDOW, and the text itself is COLOR_WINDOWTEXT. When you intercept WM_CTLCOLOR messages, you can change the text color by calling SetTextColor and the background color by calling SetBkColor and by returning the handle to the background brush.
Finally, the static class also includes the window styles SS_ICON and SS_USERITEM. However, these have no meaning when used as child window controls. We'll look at them again when discussing dialog boxes.