C# WPF 让你的窗口始终钉在桌面上

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# WPF 让你的窗口始终钉在桌面上相关的知识,希望对你有一定的参考价值。

原文:C# WPF 让你的窗口始终钉在桌面上

            IntPtr hWnd = new WindowInteropHelper(Application.Current.MainWindow).Handle;
            IntPtr hWndProgMan = FindWindow("Progman", "Program Manager");
            SetParent(hWnd, hWndProgMan);

  

 

        [DllImport("user32.dll", SetLastError = true)]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpWindowClass, string lpWindowName);
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
        const int GWL_HWNDPARENT = -8;
        [DllImport("user32.dll")]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

  

 var handle = new WindowInteropHelper(Application.Current.MainWindow).Handle;
            IntPtr hprog = FindWindowEx(
                FindWindowEx(
                    FindWindow("Progman", "Program Manager"),
                    IntPtr.Zero, "SHELLDLL_DefView", ""
                ),
                IntPtr.Zero, "SysListView32", "FolderView"
            );
            SetWindowLong(handle, GWL_HWNDPARENT, hprog);

  

以上是关于C# WPF 让你的窗口始终钉在桌面上的主要内容,如果未能解决你的问题,请参考以下文章

WPF多窗口磁性对齐贴边功能实现

WPF运行中怎么用C# 代码调整窗口位置,特别是怎么居中到屏幕中央

WPF窗口嵌入在桌面的最底层

WPF 透明窗口在桌面上放虫子。。。

截屏时延迟 C# (WPF)

想让你的Mac桌面清爽整洁?试试Mac临时文件存储小助手Yoink