Resources | Resources |



Creating a title widget

A title widget is a decorator that displays text above the widget it decorates. The text of the title widget is a static widget. To set the text of this title widget, the application needs to get the underlying static widget for the title widget.

In c_simple_widget_app_1_0, the title widget decorates a separate static widget.

All of this is accomplished as follows, in c_simple_widget_app_CreateTitle():

  1. Call ISHELL_CreateInstance() to create the title widget:
    if (AEE_SUCCESS != ISHELL_CreateInstance(pMe->piShell,
                AEECLSID_CTitleWidget, (void **)&pMe->piwTitle)) {
        pMe->piwTitle = NULL;
        return FALSE;
  2. Fill in the WidgetExtent structure and call IWidget_SetExtent() to set the extent of the title widget.
    we.width = pMe->rootcontainerwidth - 44;
    we.height = pMe->rootcontainerheight / 6;
    IWidget_SetExtent(pMe->piwTitle, &we);
  3. Call IWidget_SetBorderWidth() to set the border to zero (no border):
    (void) IWidget_SetBorderWidth(pMe->piwTitle, 0);
  4. Call IWidget_GetTitleWidget() to get the underlying static widget for the title widget, as follows:
    if (AEE_SUCCESS != IWidget_GetTitleWidget(pMe->piwTitle,
                &pMe->piwTitleStaticWidget)) {
        pMe->piwTitleStaticWidget = NULL;
        return FALSE;
    if (AEE_SUCCESS != IWIDGET_SetText(pMe->piwTitleStaticWidget,
                TITLE_TEXT, FALSE)) {
        return FALSE;
  5. Set the text for the title widget's underlying static widget by calling c_simple_widget_app_SetText(), which gets the value model for the static widget, then sets the value of the static widget to set the text, as follows:
    AEEResult nErr;
       IValueModel *pValModel;
       if (piWidget) {
          // get the value model for the static widget
          nErr = IWidget_GetModel(piWidget, AEEIID_IValueModel,
          if (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);
       else {
          return FALSE;
       return TRUE;
  6. Create a separate static widget (the title widget will decorate this static widget) and set its text by calling c_simple_widget_app_SetText():
    if (AEE_SUCCESS != ISHELL_CreateInstance(pMe->piShell,
                AEECLSID_CStaticWidget, (void **)&piwSTitle)) {
        return FALSE;
    // set the text for the static widget that the title will decorate
    if (!c_simple_widget_app_SetText(piwSTitle, ADDL_TITLE_TEXT)) {
       return FALSE;
  7. Call IDecorator_SetWidget() to decorate the static widget with the title widget:
    IDecorator_SetWidget((IDecorator *)(void*) pMe->piwTitle, piwSTitle);
  8. Fill in the WidgetExtent structure for the title widget and call IXYContainer_Insert() to insert the title widget into the XY container:
    dwpos.x = 20;
    dwpos.y = 20;
    dwpos.bVisible = TRUE;
    if (AEE_SUCCESS != IXYContainer_Insert(pMe->picXYCon,
                pMe->piwTitle, WIDGET_ZNORMAL, &dwpos)) {
        return FALSE;
    // the title widget has a reference to the static widget it
    // decorates, so the pointer to the static widget is released.

When the application is run, the title widget looks like this:

The first line of bold text is the title widget. The second line of text is the static widget that the title decorates.