C++ 我想做闪屏,现在我有两个问题?

C++ 我想做闪屏,现在我有两个问题?,c++,c,screen,x11,splash-screen,C++,C,Screen,X11,Splash Screen,1:我想有一个闪屏,但我只有一个窗口?那么,像parm这样的东西怎么办 2:我已经用了一段时间(!done)来画窗口,所以如何用函数或其他东西来打破它 这是我的代码,向你致以衷心的感谢 g++-o m_splash m_splash.cpp-lX11-lImlib2 #include <stdio.h> #include <X11/Xlib.h> #include <Imlib2.h> #include <unistd.h> int main()

1:我想有一个闪屏,但我只有一个窗口?那么,像parm这样的东西怎么办

2:我已经用了一段时间(!done)来画窗口,所以如何用函数或其他东西来打破它

这是我的代码,向你致以衷心的感谢

g++-o m_splash m_splash.cpp-lX11-lImlib2

#include <stdio.h>
#include <X11/Xlib.h>
#include <Imlib2.h>
#include <unistd.h>

int main()
{
    Imlib_Image  m_img;
    Display     *m_dpy;
    Pixmap       m_pix;
    Window       m_root;
    Screen      *scn;
    int m_width, m_height;
    const char *filename = "/home/ang/so_zt/w.png";

    m_img = imlib_load_image(filename);
    if(!m_img)
    {
        printf("%s\n","init m_img faild");
    }
    imlib_context_set_image(m_img);
    m_width = imlib_image_get_width();
    m_height = imlib_image_get_height();

    m_dpy = XOpenDisplay(NULL);
    if(!m_dpy)
    {
        printf("%s\n","open display failed");
    }
    scn = DefaultScreenOfDisplay(m_dpy);
    int s = DefaultScreen(m_dpy);
    m_root = XCreateSimpleWindow(m_dpy, RootWindow(m_dpy,s),10,10,m_width,m_height,0,
                                 BlackPixel(m_dpy, s), WhitePixel(m_dpy, s));
    m_pix = XCreatePixmap(m_dpy, m_root, m_width, m_height, DefaultDepthOfScreen(scn));

    imlib_context_set_display(m_dpy);
    imlib_context_set_visual(DefaultVisualOfScreen(scn));
    imlib_context_set_colormap(DefaultColormapOfScreen(scn));
    imlib_context_set_drawable(m_pix);

    imlib_render_image_on_drawable(0,0);
    XSetWindowBackgroundPixmap(m_dpy, m_root, m_pix);
    XClearWindow(m_dpy, m_root);
    Atom wmDeleteMessage = XInternAtom(m_dpy, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(m_dpy, m_root, &wmDeleteMessage, 1);

    XSelectInput(m_dpy, m_root, ExposureMask | KeyPressMask | StructureNotifyMask);
    XMapWindow(m_dpy, m_root);
    bool done = false;
    while (!done)
    {
        XEvent m_ev;
        XNextEvent(m_dpy, &m_ev);
        /* draw or redraw the window */
        if (m_ev.type == Expose)
        {
            XFillRectangle(m_dpy, m_root, DefaultGC(m_dpy, DefaultScreen(m_dpy)), 20, 20, 10, 10);
        }

    /* exit on key press */
        //usleep(1000000);
        //done = true;
        switch(m_ev.type)
        {
        case KeyPress:
            XDestroyWindow(m_dpy, m_root);
        break;

        case DestroyNotify:
            done = true;
        break;
        case ClientMessage:
            if (m_ev.xclient.data.l[0] == wmDeleteMessage)
            {
                done = true;
            }
        break;
        }
    }

    //XFreePixmap(m_dpy, m_pix);
    //imlib_free_image();
    //XCloseDisplay(m_dpy);
}
#包括
#包括
#包括
#包括
int main()
{
Imlib_图像m_img;
显示*m_dpy;
Pixmap m_pix;
窗木根;
屏幕*scn;
int m_宽度,m_高度;
const char*filename=“/home/ang/so_zt/w.png”;
m_img=imlib_load_图像(文件名);
如果(!m_img)
{
printf(“%s\n”,“init m_img失败”);
}
imlib\u context\u set\u image(m\u img);
m_width=imlib_image_get_width();
m_height=imlib_image_get_height();
m_dpy=XOpenDisplay(NULL);
如果(!m_dpy)
{
printf(“%s\n”,“打开显示失败”);
}
scn=显示的默认屏幕(m_dpy);
int s=默认屏幕(m_dpy);
m_root=XCreateSimpleWindow(m_dpy,RootWindow(m_dpy,s),10,10,m_宽度,m_高度,0,
黑像素(mudpy,s),白像素(mudpy,s);
m_pix=XCreatePixmap(m_dpy、m_根、m_宽度、m_高度、DefaultDepthOfScreen(scn));
imlib\u context\u set\u display(m\u dpy);
imlib_context_set_visual(默认可视化屏幕(scn));
imlib_context_set_colormap(DefaultColormapOfScreen(scn));
imlib\u context\u set\u drawinable(m\u pix);
imlib_render_image_on_drawinable(0,0);
XSetWindowBackgroundPixmap(m_dpy,m_root,m_pix);
XClearWindow(m_dpy,m_root);
Atom wmDeleteMessage=XInternAtom(m_dpy,“WM_DELETE_窗口”,False);
XSetWMProtocols(m_dpy、m_root和wmDeleteMessage,1);
XSelectInput(m|dpy,m|root,ExposureMask | KeyPressMask | StructureNotifyMask);
XMapWindow(m_dpy,m_root);
bool done=false;
而(!完成)
{
XEvent m_ev;
XNextEvent(m_dpy和m_ev);
/*绘制或重新绘制窗口*/
如果(m_ev.type==暴露)
{
XFillRectangle(m_dpy,m_root,DefaultGC(m_dpy,DefaultScreen(m_dpy)),20,20,10,10);
}
/*按键退出*/
//美国LEEP(1000000);
//完成=正确;
开关(电动式)
{
外壳按键:
XDestroyWindow(m_dpy,m_root);
打破
案件通知:
完成=正确;
打破
案例客户端消息:
if(m_ev.xclient.data.l[0]==wmDeleteMessage)
{
完成=正确;
}
打破
}
}
//XFreePixmap(m_dpy,m_pix);
//imlib_free_image();
//XCloseDisplay(m_dpy);
}

要使其成为启动屏幕,请使用扩展窗口管理器提示

#include <X11/Xatom.h>

Atom type = XInternAtom(m_dpy, "_NET_WM_WINDOW_TYPE", False);
Atom value = XInternAtom(m_dpy, "_NET_WM_WINDOW_TYPE_SPLASH", False);
XChangeProperty(m_dpy, m_root, type, XA_ATOM, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&value), 1);
在映射窗口以显示它之后

XUnmapWindow(m_dpy, m_root);
当你想摆脱它的时候

在本例中,程序仅休眠5秒,然后继续:

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <Imlib2.h>
#include <unistd.h>

int main()
{
    Imlib_Image  m_img;
    Display     *m_dpy;
    Pixmap       m_pix;
    Window       m_root;
    Screen      *scn;
    int m_width, m_height;
    const char *filename = "w.png";

    m_img = imlib_load_image(filename);
    if(!m_img)
    {
        printf("%s\n","init m_img faild");
    }
    imlib_context_set_image(m_img);
    m_width = imlib_image_get_width();
    m_height = imlib_image_get_height();

    m_dpy = XOpenDisplay(NULL);
    if(!m_dpy)
    {
        printf("%s\n","open display failed");
    }
    scn = DefaultScreenOfDisplay(m_dpy);
    int s = DefaultScreen(m_dpy);
    m_root = XCreateSimpleWindow(m_dpy, RootWindow(m_dpy,s),10,10,m_width,m_height,0,
                                 BlackPixel(m_dpy, s), WhitePixel(m_dpy, s));
    m_pix = XCreatePixmap(m_dpy, m_root, m_width, m_height, DefaultDepthOfScreen(scn));

    Atom type = XInternAtom(m_dpy, "_NET_WM_WINDOW_TYPE", False);
    Atom value = XInternAtom(m_dpy, "_NET_WM_WINDOW_TYPE_SPLASH", False);
    XChangeProperty(m_dpy, m_root, type, XA_ATOM, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&value), 1);

    imlib_context_set_display(m_dpy);
    imlib_context_set_visual(DefaultVisualOfScreen(scn));
    imlib_context_set_colormap(DefaultColormapOfScreen(scn));
    imlib_context_set_drawable(m_pix);

    imlib_render_image_on_drawable(0,0);
    XSetWindowBackgroundPixmap(m_dpy, m_root, m_pix);
    XClearWindow(m_dpy, m_root);
    Atom wmDeleteMessage = XInternAtom(m_dpy, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(m_dpy, m_root, &wmDeleteMessage, 1);

    XMapWindow(m_dpy, m_root);
    XFlush(m_dpy);
    sleep(5);
    XUnmapWindow(m_dpy, m_root);
}
#包括
#包括
#包括
#包括
#包括
int main()
{
Imlib_图像m_img;
显示*m_dpy;
Pixmap m_pix;
窗木根;
屏幕*scn;
int m_宽度,m_高度;
const char*filename=“w.png”;
m_img=imlib_load_图像(文件名);
如果(!m_img)
{
printf(“%s\n”,“init m_img失败”);
}
imlib\u context\u set\u image(m\u img);
m_width=imlib_image_get_width();
m_height=imlib_image_get_height();
m_dpy=XOpenDisplay(NULL);
如果(!m_dpy)
{
printf(“%s\n”,“打开显示失败”);
}
scn=显示的默认屏幕(m_dpy);
int s=默认屏幕(m_dpy);
m_root=XCreateSimpleWindow(m_dpy,RootWindow(m_dpy,s),10,10,m_宽度,m_高度,0,
黑像素(mudpy,s),白像素(mudpy,s);
m_pix=XCreatePixmap(m_dpy、m_根、m_宽度、m_高度、DefaultDepthOfScreen(scn));
原子类型=XInternAtom(m_dpy,“_NET_WM_WINDOW_type”,False);
原子值=XInternAtom(m_dpy,“\u NET\u WM\u WINDOW\u TYPE\u SPLASH”,False);
XChangeProperty(m_dpy,m_root,type,XA_ATOM,32,PropModeReplace,reinterpret_cast(&value),1);
imlib\u context\u set\u display(m\u dpy);
imlib_context_set_visual(默认可视化屏幕(scn));
imlib_context_set_colormap(DefaultColormapOfScreen(scn));
imlib\u context\u set\u drawinable(m\u pix);
imlib_render_image_on_drawinable(0,0);
XSetWindowBackgroundPixmap(m_dpy,m_root,m_pix);
XClearWindow(m_dpy,m_root);
Atom wmDeleteMessage=XInternAtom(m_dpy,“WM_DELETE_窗口”,False);
XSetWMProtocols(m_dpy、m_root和wmDeleteMessage,1);
XMapWindow(m_dpy,m_root);
XFlush(m_dpy);
睡眠(5);
XUnmapWindow(mudpy,muroot);
}

而且这个程序可以在hello world上引起轰动,因为我不知道如何跳出这个程序,而(!done)这么多thx给你

g++-o测试\u chr测试\u chr.cpp-lX11

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

int main(void)
{
    Display *d;
    Window w;
    XEvent e;
    const char *msg = "Hello, World!";
    int s;
    bool done = false;

    /* open connection with the server */
    d = XOpenDisplay(NULL);
    if (d == NULL)
    {
        fprintf(stderr, "Cannot open display\n");
        exit(1);
    }
    s = DefaultScreen(d);

    /* create window */
    w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 480, 320, 0,BlackPixel(d, s), WhitePixel(d, s));
    Atom type = XInternAtom(d,"_NET_WM_WINDOW_TYPE", False);
    Atom value = XInternAtom(d,"_NET_WM_WINDOW_TYPE_SPLASH", False);
    XChangeProperty(d, w, type, XA_ATOM, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&value), 1);
    /* register interest in the delete window message */
    Atom wmDeleteMessage = XInternAtom(d, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(d, w, &wmDeleteMessage, 1);

    /* select kind of events we are interested in */
    XSelectInput(d, w, ExposureMask | KeyPressMask | StructureNotifyMask);

    /* map (show) the window */
    XMapWindow(d, w);
    /* event loop */
    while (!done)
    {
        XNextEvent(d, &e);
        /* draw or redraw the window */
        if (e.type == Expose)
        {
            XDrawString(d, w, DefaultGC(d, s), 50, 50, msg, strlen(msg));
        }

        /* exit on key press */
        switch(e.type)
        {
        case KeyPress:
            XDestroyWindow(d, w);

        break;

        case DestroyNotify:
            done = true;
        break;

        case ClientMessage:
            if (e.xclient.data.l[0] == wmDeleteMessage)
            {
                done = true;
            }
        break;
        }
    }
    /* close connection to server */
    XCloseDisplay(d);

    return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
内部主(空)
{
显示*d;
窗口w;
XEvent e;
const char*msg=“你好,世界!”;
int-s;
bool done=false;
/*打开与服务器的连接*/
d=XOpenDisplay(空);
如果(d==NULL)
{
fprintf(stderr,“无法打开显示\n”);
出口(1);
}
s=默认屏幕(d);
/*创建窗口*/
w=XCreateSimpleWindow(d,根窗口(d,s),10,10,480,320,0,黑色像素(d,s),白色像素(d,s));
原子类型=XInternAtom(d,“\u NET\u WM\u WINDOW\u type”,False);
原子值=XInternAtom(d,“\u NET\u WM\u WINDOW\u TYPE\u SPLASH”,False);
XChangeProperty(d、w、类型、XA_原子、32、PropModeReplace、reinterpret_cast(&value)、1);
/*在删除窗口消息中注册兴趣*/
Atom wmDeleteMessage=XInternAtom(d,“WM_DELETE_窗口”,False);
XSetWMProtocols(d、w和wmDeleteMessage,1);
/*选择我们感兴趣的活动类型*/
XSelectInput(d、w、曝光蒙版|按键蒙版|结构通知蒙版);
/*绘制(显示)窗口地图*/
XMapWindow(d,w);
/*事件循环*/
而(!完成)
{
XNextEvent(d和e);
/*画或重画
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(void)
{
    Display *d;
    Window w;
    XEvent e;
    const char *msg = "Hello, World!";
    int s;
    bool done = false;

    /* open connection with the server */
    d = XOpenDisplay(NULL);
    if (d == NULL)
    {
        fprintf(stderr, "Cannot open display\n");
        exit(1);
    }
    s = DefaultScreen(d);

    /* create window */
    w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 480, 320, 0,BlackPixel(d, s), WhitePixel(d, s));
    Atom type = XInternAtom(d,"_NET_WM_WINDOW_TYPE", False);
    Atom value = XInternAtom(d,"_NET_WM_WINDOW_TYPE_SPLASH", False);
    XChangeProperty(d, w, type, XA_ATOM, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&value), 1);
    /* register interest in the delete window message */
    Atom wmDeleteMessage = XInternAtom(d, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(d, w, &wmDeleteMessage, 1);

    /* select kind of events we are interested in */
    XSelectInput(d, w, ExposureMask | KeyPressMask | StructureNotifyMask);

    /* map (show) the window */
    XMapWindow(d, w);
    /* event loop */
    while (!done)
    {
        XNextEvent(d, &e);
        /* draw or redraw the window */
        if (e.type == Expose)
        {
            XDrawString(d, w, DefaultGC(d, s), 50, 50, msg, strlen(msg));
        }

        /* exit on key press */
        switch(e.type)
        {
        case KeyPress:
            XDestroyWindow(d, w);

        break;

        case DestroyNotify:
            done = true;
        break;

        case ClientMessage:
            if (e.xclient.data.l[0] == wmDeleteMessage)
            {
                done = true;
            }
        break;
        }
    }
    /* close connection to server */
    XCloseDisplay(d);

    return 0;
}