Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Creating a button

The button widget is a decorator widget. The button created by c_simple_widget_app_1_0 decorates a static widget. The button is created as follows, in c_simple_widget_app_CreateButton():

  1. Call ISHELL_CreateInstance() to create the button widget:
    if (AEE_SUCCESS != ISHELL_CreateInstance(pMe->piShell,
                AEECLSID_CButtonWidget, (void **)&pMe->piwButton)) {
        pMe->piwButton = NULL;
        return FALSE;
    }
  2. Set the extent and properties for the button.

    The width and height of the button are specified in a WidgetExtent structure, which is required when calling IWidget_SetExtent().

    // set the extent for the button
    we.width = 38;
    we.height = 32;
    IWidget_SetExtent(pMe->piwButton, &we);
    
    // set properties
    (void) IWidget_SetBGColor(pMe->piwButton, RGB_WHITE);
    (void) IWidget_SetGradientStyle(pMe->piwButton, GRADIENT_STYLE_NONE);
    (void) IWidget_SetBorderStyle(pMe->piwButton, BORDERSTYLE_ROUNDED);
    (void) IWidget_SetBorderColor(pMe->piwButton, RGB_BLACK);
    (void) IWidget_SetBorderWidth(pMe->piwButton, 1);

    Note: To have the background color of the widget be a solid color, instead of a gradient, the gradient style must be set to none by calling IWidget_SetGradientStyle();

  3. Create a static widget and call c_simple_widget_app_SetText() to set the text for the static widget:
    if (AEE_SUCCESS != ISHELL_CreateInstance(pMe->piShell,
                AEECLSID_CStaticWidget, (void **)&piwStatic)) {
        return FALSE;
    }
    
    // specify text for the static widget
    if (!c_simple_widget_app_SetText(piwStatic, BUTTONTEXT)) {
        return FALSE;
    }

    c_simple_widget_app_SetText() gets the model for the static widget and then sets the value of the static widget (the text), as follows:

    // get the value model for the static widget
    nErr = IWidget_GetModel(piWidget, AEEIID_IValueModel,
                (IModel**)(void*)&pValModel);
    
    if (AEE_SUCCESS == nErr) {
        // set the value of the static widget to the desired text
        IValueModel_SetValue(pValModel, (void*)pwszText,
                WSTRLEN(pwszText), NULL);
    
        // release the value model since it's no longer needed
        (void) IValueModel_Release(pValModel);
    }
  4. Set the button widget on the static widget:
    IDecorator_SetWidget((IDecorator *)(void*) pMe->piwButton,
                piwStatic);