The operating system provides the following three ways to create custom control windows:

List boxes and menus can have an ownerdraw style, and buttons can have a user-button style, which cause the system to send a message to the owner of the ownerdraw control whenever the control must be drawn. (If the owner is a frame window, it sends these messages on to its client windows for handling by the client window procedure.) This feature lets an application alter the appearance of a control window. For menus and list boxes, the owner window draws the items within the control, and the system draws the outline of the control. For buttons, the user-button style affects the drawing of the entire control. Subclassing an existing control window is an easy way to create a custom control. The subclass procedure can alter selected behavior of the control window by processing only those messages that affect the selected behaviors. All other messages pass to the original control-window procedure.

The techniques for defining a custom control-window class are the same as those used for creating a client-window class. When you create a custom control-window class, be sure the window procedure can send and receive the messages listed in the two tables following this section.

If an application creates a private control-window class, the name of the private class could be used in the dialog template, just like a predefined window-class constant. For example, if an application defines and registers a window class called "MyControlClass", it could create a dialog window that contains that type of control window by using the following resource definition:

    DLGTEMPLATE IDD_CUSTOM_TEST
    BEGIN
    DIALOG "", IDD_CUSTOM_TEST, 1, 1, 126, 130, FS_DLGBORDER, 0
    BEGIN
        CONTROL "This is Text", IDD_TITLE,
              37, 107, 56, 12,
              WC_STATIC,
              SS_TEXT | DT_CENTER | DT_TOP | DT_WORDBREAK
              | WS_VISIBLE
        CONTROL "Custom Control", IDD_CUSTOM,
              33, 68, 64, 13,
              "MyControlClass",
              WS_VISIBLE
        CONTROL "Okay", DID_OK,
              57, 10, 24, 14,
              WC_BUTTON,
              BS_PUSHBUTTON | BS_DEFAULT | WS_TABSTOP | WS_VISIBLE
        END
    END


[Back] [Next]