使用Motif开发中文软件
作者:于明俭
使用Motif开发中文软件并不简单, 有几种方法可以设置中文,
- 在资源文件中, 这也是最常见和最方便的
- 在初时化的 fallback 中
- 每次建立XmString时使用FontSet
本例所演示的是第二种, 编译: gcc -I/usr/X11R6/include -o motif motif.c -L/usr/X11R6/lib -lXm -lX11, 运行结果为:
请注意: LessTif不支持XIM输入
// file motif.c
#include
#include
#include
#include
#include
#include
#include
#include
String fallbacks[] = {
"*fontList:8x16,cclib16_1",
NULL
};
main(int argc, char *argv[])
{
Widget toplevel, text_w, rowcol;
XtAppContext app;
setlocale(LC_ALL, "");
toplevel = XtVaAppInitialize(&app, "Demos",
NULL, 0, &argc, argv, fallbacks, NULL);
rowcol = XtVaCreateWidget("rowcol",
xmRowColumnWidgetClass, toplevel,
XmNorientation, XmHORIZONTAL,
NULL);
XtVaCreateManagedWidget("请输入:",
xmLabelGadgetClass, rowcol, NULL);
text_w = XtVaCreateManagedWidget("text_w",
xmTextFieldWidgetClass, rowcol,
NULL);
XtAddCallback(text_w, XmNactivateCallback, Test, 0);
XtManageChild(rowcol);
XtRealizeWidget(toplevel);
XtAppMainLoop(app);
}