#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);
}

 

最新文章

  1. js无刷新上传文件
  2. maven工程引用外部jar包
  3. Python将文本生成二维码
  4. 正则指引-量词demo
  5. 关于json 的那些知识点
  6. 项目解析- JspLibrary - part2
  7. Error initializing endpoint java.lang.Exception: Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í??
  8. virtualenv python虚拟环境搭建
  9. spring 切面 前置后置通知 环绕通知demo
  10. 利用 Composer 完善自己的 PHP 框架(一)——视图装载
  11. Dev 等待提示 WaitDialogForm 升级版
  12. Jquery zTree的使用
  13. Is Fibo
  14. Python爬虫 正则表达式
  15. mysql 存储ip地址
  16. 跟随我在oracle学习php(18)
  17. gitlab 安装和使用
  18. java_28 序列化与反序列化
  19. bat命令查询硬件信息
  20. day11_python_1124

热门文章

  1. 反射_Class对象功能概述-反射_Class对象功能_获取Field
  2. Java 进阶P-4.4+P-4.5
  3. Scanner概述-Scanner使用步骤
  4. Vue06 数据绑定
  5. springBoot集成flowable
  6. .NET Core MongoDB的简单使用
  7. javascript的防抖与节流
  8. JZOJ 5352. 【NOIP2017提高A组模拟9.7】计数题
  9. Hexo系列(三):Hexo主题
  10. .NET周报 【2月第4期 2023-02-25】