渲染到桌面

发布于 2024-12-04 21:19:11 字数 138 浏览 2 评论 0原文

我希望能够将某个东西渲染成壁纸一样。我使用 Windows,并且更喜欢 DirectX。我知道VLC可以在DirectX模式下渲染带有壁纸的视频,所以这是可能的。

那么,一个简单的问题是,如何将渲染目标设置为像 Windows 中的壁纸一样渲染?

I want to be able to render a thing as if it was a wallpaper. I use Windows, and I prefer DirectX. I know that VLC can render the video has a wallpaper in DirectX mode, so it's possible.

So, a quick question, How could I set the rendertarget to render like if it was a wallpaper in Windows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

败给现实 2024-12-11 21:19:11

下面是一些代码,它们将为您提供一个窗口的句柄(HWND),该窗口可用于在 Windows 桌面上进行绘制。其工作原理的主要问题是桌面图标仍然存在,但这将允许您在它们之上进行绘制。如果您希望图标正常显示(您的内容在它们后面),您需要在绘制内容后重新绘制它们,或者找到一种方法来避免首先绘制它们。这是相当重要的,也是我从未完全解决的问题。

这绝对适用于 XP 和 Windows 7(带有 Areo),以获得普通 GDI 绘图可以使用的东西。我从未使用 DirectX 测试过它,但我怀疑如果您使用 hMainWnd 作为演示窗口,它会起作用。

HWND hProgMan = NULL;
HWND hShell = NULL;
HWND hMainWnd = NULL;
unsigned int ScreenWidth = 0;
unsigned int ScreenHeight = 0;
int ScreenTop = 0;
int ScreenLeft = 0;
HRGN ValidRGN = NULL;

// ...

    ScreenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
    if ( ScreenWidth == 0 ) 
        ScreenWidth = GetSystemMetrics( SM_CXSCREEN );

    ScreenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
    if ( ScreenHeight == 0 ) 
        ScreenHeight = GetSystemMetrics(SM_CYSCREEN);

    ScreenTop = GetSystemMetrics(SM_YVIRTUALSCREEN);
    ScreenLeft = GetSystemMetrics(SM_XVIRTUALSCREEN);

    ValidRGN = CreateRectRgn(0,0,ScreenWidth,ScreenHeight);

    hProgMan = FindWindow("Progman", "Program Manager");
    if(hProgMan != NULL)
    {
        hShell = FindWindowEx(hProgMan, 0, "SHELLDLL_DefView", NULL);
    }
    else
    {
        hProgMan = FindWindow("DesktopBackgroundClass", NULL);
        if(hProgMan != NULL)
            hShell = FindWindowEx(hProgMan, 0, "DeskFolder", NULL);
    }

    hMainWnd = CreateWindowEx( WS_EX_TRANSPARENT, "MyWindowClass", "Window Title", WS_CHILDWINDOW | WS_OVERLAPPED | WS_CLIPCHILDREN, 0,0,ScreenWidth,ScreenHeight, hShell,NULL,hInstance,NULL );
    EnableWindow(hMainWnd,FALSE);
    SetWindowPos(hMainWnd,HWND_BOTTOM,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);

...然后进行绘图(使用 GDI),类似这样...

    HDC hDC = GetDC( hMainWnd );
    SelectClipRgn(hDC,ValidRGN);
    BitBlt( hDC, 0, 0, ScreenX, ScreenY, hBackBuffer, 0, 0, SRCCOPY );
    ReleaseDC( hMainWnd, hDC );

...并使用桌面图标的区域更新 ValidRGN 。通过对桌面的列表视图控制窗口进行一些操作就可以找到这些内容。这是相当复杂的,可能与这个问题无关。

Here is some code which will get you a handle (HWND) to a window that can be used to draw over top of the windows Desktop. The main issue with how this works is that the desktop icons are still present but this will allow you to draw over top of them. If you want the icons to appear as normal (with your stuff behind them) you need to redraw them after you've drawn your stuff, or find a way to avoid drawing over them in the first place. This is fairly non-trivial and something I never completely solved.

This definitely works on XP and Windows 7 (with Areo) for getting something that normal GDI drawing can use. I've never tested it with DirectX but I suspect it would work if you used hMainWnd as your presentation window.

HWND hProgMan = NULL;
HWND hShell = NULL;
HWND hMainWnd = NULL;
unsigned int ScreenWidth = 0;
unsigned int ScreenHeight = 0;
int ScreenTop = 0;
int ScreenLeft = 0;
HRGN ValidRGN = NULL;

// ...

    ScreenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
    if ( ScreenWidth == 0 ) 
        ScreenWidth = GetSystemMetrics( SM_CXSCREEN );

    ScreenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
    if ( ScreenHeight == 0 ) 
        ScreenHeight = GetSystemMetrics(SM_CYSCREEN);

    ScreenTop = GetSystemMetrics(SM_YVIRTUALSCREEN);
    ScreenLeft = GetSystemMetrics(SM_XVIRTUALSCREEN);

    ValidRGN = CreateRectRgn(0,0,ScreenWidth,ScreenHeight);

    hProgMan = FindWindow("Progman", "Program Manager");
    if(hProgMan != NULL)
    {
        hShell = FindWindowEx(hProgMan, 0, "SHELLDLL_DefView", NULL);
    }
    else
    {
        hProgMan = FindWindow("DesktopBackgroundClass", NULL);
        if(hProgMan != NULL)
            hShell = FindWindowEx(hProgMan, 0, "DeskFolder", NULL);
    }

    hMainWnd = CreateWindowEx( WS_EX_TRANSPARENT, "MyWindowClass", "Window Title", WS_CHILDWINDOW | WS_OVERLAPPED | WS_CLIPCHILDREN, 0,0,ScreenWidth,ScreenHeight, hShell,NULL,hInstance,NULL );
    EnableWindow(hMainWnd,FALSE);
    SetWindowPos(hMainWnd,HWND_BOTTOM,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);

... and then for drawing (using GDI), something like this...

    HDC hDC = GetDC( hMainWnd );
    SelectClipRgn(hDC,ValidRGN);
    BitBlt( hDC, 0, 0, ScreenX, ScreenY, hBackBuffer, 0, 0, SRCCOPY );
    ReleaseDC( hMainWnd, hDC );

... and update ValidRGN with the regions of the Desktop icons. Those can be found with a bit of work with the Desktop's listview control window. That is fairly complicated and maybe off topic for this question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文