Next: Scale Style Up: Scale Widgets Previous: Scale Callbacks

The scale.c program

The program simply brings up a virtual volume Scale. The user changes the value which is caught by a XmNvalueChangedCallback and the current value interrogated to print a message to standard output.


#include  <Xm/Xm.h>
#include <Xm/Scale.h>

main(int argc, char **argv)

{   Widget        top_wid, scale;
    XmString	  title;
    XtAppContext  app;
    void          scale_cbk();


    top_wid = XtVaAppInitialize(&app, "Scale_eg", NULL, 0,
        &argc, argv, NULL, NULL);
        
    title = XmStringCreateSimple("Volume");

    scale = XtVaCreateManagedWidget("scale",
        xmScaleWidgetClass, top_wid,
        XmNtitleString,   title,
        XmNorientation,    XmHORIZONTAL,
        XmNmaximum,       11,
        XmNdecimalPoints, 0,
        XmNshowValue,     True,
        XmNwidth,         200,
        XmNheight,        100,
        NULL);

       
    XtAddCallback(scale,XmNvalueChangedCallback, scale_cbk, 
                  NULL);
 
    XtRealizeWidget(top_wid);
    XtAppMainLoop(app);
}


void scale_cbk(Widget widget, int data, 
               XmScaleCallbackStruct *scale_struct)

{    if (scale_struct->value < 4)
       printf("Volume too quiet (%d)\n");
    else if (scale_struct->value < 7)
       printf("Volume Ok (%d)\n");

    
     else
        if (scale_struct->value < 10)
       printf("Volume too loud (%d)\n");
      else /* Volume == 11 */
       printf("Volume VERY Loud (%d)\n");       
}


Dave.Marshall@cm.cf.ac.uk
Tue May 24 16:52:56 BST 1994