📄 00000003.htm
字号:
} <BR> <BR>static void DeleteProp(Widget w, <BR> caddr_t client_data, <BR> XmAnyCallbackStruct *call_data) <BR>{ <BR> XDeleteProperty(mydisplay, root_window, myproperty); <BR> XFlush(mydisplay); <BR> XtCloseDisplay(mydisplay); <BR> exit(0); <BR>} <BR>/* <BR> * Program: get_from_prop.c <BR> * <BR> * Purpose: Get the data from a property which is hanged on <BR> * root window. <BR> * <BR> * Author : Chung-Chia Chen <BR> * <BR> * Date : Dec. 12, 1994 <BR> */ <BR> <BR>#include <X11/StringDefs.h> <BR>#include <X11/Intrinsic.h> <BR>#include <X11/Xatom.h> <BR>#include <Xm/Xm.h> <BR>#include <Xm/RowColumn.h> <BR>#include <Xm/PushB.h> <BR>#include <Xm/Text.h> <BR>#include <stdio.h> <BR>#include <stdlib.h> <BR> <BR>#define ROWS 10 <BR>#define COLS 40 <BR> <BR>static void GetData(Widget*); <BR>static void CloseApp(Widget, XtPointer*, XmAnyCallbackStruct*); <BR> <BR>static Display *mydisplay; <BR>static XEvent myevent; <BR>static Window root_window; <BR>static Atom myproperty; <BR> <BR>void main(int argc, char *argv[]) <BR>{ <BR> Widget toplevel, rc, data_field, quit_btn; <BR> <BR> <BR> if( argv[1] == NULL ) { <BR> printf("Usage: program_name property_name_that_already_exists\n"); <BR> exit(0); <BR> } <BR> <BR> toplevel = XtInitialize(argv[0], "GetDemo", NULL, 0, <BR> &argc, argv); <BR> <BR> mydisplay = XtDisplay(toplevel); <BR> <BR> if( (root_window = DefaultRootWindow(mydisplay)) == NULL ) { <BR> printf("root_window is null, error\n"); <BR> exit(0); <BR> } <BR> /*************************************************** <BR> * Get the display and root window id. <BR> ***************************************************/ <BR> <BR> myproperty = XInternAtom(mydisplay, argv[1], True); <BR> if( myproperty == None ) { <BR> printf("The property named %s does not exist.\n", argv[1]); <BR> exit(0); <BR> } <BR> /************************************************* <BR> * Check that the property exists or not. <BR> *************************************************/ <BR> <BR> rc = XtVaCreateManagedWidget("Panel", <BR> xmRowColumnWidgetClass, toplevel, <BR> NULL); <BR> <BR> data_field = XtVaCreateManagedWidget("DataField", <BR> xmTextWidgetClass, rc, <BR> XmNeditMode, XmMULTI_LINE_EDIT, <BR> XmNrows, ROWS, <BR> XmNcolumns, COLS, <BR> NULL); <BR> <BR> quit_btn = XtVaCreateManagedWidget("Quit", <BR> xmPushButtonWidgetClass, rc, <BR> NULL); <BR> <BR> XtAddCallback(quit_btn, XmNactivateCallback, (XtCallbackProc) CloseApp, NULL); <BR> <BR> XtRealizeWidget(toplevel); <BR> <BR> <BR> XSelectInput(XtDisplay(toplevel), root_window, PropertyChangeMask); <BR> /***************************************************** <BR> * The root window solicits PropertyChange event. <BR> *****************************************************/ <BR> <BR> while(TRUE) { <BR> <BR> XtNextEvent(&myevent); <BR> <BR> switch (myevent.type){ <BR> <BR> case PropertyNotify: <BR> <BR> printf("PropertyNotify event occured on root window\n"); <BR> <BR> if(myevent.xproperty.window = root_window && <BR> myevent.xproperty.atom == myproperty) <BR> GetData(&data_field); <BR> else <BR> XtDispatchEvent(&myevent); <BR> <BR> break; <BR> /************************************************ <BR> * It's important to check the xproperty.window <BR> * and xproperty.atom, otherwise some bad access <BR> * event will occur. <BR> ************************************************/ <BR> <BR> default: <BR> XtDispatchEvent(&myevent); <BR> break; <BR> <BR> }/* end of switch(myevent.type) */ <BR> <BR> }/* end of while(TRUE) */ <BR> <BR>} <BR> <BR> <BR>static void GetData(Widget *data_w) <BR>{ <BR> <BR> Atom ret_type; <BR> int ret_format; <BR> unsigned long ret_len, ret_after; <BR> unsigned char *ret_property; <BR> <BR> if( (XGetWindowProperty(mydisplay, root_window, myproperty, <BR> 0, 8192, False, XA_STRING, <BR> &ret_type, &ret_format, &ret_len, &ret_after, <BR> &ret_property) == Success) && (ret_type == XA_STRING)) { <BR> <BR> XmTextSetString(*data_w, (char *) ret_property); <BR> XFree(ret_property); <BR> } <BR> else <BR> printf("XGetWindowProperty failed\n"); <BR> <BR>} <BR> <BR>static void CloseApp(Widget w, <BR> XtPointer *client_data, <BR> XmAnyCallbackStruct *call_data) <BR>{ <BR> XtCloseDisplay(XtDisplay(w)); <BR> exit(0); <BR>} <BR> <BR> <BR>-- <BR> <BR> ========================= <BR> ● 兰阳子弟,故乡溪南小镇 <BR> 陈重嘉 <BR> ========================= <BR> <BR> <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -