其他分享
首页 > 其他分享> > x11 窗口代码范例

x11 窗口代码范例

作者:互联网

从别人那里抄的。

#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define DISPLAY_TEXT "Taishan Office"

void start_window()
{
   Display *display;
   Window   window;
   XEvent   event;
   int      screen;
 
   display = XOpenDisplay(NULL);
   if (display == NULL)
   {
      fprintf(stderr, "Cannot open display\n");
      exit(1);
   }
 
   screen = DefaultScreen(display);
   window = XCreateSimpleWindow(display, RootWindow(display, screen),
         100, 100, 500, 500,
         1, 777215, 111111);
   XSelectInput(display, window, ExposureMask | KeyPressMask);
   XMapWindow(  display, window);

   while (1)
   {
      XNextEvent(display, &event);
      if (event.type == Expose)
      {
         XFillRectangle(display, window, DefaultGC(display, screen),
              20, 20, 50, 50);
         XDrawString(   display, window, DefaultGC(display, screen),
              90, 90, DISPLAY_TEXT, strlen(DISPLAY_TEXT));
      }

      //任意键退出
      if (event.type == KeyPress)
      {
          break;
      }
   }

   XCloseDisplay(display);
}


int main(int argc, char** argv)
{
   start_window();
   return 0;
}
#!/bin/bash
 
COMPILE_LINK=" -lX11"
 
OUTPUT_FILE=x11
if [ -f ${OUTPUT_FILE} ]; then
    rm ${OUTPUT_FILE}
fi
echo ${COMPILE_INCLUDE_LINK}
gcc \
    -o ${OUTPUT_FILE} \
    x11.cpp \
    ${COMPILE_LINK}

标签:范例,窗口,screen,event,window,FILE,x11,include,display
来源: https://blog.csdn.net/quantum7/article/details/121994762