C# 设置桌面为父窗口
2024-09-08 19:08:18
#region 设置桌面为父窗口
IntPtr hDesktop;
public const int GW_CHILD = 5; 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);
} private void button1_Click(object sender, EventArgs e)
{ } 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);
} public enum DesktopLayer
{
Progman = 0,
SHELLDLL = 1,
FolderView = 2
}
#endregion
public Form1()
{
InitializeComponent();
this.hDesktop = GetDesktopHandle(DesktopLayer.Progman);
EmbedDesktop(this, this.Handle, this.hDesktop);
}
最新文章
- js无刷新上传文件
- maven工程引用外部jar包
- Python将文本生成二维码
- 正则指引-量词demo
- 关于json 的那些知识点
- 项目解析- JspLibrary - part2
- Error initializing endpoint java.lang.Exception: Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í??
- virtualenv python虚拟环境搭建
- spring 切面 前置后置通知 环绕通知demo
- 利用 Composer 完善自己的 PHP 框架(一)——视图装载
- Dev 等待提示 WaitDialogForm 升级版
- Jquery zTree的使用
- Is Fibo
- Python爬虫 正则表达式
- mysql 存储ip地址
- 跟随我在oracle学习php(18)
- gitlab 安装和使用
- java_28 序列化与反序列化
- bat命令查询硬件信息
- day11_python_1124