📄 list_16_13.c
字号:
/************************************************************************* **** listing_16_13.c **** **** String-to-XmString converter example. This converter allows a **** program to specify multi-line XmStrings in a resource file. It **** is in the context of "Hello, World". **** *************************************************************************/#include <Xm/Label.h>void CvtStringToXmString(); /* FORWARD Definition */Widget appshell, /* Application Shell */ a_label, /* Dummy label */ the_label; /* The only true label */void main( argc, argv ) int argc; char *argv[];{ appshell = XtInitialize( argv[0], "Listing_16_13", NULL, 0, &argc, argv ); a_label = XmCreateLabel( appshell, "ALabel", NULL, 0 ); XtDestroyWidget( a_label ); XtAddConverter( XmRString, XmRXmString, CvtStringToXmString, NULL, 0 ); the_label = XmCreateLabel( appshell, "TheLabel", NULL, 0 ); XtManageChild( the_label ); XtRealizeWidget( appshell ); XtMainLoop();}/***** CvtStringToXmString( args, num_args, from, to )****** Converts "String" data (NUL-terminated ASCII strings) to *** "XmString" data (compound strings). Recognizes the sequence*** "\n" as an embedded newline, allowing the compound string*** to have multiple lines.****** Notes: *** - The parameters "args" and "num_args" are not used by this *** conversion.*** - The maximum size of the compound string is 1024 bytes. This*** limit is imposed by the fact that the string is copied into*** a local buffer.**/void CvtStringToXmString( args, num_args, from, to ) XrmValue *args; Cardinal *num_args; XrmValue *from; XrmValue *to;{ static char lcl_buf[1024]; static XmString lcl_ptr = lcl_buf; XmString xms; String str; int siz; str = (String)from->addr; xms = XmStringCreateLtoR( str, XmSTRING_DEFAULT_CHARSET ); siz = XmStringLength(xms); if (siz < 1024) { memcpy( lcl_buf, xms, siz ); to->addr = (caddr_t)&lcl_ptr; to->size = sizeof(XmString); } else { to->addr = NULL; to->size = 0; } XmStringFree( xms );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -