private static bool TryGetNotifyIconIdentifier(NotifyIcon notifyIcon, out NOTIFYICONIDENTIFIER identifier) { identifier = new NOTIFYICONIDENTIFIER() { cbSize = (uint)Marshal.SizeOf(typeof(NOTIFYICONIDENTIFIER)) }; int id; if (!TryGetNonPublicFieldValue(notifyIcon, "id", out id)) { return(false); } NativeWindow window; if (!TryGetNonPublicFieldValue(notifyIcon, "window", out window)) { return(false); } identifier.uID = (uint)id; identifier.hWnd = window.Handle; return(true); }
private NOTIFYICONIDENTIFIER GetNotifyIconIdentifier() { // Ugly hacks here var result = new NOTIFYICONIDENTIFIER(); result.uID = (uint)(int)_notifyIconIdField.GetValue(_notifyIcon); var window = (NativeWindow)_notifyIconWindowField.GetValue(_notifyIcon); result.hWnd = window.Handle; result.cbSize = (uint)Marshal.SizeOf(result); return(result); }
public static RG GetIconRect(NotifyIcon icon) { RECT rect = new RECT(); NOTIFYICONIDENTIFIER notifyIcon = new NOTIFYICONIDENTIFIER(); notifyIcon.cbSize = Marshal.SizeOf(notifyIcon); notifyIcon.hWnd = GetHandle(icon); notifyIcon.uID = GetId(icon); int hresult = Shell_NotifyIconGetRect(ref notifyIcon, out rect); return(new RG(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top)); }
public static Rectangle GetIconRect(NotifyIcon icon) { 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 var 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)); }
internal static RECT GetNotifyIconArea(IDisposable notifyicon) { var field = notifyicon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance); var num = (int)field.GetValue(notifyicon); var fieldInfo = notifyicon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance); var window = (NativeWindow)fieldInfo.GetValue(notifyicon); var notifyiconidentifier2 = new NOTIFYICONIDENTIFIER { hWnd = window.Handle, uID = (uint)num }; notifyiconidentifier2.cbSize = (uint)Marshal.SizeOf(notifyiconidentifier2); RECT rect; Shell_NotifyIconGetRect(ref notifyiconidentifier2, out rect); return(rect); }
private static Point GetNotifyIconPosition(IDisposable notifyicon) { var field = notifyicon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance); var num = (int)field.GetValue(notifyicon); var fieldInfo = notifyicon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance); var window = (NativeWindow)fieldInfo.GetValue(notifyicon); var notifyiconidentifier2 = new NOTIFYICONIDENTIFIER { hWnd = window.Handle, uID = (uint)num }; notifyiconidentifier2.cbSize = (uint)Marshal.SizeOf(notifyiconidentifier2); RECT rect; Shell_NotifyIconGetRect(ref notifyiconidentifier2, out rect); return(new Point(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2)); }
public static RECT GetNotifyIconRect(NotifyIcon icon) { var rect = new RECT(); var notifyIcon = new NOTIFYICONIDENTIFIER { cbSize = (uint)Marshal.SizeOf(typeof(NOTIFYICONIDENTIFIER)), hWnd = GetHandle(icon), uID = GetId(icon) }; var result = Shell_NotifyIconGetRect(ref notifyIcon, out rect); if (result != WinError.S_OK) { throw new Win32Exception(result); } return(rect); }
public static Rectangle GetNotifyIconRectangle(NotifyIcon notifyIcon) { if (!OperatingSystem.GteWindows7) { return(new Rectangle(0, 0, 0, 0)); } NOTIFYICONIDENTIFIER _notifyIconIdentifier = new NOTIFYICONIDENTIFIER(); _notifyIconIdentifier.cbSize = (uint)Marshal.SizeOf(_notifyIconIdentifier); _notifyIconIdentifier.hWnd = GetHandle(notifyIcon); _notifyIconIdentifier.uID = (uint)GetUID(notifyIcon); RECT _notifyIconLocation = new RECT(); Shell_NotifyIconGetRect(ref _notifyIconIdentifier, out _notifyIconLocation); return(Rectangle.FromLTRB(_notifyIconLocation.left, _notifyIconLocation.top, _notifyIconLocation.right, _notifyIconLocation.bottom)); }
/// <summary> /// Gets position of the tray icon on the screen /// </summary> /// <returns>Position of the tray icon on the screen</returns> /// <remarks>Works only on Win7 and later. Will return <see cref="Cursor.Position"/> when running on earlier OS</remarks> public Point GetIconPosition() { var ident = new NOTIFYICONIDENTIFIER { cbSize = (uint)Marshal.SizeOf(typeof(NOTIFYICONIDENTIFIER)), hWnd = _ownerForm.Handle, uID = (uint)_id }; //ident.guidItem = guid; // don't know why, but setting GUID produces "The parameter is incorrect" HRESULT var rect = new Rectangle(); var result = Shell_NotifyIconGetRect(ref ident, ref rect); if (result != 0) { throw new Win32Exception(result); } return(new Point(rect.Left, rect.Top)); }
public static RECT GetNotifyIconLocation(NotifyIcon notifyIcon) { FieldInfo idFieldInfo = notifyIcon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance); int iconid = (int)idFieldInfo.GetValue(notifyIcon); FieldInfo windowFieldInfo = notifyIcon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance); NativeWindow nativeWindow = (NativeWindow)windowFieldInfo.GetValue(notifyIcon); IntPtr iconhandle = nativeWindow.Handle; RECT rect = new RECT(); NOTIFYICONIDENTIFIER nid = new NOTIFYICONIDENTIFIER() { hWnd = iconhandle, uID = (uint)iconid }; nid.cbSize = (uint)Marshal.SizeOf(nid); int result = Shell_NotifyIconGetRect(ref nid, out rect); return(rect); }
public static Rect?GetNotifyIconRectangle(NotifyIcon notifyicon) { // get notify icon id FieldInfo idFieldInfo = notifyicon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance); int iconid = (int)idFieldInfo.GetValue(notifyicon); // get notify icon hwnd FieldInfo windowFieldInfo = notifyicon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance); System.Windows.Forms.NativeWindow nativeWindow = (System.Windows.Forms.NativeWindow)windowFieldInfo.GetValue(notifyicon); IntPtr iconhandle = nativeWindow.Handle; if (iconhandle == IntPtr.Zero) { return(null); } RECT rect = new RECT(); NOTIFYICONIDENTIFIER nid = new NOTIFYICONIDENTIFIER() { hWnd = iconhandle, uID = (uint)iconid }; nid.cbSize = (uint)Marshal.SizeOf(nid); int result = Shell_NotifyIconGetRect(ref nid, out rect); // 0 means success, 1 means the notify icon is in the fly-out - either is fine if (result != 0 && result != 1) { return(null); } // convert to System.Rect and return return(rect); }
public static extern int Shell_NotifyIconGetRect(ref NOTIFYICONIDENTIFIER identifier, out RECT iconLocation);
internal static RECT GetNotifyIconArea(IDisposable notifyicon) { var field = notifyicon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance); var num = (int)field.GetValue(notifyicon); var fieldInfo = notifyicon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance); var window = (NativeWindow)fieldInfo.GetValue(notifyicon); var notifyiconidentifier2 = new NOTIFYICONIDENTIFIER { hWnd = window.Handle, uID = (uint)num }; notifyiconidentifier2.cbSize = (uint)Marshal.SizeOf(notifyiconidentifier2); RECT rect; Shell_NotifyIconGetRect(ref notifyiconidentifier2, out rect); return rect; }
public int[] GetRectangle() { RECT rect = new RECT(); NOTIFYICONIDENTIFIER nid = new NOTIFYICONIDENTIFIER() { hWnd = iconData.WindowHandle, uID = (uint)iconData.TaskbarIconId }; nid.cbSize = (uint)Marshal.SizeOf(nid); Shell_NotifyIconGetRect(ref nid, out rect); int[] result = new int[4]; result[0] = rect.Bottom; result[1] = rect.Top; result[2] = rect.Left; result[3] = rect.Right; return result; }
private static extern int Shell_NotifyIconGetRect(ref NOTIFYICONIDENTIFIER identifier, out RECT iconLocation);
private static extern Int32 Shell_NotifyIconGetRect([In] ref NOTIFYICONIDENTIFIER identifier, [Out] out RECT iconLocation);
public static extern int Shell_NotifyIconGetRect([In] ref NOTIFYICONIDENTIFIER identifier, [Out] out RectStruct iconLocation);
private static Point GetNotifyIconPosition(IDisposable notifyicon) { var field = notifyicon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance); var num = (int) field.GetValue(notifyicon); var fieldInfo = notifyicon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance); var window = (NativeWindow) fieldInfo.GetValue(notifyicon); var notifyiconidentifier2 = new NOTIFYICONIDENTIFIER {hWnd = window.Handle, uID = (uint) num}; notifyiconidentifier2.cbSize = (uint) Marshal.SizeOf(notifyiconidentifier2); RECT rect; Shell_NotifyIconGetRect(ref notifyiconidentifier2, out rect); return new Point(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); }