Next: Line 5 Up: Explanation of the Previous: Lines 2 and

Line 4

Line 4 creates and MANAGES the label widget that contains the word "hello". [It is also possible to call procedures that only create a widget, so that you can manage it later. It is the act of managing the widget that causes it to show up on the screen.]


         msg=XtCreateManagedWidget("msg",xmLabelWidgetClass,toplevel,al,ac);

In this line, the parameter "msg" is the name of the widget. You can place any name here. This name is used when setting the widget's resources from a resource file, and is also used during error messages to tell you which widget is having problems. You want to make these widget names unique and descriptive. The xmLabelWidgetClass parameter says what type of widget is being created - in this case it's a label widget. The toplevel parameter declares which widget is the parent of the label widget. All widgets must have a parent. Finally the al and ac parameters let you modify the value of the widget's resources as the widget is created.

Once the widget is created, the function returns a value to the msg valiable, that can be used later to refer to that widget (eg - to change it's resources).

As with line one, there are many ways to make this line create segmentation faults. In this case however, the al and ac parameters can be replaced by NULL and 0 respectively if no resources are being changed at creation. An extremely common bug here (and always) is to leave out the #include for the label widget. On many compilers this will generate irrational errors in many places. Be sure you have all the libraries needed for all of the Widgets used.


morbe@enstb.enst-bretagne.fr