您当前的位置: 首页 >  ui

柳鲲鹏

暂无认证

  • 0浏览

    0关注

    4642博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

x11/xwindow GUI窗口代码范例

柳鲲鹏 发布时间:2021-12-17 13:57:07 ,浏览量:0

从别人那里抄的。

  • 代码
#include 
#include 
#include 
#include 

#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}

关注
打赏
1665724893
查看更多评论
立即登录/注册

微信扫码登录

0.0538s