list_17_08.c

来自「This source code has been tested under O」· C语言 代码 · 共 63 行

C
63
字号
/*************************************************************************                                                                    ****  listing_17_08.c                                                   ****                                                                    ****  Digital clock program, implemented using a label updated by a     ****  timeout callback.                                                 ****                                                                    *************************************************************************/#include <time.h>#include <Xm/Label.h>void	TimeoutCB();			/* FORWARD Definitions	      */Widget	appshell,	the_label;void main( argc, argv )    int     argc;    char    *argv[];{    appshell = XtInitialize( argv[0], "Listing_17_08", NULL, 0, &argc, argv );    the_label = XmCreateLabel( appshell, "TheLabel", NULL, 0 );    XtManageChild( the_label );    XtAddTimeOut( 1000, TimeoutCB, the_label );    XtRealizeWidget( appshell );    XtMainLoop();}void TimeoutCB( w, id )    Widget	    w;			/* Note implicit caddr_t cast */    XtIntervalId    *id;		/* Ignored		      */{    long	    clock;		/* The raw time value...      */    struct tm	    *the_time;		/* Converted to localtime...  */    char	    lcl_str[256];       /* Converted to text...       */    XmString	    xms;		/* Converted for the widget   */    Arg		    the_arg;    XtAddTimeOut( 1000, TimeoutCB, the_label );    clock    = time( NULL );    the_time = localtime( &clock );    sprintf( lcl_str, "%02d:%02d:%02d", the_time->tm_hour,					the_time->tm_min,					the_time->tm_sec );    xms = XmStringCreate( lcl_str, XmSTRING_DEFAULT_CHARSET );    XtSetArg( the_arg, XmNlabelString, xms );    XtSetValues( w, &the_arg, 1 );    XmStringFree( xms );}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?