An application can create a button control using an application client window as the owner. The following code fragment shows how an application can use buttons in client windows:

    #define ID_PBWINDOW 110
    HWND hwndButton,hwndClient;

    /* Create a button window. */
    hwndButton = WinCreateWindow(hwndClient,   /* Parent window  */
        WC_BUTTON,                             /* Class window   */
        "Test Button"                          /* Button text    */
        WS_VISIBLE |                           /* Visible style  */
        BS_PUSHBUTTON,                         /* Button style   */
        10, 10,                                /* x, y           */
        70, 60,                                /* cx, cy         */
        hwndClient,                            /* Owner window   */
        HWND_TOP,                              /* Top of z-order */
        ID_PBWINDOW,                           /* Identifier     */
        NULL,                                  /* Control data   */
        NULL);                                 /* parameters     */

Once created in the client window, the button control posts a WM_COMMAND message or sends a WM_CONTROL message to the client-window procedure. This window procedure should examine the message identifier to determine which button posted or sent the message.

An application that has client-window buttons can move and size the buttons when the client window receives a WM_SIZE message. An application can move and size a window by using the WinSetWindowPos function. An application can obtain a window handle for a button control by calling the WinWindowFromID function, specifying the handle of the parent window and the window identifier for each button.


[Back] [Next]