The following code example shows how to specify the placement and size of a label control.
IDF_MAIN DIALOGEX DISCARDABLE 0, 0, 0, 0 // Full display
CAPTION "My Form"
STYLE WS_VISIBLE
BEGIN
// Because they are specified by constraints, the position and
// dimensions in the CONTROL statement are left as zero.
CONTROL "Hello", IDC_CTRL,"APC_Label",ASFC_ALIGN_LEFT,
0,0,0,0
BEGIN
// Use the following constraints.
FA_TOP_OF_FORM, // Aligns the top edge of the control with
// the top edge of the form.
FA_LEFT_OF_FORM, // Aligns the left edge of the control with
// the left edge of the form.
FA_RIGHT_OF_FORM, // Aligns the right edge of the control with
// right of the form.
FA_BOTTOM_OF_FORM // Aligns the bottom edge of the control
// with the bottom edge of the form.
END
END
The constraints in this example define a label control that fills the form. For forms with title bars, the top of the form is directly under the title bar. If not enough constraints are specified so that each edge can be determined, the natural size of the control is considered. The natural size of a control typically consists of the dimensions a control would need to display its contents. For example, the natural size of a label control with a ASFC_ALIGN_SINGLELINE format is the width required to display the control’s full caption.
When using a control that does not have a natural size — for example, a multiline control — you must provide the constraints necessary to determine all the edges.
The following code example shows how to specify a label control using natural size.
CONTROL "Hello",
IDC_CTRL,"APC_Label",ASFC_ALIGN_LEFT|ASFC_ALIGN_SINGLELINE, 0,0,0,0
BEGIN
// Use the following constraints.
FA_TOP_OF_FORM, // Align the top edge of the control with the
// top edge of the form.
FA_LEFT_OF_FORM, // Align the left edge of the control with
// the left edge of the form.
END
In this example, the control’s natural size is used to specify the dimensions of the control. The net effect is that a label control is created in the upper-left corner of the form and is just large enough to display its caption, “Hello.” It is important to realize that constraints are applied at the time you call LoadFormResource and not each time a control position or caption is changed. If your application has to change the caption at runtime, add another constraint, such as FA_RIGHT_OF_FORM.
In addition to label controls, glyph, tabber and edit controls also support natural sizes. Tabber and edit controls are subject to the following rules:
For more information about controls, see “Using Auto PC Simple Controls.”