win7下如何把alpha透明窗口嵌入桌面

win7下如何把alpha透明窗口嵌入桌面,第1张

下面这么多步,可完美让程序兼容于WIN7的AERO主题

DesktopHandle := Winapi.Windows.FindWindow('Progman', 'Program Manager')

DesktopHandle := FindWindowEx(desktopHandle, 0, 'SHELLDLL_DefView', nil)

DesktopHandle := FindWindowEx(desktopHandle, 0, 'SysListView32', 'FolderView')

if (DesktopHandle= 0) then begin

DesktopHandle := Winapi.Windows.FindWindow('Progman', 'Program Manager')

DesktopHandle := DesktopHandle+ 2

DesktopHandle := FindWindowEx(DesktopHandle, 0, 'SysListView32', 'FolderView')

end

Winapi.Windows.SetParent(FMHWnd, DesktopHandle)

你看看你的嵌入函数对不对

using System

using System.Windows.Forms

using System.Runtime.InteropServices

namespace ShowInDesk

{

    public partial class Form1 : Form

    {

        IntPtr hDesktop

        public const int GW_CHILD = 5

        public Form1()

        {

            InitializeComponent()

            this.hDesktop = GetDesktopHandle(DesktopLayer.Progman)

            EmbedDesktop(this, this.Handle, this.hDesktop)

            //isMouseDown = false

        }

        public IntPtr GetDesktopHandle(DesktopLayer layer)

        {

            //hWnd = new HandleRef()

            HandleRef hWnd

            IntPtr hDesktop = new IntPtr()

            switch (layer)

            {

                case DesktopLayer.Progman:

                    hDesktop = Win32Support.FindWindow("Progman", null)//第一层桌面

                    break

                case DesktopLayer.SHELLDLL:

                    hDesktop = Win32Support.FindWindow("Progman", null)//第一层桌面

                    hWnd = new HandleRef(this, hDesktop)

                    hDesktop = Win32Support.GetWindow(hWnd, GW_CHILD)//第2层桌面

                    break

                case DesktopLayer.FolderView:

                    hDesktop = Win32Support.FindWindow("Progman", null)//第一层桌面

                    hWnd = new HandleRef(this, hDesktop)

                    hDesktop = Win32Support.GetWindow(hWnd, GW_CHILD)//第2层桌面

                    hWnd = new HandleRef(this, hDesktop)

                    hDesktop = Win32Support.GetWindow(hWnd, GW_CHILD)//第3层桌面

                    break

            }

            return hDesktop

        }

        public void EmbedDesktop(Object embeddedWindow, IntPtr childWindow, IntPtr parentWindow)

        {

            Form window = (Form)embeddedWindow

            HandleRef HWND_BOTTOM = new HandleRef(embeddedWindow, new IntPtr(1))

            const int SWP_FRAMECHANGED = 0x0020//发送窗口大小改变消息

            Win32Support.SetParent(childWindow, parentWindow)

            Win32Support.SetWindowPos(new HandleRef(window, childWindow), HWND_BOTTOM, 300, 300, window.Width, window.Height, SWP_FRAMECHANGED)

        }

    }

}

namespace ShowInDesk

{

    class Win32Support

    {

        [DllImport("user32.dll", CharSet = CharSet.Auto)]

        public static extern IntPtr FindWindow(string className, string windowName)

        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]

        public static extern IntPtr GetWindow(HandleRef hWnd, int nCmd)

        [DllImport("user32.dll")]

        public static extern IntPtr SetParent(IntPtr child, IntPtr parent)

        [DllImport("user32.dll", EntryPoint = "GetDCEx", CharSet = CharSet.Auto, ExactSpelling = true)]

        public static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, int flags)

        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]

        public static extern bool SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter, int x, int y, int cx, int cy, int flags)

        [DllImport("user32.dll")]

        public static extern int ReleaseDC(IntPtr window, IntPtr handle)

    }

}

namespace ShowInDesk

{

    public enum DesktopLayer

    {

        Progman = 0,

        SHELLDLL = 1,

        FolderView = 2

    }

}

你获取句柄的方法好像没什么问题,关键看你取到句柄后具体要做什么 *** 作?

我在MFC 中试了一下,没有问题 ,把桌面关闭掉

HWND  desktopHwnd = ::FindWindowEx( ::FindWindowEx( ::FindWindow(L"Progman", L"Program Manager"), NULL, L"SHELLDLL_DefView", NULL), NULL, L"SysListView32", L"FolderView" )

::SendMessage( desktopHwnd,WM_CLOSE,0,0  )


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11057708.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-13
下一篇 2023-05-13

发表评论

登录后才能评论

评论列表(0条)

保存