windows 如何用GNU C++创建一个无需X-Server窗口管理器即可移动的窗口

34gzjxbg  于 2023-04-22  发布在  Windows
关注(0)|答案(1)|浏览(101)

就像主题的主题说:

  • CygWin for Windows附带了一个用于Windows的X-Server端口
  • 我怎样才能创建一个“可移动的”窗口,当你(我)用GNUC ++编译器编程时,可以使用X-Server函数
  • 我已经用Qt 5编程了,但我会用X-Server的内置函数来编程,而不需要使用窗口管理器

感谢您的阅读和帮助反馈

  • 我已经能够用Qt 5框架创建一个窗口,但这个框架需要大量的空间,因为附带的大型库
  • 我期待一个小的例子,不使用任何框架,只有X-Server的功能,可用于Cygwin的X-Server
voase2hg

voase2hg1#

遵循[YouTube]: Future Tech Labs - X11 Tutorials - 1 - Creating a Simple Window教程,并得出以下(虚拟)示例。

  • main00.c*:
#include <stdio.h>

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

int main()
{
    Display *pd = NULL;
    if ((pd = XOpenDisplay((char*)NULL)) == NULL) {
        printf("XOpenDisplay error\n");
        return -1;
    }
    int scr = DefaultScreen(pd);
    Window win = XCreateSimpleWindow(pd, RootWindow(pd, scr),
        100, 100, 320, 200, 15, BlackPixel(pd, scr), WhitePixel(pd, scr));
    XSetStandardProperties(pd, win, "Cygwin X q075977479", "q075977479", None, NULL, 0, NULL);
    XMapWindow(pd, win);

    XEvent ev;

    while (XNextEvent(pd, &ev) == 0) {
    }

    XUnmapWindow(pd, win);
    XDestroyWindow(pd, win);
    XCloseDisplay(pd);

    printf("\nDone.\n\n");
    return 0;
}

输出

[cfati@cfati-5510-0:/cygdrive/e/Work/Dev/StackExchange/StackOverflow/q075977479]> ~/sopr.sh
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###

[064bit prompt]> uname -a
CYGWIN_NT-10.0-19045 cfati-5510-0 3.4.6-1.x86_64 2023-02-14 13:23 UTC x86_64 Cygwin
[064bit prompt]> ls
main00.c
[064bit prompt]> gcc main00.c -o main00.exe -lX11
[064bit prompt]> ls
main00.c  main00.exe
[064bit prompt]> DISPLAY=:0 ./main00.exe

窗口:

还可以检查:

相关问题