更换桌面墙纸/在桌面上绘制 [英] Replacing desktop wallpaper / draw on the desktop

查看:100
本文介绍了更换桌面墙纸/在桌面上绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows桌面上进行一些自定义绘制,以便看起来可以代替桌面背景(墙纸)。我的第一个尝试是获取 desktopListView 的DC并吸引到它:

I'd like to do some custom drawing to my windows desktop such that it appears to replace the desktop background (wallpaper). My first try was to get a DC for desktopListView and draw to it:

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

然后我尝试创建NativeWindow并捕获 WM_PAINT 消息,方法是将本机窗口的句柄分配给桌面并执行自己的绘图,但是我看不到任何消息到桌面。

I then tried to create a NativeWindow and capture the WM_PAINT message by assigning the native window's handle to the desktop and do my own drawing, but I was unable to see any messages to the desktop.

理想情况下,我想在WPF中执行此操作,而不是Windows窗体。有什么线索可以创建一个我可以绘制的WPF窗口,该窗口位于桌面图标下方但在壁纸上方,因此它忽略了任何鼠标消息,并且桌面继续正常工作?

Ideally I'd like to do this in WPF and not windows forms at all. Any clue how to create a WPF window that I can draw to that sits beneath the desktop icons but on top of the wallpaper such that it ignores any mouse messages and the desktop continues to work normally?

推荐答案

如果您获得了桌面的窗口句柄,则可以创建一个新窗口并添加自己的自定义窗口作为其子窗口。将其放在列表视图的后面可能会为您提供所需的结果,尽管我不确定100%确定透明度的效果。

If you get the window handle of the desktop, you can create a new window and add your own custom window as a child of that. Putting it behind the list view may give you the result you need, though I'm not 100% sure how well the transparency will work.

找到了一些代码-大多数如果您不需要处理多个会改变形状的屏幕,那么您需要的是第一部分。

Found some code - Most of what you need is in the first part if you don't need to deal with multiple screens that change shape.

    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);


        }

    }

这篇关于更换桌面墙纸/在桌面上绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆