📄 list_16_20.c
字号:
/************************************************************************* **** listing_16_20.c **** **** Example of explicit converter calls. This program presents a **** pushbutton. Each time the button is pushed, its background **** color changes. **** *************************************************************************/#include <string.h>#include <Xm/PushB.h>void ButtonCB(); /* FORWARD Definitions */void SetBackground();Widget appshell, the_btn;void main( argc, argv ) int argc; char *argv[];{ appshell = XtInitialize( argv[0], "Listing_16_20", NULL, 0, &argc, argv ); the_btn = XmCreatePushButton( appshell, "TheBtn", NULL, 0 ); XtManageChild( the_btn ); XtAddCallback( the_btn, XmNactivateCallback, ButtonCB, NULL ); XtRealizeWidget( appshell ); XtMainLoop();}void ButtonCB( w, client_data, call_data ) Widget w; caddr_t client_data; caddr_t call_data;{ static int cnum = 0; switch (cnum++) { case 0 : SetBackground( w, "Red" ); break; case 1 : SetBackground( w, "Green" ); break; case 2 : SetBackground( w, "Blue" ); break; case 3 : SetBackground( w, "Black" ); cnum = 0; break; }}/***** SetBackground( w, cname )****** Sets the "background" resource of widget "w" to the color*** named by "cname".**/void SetBackground( w, cname ) Widget w; String cname;{ XrmValue from, to; Arg arg; from.addr = cname; from.size = strlen(cname); to.addr = NULL; to.size = 0; XtConvert( w, XmRString, &from, XmRPixel, &to ); if (to.addr != NULL) { XtSetArg( arg, XmNbackground, *(Pixel*)to.addr ); XtSetValues( w, &arg, 1 ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -