Xlib中的如何将窗口在创建时指定或移动到屏幕范围之外呢?

jeffzhu 2009-07-24 01:34:00
我想让一个窗口在初始化时不可见,想通过改变窗口xy座标来实现,初始化好后再移回来,但是XMoveWindow方法似乎每次都要自动将窗口计算到桌面之内,请教各位如何让它不要这么聪明呢?

程序代码如下:

#include <X11/Xlib.h>
#include <X11/Xutil.h>

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

/* Global variables */

Display * display;
int screen_num;
static char * appname;


/* main() function */

int main( int argc, char * argv[] ) {

/* Window variables */

Window win;
int x, y;
unsigned int width, height;
unsigned int border_width;


/* Display variables */

char * display_name = NULL;
unsigned int display_width, display_height;


/* Miscellaneous X variables */

XSizeHints * size_hints;
XWMHints * wm_hints;
XClassHint * class_hints;
XEvent report;

appname = argv[0];


/* Allocate memory for our structures */
if ( !( size_hints = XAllocSizeHints() ) ||
!( wm_hints = XAllocWMHints() ) ||
!( class_hints = XAllocClassHint() ) ) {
fprintf(stderr, "%s: couldn't allocate memory.\n", appname);
exit(EXIT_FAILURE);
}


/* Connect to X server */
if ( (display = XOpenDisplay(display_name)) == NULL ) {
fprintf(stderr, "%s: couldn't connect to X server %s\n",
appname, display_name);
exit(EXIT_FAILURE);
}


/* Get screen size from display structure macro */

screen_num = DefaultScreen(display);
display_width = DisplayWidth(display, screen_num);
display_height = DisplayHeight(display, screen_num);


/* Set initial window size and position, and create it */

x = 0;
y = 0;
width = 500;
height = 300;

win = XCreateSimpleWindow(display, RootWindow(display, screen_num),
x, y, width, height, border_width,
BlackPixel(display, screen_num),
WhitePixel(display, screen_num));

/* Display Window */
XMapWindow(display, win);

XMoveWindow(display, win,1500,100);

/* Enter event loop */
XNextEvent(display, &report);

return EXIT_SUCCESS; /* We shouldn't get here */
}


编译 gcc -o test test.c -Wall -L/usr/X11R6/lib -lX11
...全文
237 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ShowMan 2009-07-31
  • 打赏
  • 举报
回复
一般显卡可以用offscreen的特性来做这个,窗体有hide属性也可以
yhf365 2009-07-31
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jeffzhu 的回复:]
谢谢楼上的回复,我正用这个方法。不过还是特别想知道有没有办法让窗口移到屏幕外面去。
[/Quote]
如果移到屏幕外,
用户就无法手动把它移回来了,
xlib的开发人员会感觉这是一个bug,
所以我感觉xlib是不能实现的。
jeffzhu 2009-07-31
  • 打赏
  • 举报
回复
谢谢楼上的回复,我正用这个方法。不过还是特别想知道有没有办法让窗口移到屏幕外面去。
yhf365 2009-07-28
  • 打赏
  • 举报
回复
不能在初始化之前先隐藏吗?
VC、Delphi、Qt都可以这样的,
xlib貌似可以通过这个函数实现:
XUnmapWindow(Display *, Window);

LZ可以去查一下如何隐藏窗体,
这样效率也高一些。
而不是用移动的方法,
jeffzhu 2009-07-28
  • 打赏
  • 举报
回复
太惨了,都没人回

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧