winform 获取NotifyIcon的位置
来源:互联网 发布:好看的网络自制剧穿越 编辑:程序博客网 时间:2024/06/07 07:22
Winform 获取NotifyIcon的位置
主要代码:
public class NotifyIconHelper{ public static Rectangle GetIconRect(NotifyIcon icon) { RECT rect = new RECT(); NOTIFYICONIDENTIFIER notifyIcon = new NOTIFYICONIDENTIFIER(); notifyIcon.cbSize = Marshal.SizeOf(notifyIcon); //use hWnd and id of NotifyIcon instead of guid is needed notifyIcon.hWnd = GetHandle(icon); notifyIcon.uID = GetId(icon); int hresult = Shell_NotifyIconGetRect(ref notifyIcon, out rect); //rect now has the position and size of icon return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); } [StructLayout(LayoutKind.Sequential)] private struct RECT { public Int32 left; public Int32 top; public Int32 right; public Int32 bottom; } [StructLayout(LayoutKind.Sequential)] private struct NOTIFYICONIDENTIFIER { public Int32 cbSize; public IntPtr hWnd; public Int32 uID; public Guid guidItem; } [DllImport("shell32.dll", SetLastError = true)] private static extern int Shell_NotifyIconGetRect([In]ref NOTIFYICONIDENTIFIER identifier, [Out]out RECT iconLocation); private static FieldInfo windowField = typeof(NotifyIcon).GetField("window", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); private static IntPtr GetHandle(NotifyIcon icon) { if (windowField == null) throw new InvalidOperationException("[Useful error message]"); NativeWindow window = windowField.GetValue(icon) as NativeWindow; if (window == null) throw new InvalidOperationException("[Useful error message]"); // should not happen? return window.Handle; } private static FieldInfo idField = typeof(NotifyIcon).GetField("id", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); private static int GetId(NotifyIcon icon) { if (idField == null) throw new InvalidOperationException("[Useful error message]"); return (int)idField.GetValue(icon); }}
参考资料:
1、https://stackoverflow.com/questions/26153810/get-the-applications-notifyicon-rectangle
2、http://pinvoke.net/default.aspx/shell32.Shell_NotifyIconGetRect
阅读全文
0 0
- winform 获取NotifyIcon的位置
- winform 获取鼠标的位置
- WinForm:系统托盘NotifyIcon
- C# WinForm中NotifyICon控件的用法【1】
- C# WinForm中NotifyICon控件的用法【2】
- 做WinForm程序,在通知区域加入NotifyIcon,程序退出后不消失的解决
- 获取winform任意位置点击事件
- NotifyIcon的应用
- NotifyIcon
- winform中坐标系转换的问题,获取某点在屏幕中的绝对位置等
- Winform 单例模式 如果有相同的程序在运行 notifyIcon气泡提示 “程序正在运行,我在这儿”
- Winform 单例模式 如果有相同的程序在运行 notifyIcon气泡提示 “程序正在运行,我在这儿”
- NotifyIcon(托盘的实现)
- Winform托盘NotifyIcon使用(类似QQ消息提示)
- C#WinForm程序设计——系统托盘NotifyIcon控件
- c# winform notifyIcon 系统托盘图标闪动 气泡提示
- WPF ,利用Winform库中的NotifyIcon实现托盘小程序
- C# winform中使窗体最小化(NotifyIcon)
- Java用户自定义异常Exception处理
- [算法与数据结构]
- datacleaner第四部分,11、12、13、14章
- iOS蓝牙开发:蓝牙连接和数据读写
- APP混淆后Cookie不能正确保存的解决办法
- winform 获取NotifyIcon的位置
- tcp no delay
- 表情符合正则工具类
- 原型链继承
- Xamarin.Android开发入门——Hello,Android深入理解
- Linux安装mysql及删除
- 基于电信业务的第三方测试服务实践
- 新书《Cocos2dx 3.x 3D图形学渲染技术讲解》问世
- 利用c标签根据list数据源进行表格布局