如何让你的WinForm嵌入桌面
2007-10-26 23:58
555 查看
首先, 调用一些User32.dll的WinAPI函数
internal class User32
...{
public const int SE_SHUTDOWN_PRIVILEGE = 0x13;
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx,
int cy, uint uFlags);
}
然后, 在WinForm里面
public MainForm()
...{
InitializeComponent();
try
...{
if (Environment.OSVersion.Version.Major < 6)
...{
base.SendToBack();
IntPtr hWndNewParent = User32.FindWindow("Progman", null);
User32.SetParent(base.Handle, hWndNewParent);
}
else
...{
User32.SetWindowPos(base.Handle, 1, 0, 0, 0, 0, User32.SE_SHUTDOWN_PRIVILEGE);
}
}
catch (ApplicationException exx)
...{
MessageBox.Show(this, exx.Message, "Pin to Desktop");
}
}
private void MainForm_Activated(object sender, EventArgs e)
...{
if (Environment.OSVersion.Version.Major >= 6)
...{
User32.SetWindowPos(base.Handle, 1, 0, 0, 0, 0, User32.SE_SHUTDOWN_PRIVILEGE);
}
}
private void MainForm_Paint(object sender, PaintEventArgs e)
...{
if (Environment.OSVersion.Version.Major >= 6)
...{
User32.SetWindowPos(base.Handle, 1, 0, 0, 0, 0, User32.SE_SHUTDOWN_PRIVILEGE);
}
}
internal class User32
...{
public const int SE_SHUTDOWN_PRIVILEGE = 0x13;
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx,
int cy, uint uFlags);
}
然后, 在WinForm里面
public MainForm()
...{
InitializeComponent();
try
...{
if (Environment.OSVersion.Version.Major < 6)
...{
base.SendToBack();
IntPtr hWndNewParent = User32.FindWindow("Progman", null);
User32.SetParent(base.Handle, hWndNewParent);
}
else
...{
User32.SetWindowPos(base.Handle, 1, 0, 0, 0, 0, User32.SE_SHUTDOWN_PRIVILEGE);
}
}
catch (ApplicationException exx)
...{
MessageBox.Show(this, exx.Message, "Pin to Desktop");
}
}
private void MainForm_Activated(object sender, EventArgs e)
...{
if (Environment.OSVersion.Version.Major >= 6)
...{
User32.SetWindowPos(base.Handle, 1, 0, 0, 0, 0, User32.SE_SHUTDOWN_PRIVILEGE);
}
}
private void MainForm_Paint(object sender, PaintEventArgs e)
...{
if (Environment.OSVersion.Version.Major >= 6)
...{
User32.SetWindowPos(base.Handle, 1, 0, 0, 0, 0, User32.SE_SHUTDOWN_PRIVILEGE);
}
}
相关文章推荐
- 【转】如何让你的WinForm嵌入桌面
- 如何让你的WinForm嵌入桌面窗口最底层
- 【转】C#如何让WinForm嵌入桌面窗口最底层
- C# Dsoframer.ocx 如何在winform中嵌入Excel,内嵌Excel,word
- 如何在Office12嵌入winform程序和添加Ribbon
- 把WINFORM嵌入IE如何带上app.config?
- C#.net Winform 如何将窗体嵌入Panle中
- C# 如何在winform中嵌入Excel,内嵌Excel,word
- WinForm程序如何将子窗体嵌入到父窗体的Panel里
- php网页如何调用桌面应用程序C# winform
- C#中winform窗体如何嵌入cmd命令窗口
- WinForm程序如何将子窗体嵌入到父窗体的Panel里
- 介绍一下如何在桌面背景里面嵌入一个shell
- 如何将一个Winform嵌入到一个Control当中
- CCF问题集合2:CCF集成winform应用,如何嵌入CCF的mainPanel
- 【转载】WinForm中如何进行获取【嵌入资源】
- winform安装项目如何在桌面创建快捷方式
- C# 如何在winform中嵌入Excel,内嵌Excel,word
- Matlab函数产生的Figure图形框如何嵌入C# Winform中的一个Panel中?
- 把Winform程序窗口嵌入到桌面