将一个WinForm设置到桌面上
来源:互联网 发布:深入浅出mysql 编辑:程序博客网 时间:2024/04/29 16:29
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
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 Form1_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 Form1_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设置到桌面上
- 如何将一个窗口订在桌面上
- 桌面上点击一个图标,链接到网页
- 桌面上Internet Explorer图标消失,怎样将Internet Explorer图标恢复到桌面上
- 无法使用程序将widget添加到桌面上
- 如何将无法显示的NTFS硬盘显示到桌面上
- 将XNA整合到WinForm
- 在服务里面弹出一个窗口到用户的桌面上
- WinForm特效:桌面上的遮罩层
- winform自定义组件创建失败——未将对象设置引用到实例
- WINFORM 使用datagridview取值时出现"未将对象引用设置到对象的实例
- winform中出现错误“未将对象引用设置到对象的实例”的原因
- winform下如何将一个xml文件缓存到内存中
- 将一个类设置到另一个类的快捷方式
- 桌面图标有蓝色阴影。Word里面的一个图片复制到桌面上后,桌面上的图标都有了蓝色阴影
- winform将窗体最小化到托盘
- winform将图片嵌入到exe
- C# winform 将dataGridView导出到excel
- 揭秘IT人才特点:中美印日四国程序员比较(引用)
- Socket编程(C#)
- Linux代理网关做Vpn
- 怎样添加右键菜单?
- MVC原理(struts框架详解)
- 将一个WinForm设置到桌面上
- 注册表的编写
- Asp.Net 缓存技术总结
- Internet上不同网段间的通信问题解析
- 支持Cacti运作的PHP+RRDtool环境配置方法 -1
- 产生不重复的随机数
- vim 删除所有空行
- ajax poller
- LoadRunner在性能测试工作中遇到的问题以及解决办法小结