We can set a Resource values at creation.
We can set the argument list using XtSetArg() as in the previous section and then specify these arguments in the XmCreate...() function. In push_res2.c we do this with the line:
button = XmCreatePushButton(top_wid, "Push_me", args, n);
There is an alternative method which lets us set resource values and create a managed widget in one function call. The function is XtVaCreateManagedWidget() and is a convenient way to program such tasks.
Note it is a ``general'' function that can create many different classes of widget. This function is preferred for the creation of widgets due to its uniformity of syntax/structure and its brevity in performing more than one task.
All widgets (in this course) will subsequently be created using this function.
There are related functions in Motif - see Xt reference manual.
Let us look a the syntax of this function:
Widget XtVaCreateManagedWidget(String name, WidgetClass widget_class, Widget parent, ... resource name/value pairs ..., NULL)
name specifies the text label for the created widget.
widget_class specifies the class of the widget.
parent is the parent widget.
There then follows a NULL terminated list of pairs of resource name and values.
The function returns a widget of the class specified.
So to create a managed PushButton widget with dimensions 400 by 300 (as in push_res3.c) we would type:
button = XtVaCreateManagedWidget("Push_me", XmPushButtonWidgetClass, top_wid, XmNwidth, 400, XmNheight, 200, NULL);
Here XmPushButtonWidgetClass is the class identifier of a PushButton. Other widget types should be fairly obvious.