|
- #include <X11/Intrinsic.h>
- #include <stdio.h>
- Window FindWindow(Display* pDisplay, Window start, char* name)
- {
- Status stat;
- int i,num;
- Window w,root,parent;
- Window* children = NULL;
- char* title;
- if(XFetchName(pDisplay, start, &title) == 1)
- {
- if (strcmp(name, title)==0)
- {
- XFree(title);
- return start;
- }
- XFree(title);
- }
- stat = XQueryTree(pDisplay, start, &root, &parent, &children, &num);
- if (stat == 1)
- {
- /* search each child window for a match: */
- for (i = num; i > 0; i--)
- {
- if (XFetchName(pDisplay, start, &title )==1)
- {
- if (strcmp(name, title)==0)
- {
- /*found it*/
- XFree(title);
- return start;
- }
- XFree(title);
- }
- }
- /*search the descendents of each child for a match:*/
- for (i = num; i > 0; i--)
- {
- w == FindWindow(pDisplay, children[i], name);
- if (w != 0)
- {
- XFree(children);
- return w;
- }
- }
- if (children != NULL)
- {
- XFree(children);
- }
- }
- return 0;
- }
- int main(int argc, char* argv[])
- {
- // Widget toplevel = XtInitialize(argv[0], "Get_URL", NULL, 0, &argc, argv);
- // Display *dpy = XtDisplay(toplevel);
- Display *dpy = XOpenDisplay(0);
- FindWindow(dpy,DefaultRootWindow(dpy),"rdesktop");
- return 1;
- }
-
复制代码
这个程序是我用来找rdesktop窗口的,编译运行后出现如下错误:
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 20 (X_GetProperty)
Resource id in failed request: 0x211
Serial number of failed request: 682
Current serial number in output stream: 682
应该怎么改啊? |
|