📄 notifywindowmanager.cs
字号:
namespace Imps.Client.Pc.BizControls.NotifyWindows
{
using Imps.Client.Utils.Win32;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
public static class NotifyWindowManager
{
private static PopupDirection direction = PopupDirection.Up;
private static List<NotifyWindowBase> notifyWindowList = new List<NotifyWindowBase>();
private static int padding = 0x11;
private static Point startPoint = Point.Empty;
private static Rectangle taskbarBound;
private static TaskbarPosition taskbarPosition;
private static Rectangle workAreaRectangle;
public static void Add(NotifyWindowBase notifyWindow)
{
workAreaRectangle = Screen.GetWorkingArea(workAreaRectangle);
int num = notifyWindowList.get_Count();
notifyWindowList.Add(notifyWindow);
if (num == 0)
{
taskbarPosition = FindTaskbarPosition();
direction = (taskbarPosition == TaskbarPosition.Top) ? PopupDirection.Down : PopupDirection.Up;
switch (taskbarPosition)
{
case TaskbarPosition.Top:
startPoint = new Point((workAreaRectangle.Right - notifyWindow.RealWidth) - padding, workAreaRectangle.Top + 1);
goto Label_01AA;
case TaskbarPosition.Right:
case TaskbarPosition.Bottom:
startPoint = new Point((workAreaRectangle.Right - notifyWindow.RealWidth) - padding, workAreaRectangle.Bottom - 1);
goto Label_01AA;
case TaskbarPosition.Left:
startPoint = new Point(workAreaRectangle.Left + padding, workAreaRectangle.Bottom - 1);
goto Label_01AA;
}
}
else
{
startPoint.X = (taskbarPosition == TaskbarPosition.Left) ? (workAreaRectangle.Left + padding) : ((workAreaRectangle.Right - notifyWindow.RealWidth) - padding);
if (direction == PopupDirection.Up)
{
if ((notifyWindow.RealHeight * 2) > startPoint.Y)
{
DisposeNotifyWindow(notifyWindow);
return;
}
startPoint.Y -= notifyWindow.RealHeight + 1;
}
else
{
if ((notifyWindow.RealHeight + startPoint.Y) > workAreaRectangle.Height)
{
DisposeNotifyWindow(notifyWindow);
return;
}
startPoint.Y += notifyWindow.RealHeight - 1;
}
}
Label_01AA:
notifyWindow.PopupHide += new EventHandler(NotifyWindowManager.notifyWindow_PopupHide);
notifyWindow.add_FormClosed(new FormClosedEventHandler(null, (IntPtr) notifyWindow_PopupHide));
notifyWindow.Notify(startPoint, direction);
}
public static void Clear()
{
for (int i = notifyWindowList.get_Count() - 1; i >= 0; i--)
{
NotifyWindowBase notifyWindow = notifyWindowList.get_Item(i);
if (notifyWindow != null)
{
notifyWindow.Hide();
}
DisposeNotifyWindow(notifyWindow);
}
}
private static void DisposeNotifyWindow(NotifyWindowBase notifyWindow)
{
if (notifyWindow != null)
{
notifyWindowList.Remove(notifyWindow);
if (!notifyWindow.IsDisposed)
{
notifyWindow.Dispose();
}
}
}
private static TaskbarPosition FindTaskbarPosition()
{
TaskbarPosition bottom = TaskbarPosition.Bottom;
IntPtr hWnd = Imps.Client.Utils.Win32.NativeMethods.FindWindow("Shell_TrayWnd", null);
if (hWnd == IntPtr.Zero)
{
return TaskbarPosition.Bottom;
}
Size primaryMonitorSize = SystemInformation.PrimaryMonitorSize;
if (!Imps.Client.Utils.Win32.NativeMethods.GetWindowRectangle(hWnd, out taskbarBound))
{
return bottom;
}
if ((taskbarBound.X > 0) || (taskbarBound.Y > 0))
{
if (taskbarBound.X > 0)
{
return TaskbarPosition.Right;
}
return TaskbarPosition.Bottom;
}
if (Math.Abs((int) (taskbarBound.Width - primaryMonitorSize.Width)) < 10)
{
return TaskbarPosition.Top;
}
return TaskbarPosition.Left;
}
private static void notifyWindow_PopupHide(object sender, EventArgs e)
{
NotifyWindowBase notifyWindow = sender as NotifyWindowBase;
if (notifyWindow != null)
{
DisposeNotifyWindow(notifyWindow);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -