#include	<Xm/Label.h>
/* プライベートヘッダファイルをインクルードする */
#include	<Xm/LabelP.h>

XtAppContext app;
int count = 0;
String label_string_ptr; /* 直接書き換える位置を保持する */

void Timer(Widget label);

int
main(int ac, char *av[])
{
    Widget top, label;
    String str = "000000";
    XmString xms;
    Arg label_arg[1];

    top = XtAppInitialize(&app, "Sample",
			  NULL, 0, &ac, av, NULL, NULL, 0);
    xms = XmStringCreateSimple(str);
    XtSetArg(label_arg[0], XmNlabelString, xms);
    label = XmCreateLabel(top, "label1", label_arg, XtNumber(label_arg));
    XmStringFree(xms);
    XtManageChild(label);

    /* ラベルウィジェットの中身に触って
       文字列情報を取り出す */
    label_string_ptr = (String)((XmLabelRec *)label)->label._label;
    /* 文字列の始まる位置を決定する */
    while (strncmp(str, label_string_ptr, strlen(str)))
	    label_string_ptr++;

    XtAppAddTimeOut(app, 100, (XtTimerCallbackProc)Timer, label); 

    XtRealizeWidget(top);
    XtAppMainLoop(app);
}

void
Timer(Widget label) 
{
    if (++count >= 1000000) return;

    /* 文字列情報の中身を書き換える */
    sprintf(label_string_ptr, "%06d", count);
    /* Expose Eventを送って表示を更新する */
    XClearArea(XtDisplay(label), XtWindow(label), 0, 0, 0, 0, True);

    XtAppAddTimeOut(app, 100, (XtTimerCallbackProc)Timer, label); 
}
