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

问题描述 投票:0回答:1

就像主题的主题说的那样:

  • 适用于 Windows 的 CygWin 带有适用于 Windows 的 X-Server 端口
  • 如何使用 X-Server 创建“可移动”窗口 当你(我)用 GNU C++ 编译器
  • 我已经用 Qt5 编程了,但我会这样做 使用来自 X-Server 的内置函数,无需使用 窗口管理器

感谢阅读,帮助反馈

  • 我已经能够使用 Qt5 框架创建一个窗口 但是这个框架需要大量的空间,因为 附带的大型图书馆
  • 我期待一个不使用任何框架的小例子, 只有 Cygwin 可用的 X-Server 函数 X服务器
c windows cygwin xserver
1个回答
0
投票

关注[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

还有窗户:

可能还想检查:

© www.soinside.com 2019 - 2024. All rights reserved.