C#将窗口嵌入桌面

一、先上代码

static class Win32
{
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("User32.dll", EntryPoint = "SetParent")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("user32", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2);

}

IntPtr pWnd = Win32.FindWindow("Progman", "Program Manager");
pWnd = Win32.FindWindowEx(pWnd, IntPtr.Zero, "SHELLDLL_DefView", null);
pWnd = Win32.FindWindowEx(pWnd, IntPtr.Zero, "SysListView32", null);
Win32.SetParent(Handle, pWnd);

二、用上面的代码可以成功,但开启“桌面整理工具”后,上面的代码执行无效。

1. 查找原因,用spy++工具查看进程,正常的"Program Manager",请看下图

 

 

2. 开启“桌面整理工具”后,用spy++工具查看进程,请看下图

 

 

 3.问题分析:开启“桌面整理工具”后,它会将"Program Manager"进程名称修改成"WorkerW"。然后新建两个空进程,并命名成"WorkerW"和"Program Manager"。

4.解决办法:关闭“桌面整理工具”,重启“explorer.exe”进程。

 

posted @   ghome83  阅读(360)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示