c#中借助API函数使窗口置顶
来源:互联网 发布:淘宝连锁店 编辑:程序博客网 时间:2024/06/01 10:35
由于以前做一个小程序,想把窗口置顶,其实这个技术已经不是难题了,以前在VB中也是借助于API函数。但在C#中没想用API函数,至今没找到好办法,最后还得借助于API函数。
片断代如下:
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
/// <summary>
/// 得到当前活动的窗口
/// </summary>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern System.IntPtr GetForegroundWindow();
哪个窗体想要置顶,在Form_Load中加上
SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2); //最后参数也有用1 | 4
具体说明,看API函数说明
如果是用点击一个按钮后弹出新窗体,并置顶,则:
Form2 frm = new Form2();
frm.Show();
SetWindowPos(GetForegroundWindow(), -1, 0, 0, 0, 0, 1 | 2);
这样,新打开的窗体就是置顶了。呵
片断代如下:
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
/// <summary>
/// 得到当前活动的窗口
/// </summary>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern System.IntPtr GetForegroundWindow();
哪个窗体想要置顶,在Form_Load中加上
SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2); //最后参数也有用1 | 4
具体说明,看API函数说明
如果是用点击一个按钮后弹出新窗体,并置顶,则:
Form2 frm = new Form2();
frm.Show();
SetWindowPos(GetForegroundWindow(), -1, 0, 0, 0, 0, 1 | 2);
这样,新打开的窗体就是置顶了。呵
- c#中借助API函数使窗口置顶
- 在C#中调用windows API函数 最大、最小化窗口
- vb窗口置顶函数
- [置顶] MFC中获取窗口句柄及相关函数
- C# SetWindowPos窗口置顶使用说明
- 使用Qt4本身的函数使窗口置顶
- Visual Basic 借助API找窗口和子窗口
- win api 窗口操作-窗口置顶与寻找与激活
- 窗口置顶/取消置顶
- c#调用API函数拖动无标题窗口及控件
- C#调用API函数EnumWindows枚举窗口的方法
- C#调用API函数EnumWindows枚举窗口的方法
- opencv中窗口置顶的方法
- VC中置顶窗口的方法
- opencv中窗口置顶的方法
- 窗口置顶
- 窗口置顶
- 窗口置顶
- 笔记本安装Vista-xp双系统详解
- 特征驱动开发FDD
- 用Excel轻松制作春节联欢抽奖系统
- 背包问题
- DF
- c#中借助API函数使窗口置顶
- LINUX 硬链接与软链接的区别
- 风云三国游戏检测
- 正式支持大文件上传--艾恩asp文件上传组件
- jquery 插件
- WINCE中编辑框(CEdit)的“奇怪现象”
- JavaScript页面刷新与弹出窗口问题解决方法
- 新起点
- DataSet导出到Excel比较完整的解决方案(二)--服务器端生成文件(downmoon)