Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 更换桌面壁纸/在桌面上绘图_Wpf_Windows_Desktop_Wallpaper - Fatal编程技术网

Wpf 更换桌面壁纸/在桌面上绘图

Wpf 更换桌面壁纸/在桌面上绘图,wpf,windows,desktop,wallpaper,Wpf,Windows,Desktop,Wallpaper,我想在我的windows桌面上做一些自定义绘图,这样它看起来会取代桌面背景(墙纸)。我的第一次尝试是为desktopListView获取一个DC并绘制到它: IntPtr desktopDC = GetWindowDC(desktopListView); Graphics g = Graphics.FromHwnd(desktopDC); //<-- fails on out of memory error IntPtr desktopDC=GetWindowDC(desktopList

我想在我的windows桌面上做一些自定义绘图,这样它看起来会取代桌面背景(墙纸)。我的第一次尝试是为
desktopListView
获取一个DC并绘制到它:

IntPtr desktopDC = GetWindowDC(desktopListView);
Graphics g = Graphics.FromHwnd(desktopDC); //<-- fails on out of memory error
IntPtr desktopDC=GetWindowDC(desktopListView);

Graphics g=Graphics.FromHwnd(桌面DC)// 如果获得桌面的窗口句柄,则可以创建一个新窗口,并将自己的自定义窗口添加为该窗口的子窗口。把它放在列表视图后面可能会给你你需要的结果,尽管我不能100%确定透明度会有多好

找到一些代码-如果您不需要处理多个改变形状的屏幕,那么您需要的大部分代码都在第一部分中

    public void SetDesktopWindows()
    {
        Thread.Sleep(0);
        while (this.Count < Screen.AllScreens.Length)
        {
            OrangeGuava.Desktop.DesktopWindow.DesktopControl dtc = new OrangeGuava.Desktop.DesktopWindow.DesktopControl();
            User32.SetParent(dtc.Handle, User32.FindWindow("ProgMan", null));
            this.Add(dtc);

        }

        int minx = 0;
        int miny = 0;

        foreach (Screen screen in Screen.AllScreens)
        {               
            if (screen.Bounds.Left < minx) minx = screen.Bounds.Left;
            if (screen.Bounds.Top < miny) miny = screen.Bounds.Top;
        }

        for (int i = Screen.AllScreens.Length; i < Count; i++)
        {
            OrangeGuava.Desktop.DesktopWindow.DesktopControl dtc = (OrangeGuava.Desktop.DesktopWindow.DesktopControl)this[i];
            dtc.Hide();
        }

        for (int i = 0; i < Screen.AllScreens.Length; i++)
        {
            OrangeGuava.Desktop.DesktopWindow.DesktopControl dtc = (OrangeGuava.Desktop.DesktopWindow.DesktopControl)this[i];
            dtc.DeviceId = i.ToString();


            Rectangle r = Screen.AllScreens[i].WorkingArea;
            r.X -= minx;
            r.Y -= miny;



            dtc.SetBounds(r.X, r.Y, r.Width, r.Height);

            dtc.displaySettingsChanged(null, null);


        }

    }
public void SetDesktopWindows()
{
睡眠(0);
while(this.Count
我通过设置
WINDOWPOS.hWndInsertAfter=HWND\u BOTTOM
让我的窗口响应
WM\u WINDOWPOSCHANGING
消息来实现这一点。这对操作系统说:确保“我的窗口”位于所有其他窗口的下方,并使其看起来像您的窗口粘在桌面上一样。

谢谢-您能告诉我如何将子窗口附加到现有窗口中吗?我看不到任何明显的API函数可以做到这一点。这都是pinvoke的东西-我做这件事已经有几年了,但我认为您希望查找sethwndparent或setwindow。创建表单并作为桌面listview的子级添加似乎几乎可以。表单位于所有其他窗口下方,但仍位于图标上方。你知道如何让它真正成为背景/墙纸的背面吗?我为之编写的程序正在替换图标,所以这个问题没有出现。您可能希望将窗体设置为列表视图父级的子级,然后设置zindex将其置于列表视图后面。这会产生一个稍微不同的结果-您的窗口将位于桌面的任何子窗口前面,我相信show desktop功能将使其消失。