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

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

  

 

1
2
3
4
5
6
7
8
9
[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);

  

1
2
3
4
5
6
7
8
9
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);

  

posted @   liulun  阅读(5987)  评论(4编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
点击右上角即可分享
微信分享提示