如何在用xlib建立的窗口上显示文字?
int i = 0;
int xfd;
int max_fd;
ts_fd = open (TS_DEVICE, O_RDONLY);
if (ts_fd < 0)
{
perror (TS_DEVICE);
exit (1);
}
rect_sideLength = 8;
for (i = 1; i < argc; i++)
{
if (argv[0] > 0x30 && argv[0] < 0x3a)
rect_sideLength = atoi(argv);
}
for (i = 1; i < argc; i++)
{
if (!strcmp (argv, "-debug"))
flag_debug = 1;
}
dsp = XOpenDisplay(NULL);
if (dsp == NULL)
{
printf("Cannot connect to X server %sn", XDisplayName(NULL));
exit(1);
}
// else
// printf("Open X successfuln");
xfd = ConnectionNumber (dsp);
max_fd = (xfd > ts_fd) ? xfd : ts_fd;
screen = DefaultScreen(dsp);
XSetWindowAttributes attributes;
attributes.override_redirect = True;//flag_debug ? False : True;
attributes.background_pixel = WhitePixel(dsp, screen);
win = XCreateWindow(dsp, DefaultRootWindow(dsp), 0, 0,
DisplayWidth(dsp, 0), DisplayHeight(dsp, 0),
0,
DefaultDepth(dsp, 0),
InputOutput,
DefaultVisual(dsp, 0),
CWOverrideRedirect | CWBackPixel,
&attributes);
unsigned long valuemask = 0;
XGCValues values;
gc = XCreateGC(dsp, win, valuemask, &values);
XDrawString(dsp,win,gc,10,10,strdraw,strlen(strdraw));
XMapWindow(dsp,win);
XSelectInput (dsp, win, StructureNotifyMask | ButtonPressMask | KeyPressMask);
XGrabKeyboard (dsp, win, True, GrabModeAsync, GrabModeAsync, CurrentTime);
#if 1
draw_XYlines(0, 0, DisplayWidth(dsp, 0), DisplayHeight(dsp, 0));
#endif
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 100*1000; /* 100ms */
printf("xfd: %dn",xfd);
printf("ts_fd: %dn",ts_fd);
while(1)
{
fd_set fds;
handle_events ();
FD_ZERO (&fds);
FD_SET (xfd, &fds);
if (ts_fd != -1)
FD_SET (ts_fd, &fds);
select (max_fd + 1, &fds, NULL, NULL, &timeout);
if (ts_fd != -1 && FD_ISSET (ts_fd, &fds))
read_ts ();
else
XRaiseWindow(dsp, win);
}
close(ts_fd);
XCloseDisplay(dsp);
return 0;
}
红色部分为我想窗口初始化时显示的字符串strdraw,可是只显示窗口,没显示字符串,是怎么回事?
XDrawString(dsp,win,gc,10,10,strdraw,strlen(strdraw)这个函数是怎么使用的呢?哪位大侠知道,请指教。。谢谢。。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XftTextExtentsUtf8()
你试试这个函数行吗