mirror of
https://github.com/ckaczor/wpf-notifyicon.git
synced 2026-02-16 11:08:30 -05:00
WPF NotifyIcon : Public Release
------------------------------- CHG Common cleanup, copyright etc. DEL Removed unused dependency property change handlers. ADD Added ResetBalloonCloseTimer method which keeps custom balloons open. ADD Provided implementation for attached BalloonClosingEvent. git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@94 9f600761-6f11-4665-b6dc-0185e9171623
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
||||
|
||||
|
||||
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
||||
{
|
||||
/// <summary>
|
||||
/// Event flags for clicked events.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
|
||||
|
||||
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
||||
{
|
||||
|
||||
172
Source/NotifyIconWpf/Interop/TrayInfo.cs
Normal file
172
Source/NotifyIconWpf/Interop/TrayInfo.cs
Normal file
@@ -0,0 +1,172 @@
|
||||
// Interop code taken from Mike Marshall's AnyForm
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
||||
{
|
||||
/// <summary>
|
||||
/// Resolves the current tray position.
|
||||
/// </summary>
|
||||
public static class TrayInfo
|
||||
{
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern Int32 GetWindowLong(IntPtr hWnd, Int32 Offset);
|
||||
|
||||
|
||||
public static Point GetTrayLocation()
|
||||
{
|
||||
var info = new AppBarInfo();
|
||||
info.GetSystemTaskBarPosition();
|
||||
|
||||
Rectangle rcWorkArea = info.WorkArea;
|
||||
|
||||
int x = 0, y = 0;
|
||||
if (info.Edge == AppBarInfo.ScreenEdge.Left)
|
||||
{
|
||||
x = rcWorkArea.Left + 2;
|
||||
y = rcWorkArea.Bottom;
|
||||
}
|
||||
else if (info.Edge == AppBarInfo.ScreenEdge.Bottom)
|
||||
{
|
||||
x = rcWorkArea.Right;
|
||||
y = rcWorkArea.Bottom;
|
||||
}
|
||||
else if (info.Edge == AppBarInfo.ScreenEdge.Top)
|
||||
{
|
||||
x = rcWorkArea.Right;
|
||||
y = rcWorkArea.Top;
|
||||
}
|
||||
else if (info.Edge == AppBarInfo.ScreenEdge.Right)
|
||||
{
|
||||
x = rcWorkArea.Right;
|
||||
y = rcWorkArea.Bottom;
|
||||
}
|
||||
|
||||
return new Point { X = x, Y = y};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
internal class AppBarInfo
|
||||
{
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
private static extern UInt32 SHAppBarMessage(UInt32 dwMessage, ref APPBARDATA data);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern Int32 SystemParametersInfo(UInt32 uiAction, UInt32 uiParam,
|
||||
IntPtr pvParam, UInt32 fWinIni);
|
||||
|
||||
|
||||
private const int ABE_BOTTOM = 3;
|
||||
private const int ABE_LEFT = 0;
|
||||
private const int ABE_RIGHT = 2;
|
||||
private const int ABE_TOP = 1;
|
||||
|
||||
private const int ABM_GETTASKBARPOS = 0x00000005;
|
||||
|
||||
// SystemParametersInfo constants
|
||||
private const UInt32 SPI_GETWORKAREA = 0x0030;
|
||||
|
||||
private APPBARDATA m_data;
|
||||
|
||||
public ScreenEdge Edge
|
||||
{
|
||||
get { return (ScreenEdge) m_data.uEdge; }
|
||||
}
|
||||
|
||||
|
||||
public Rectangle WorkArea
|
||||
{
|
||||
get
|
||||
{
|
||||
Int32 bResult = 0;
|
||||
var rc = new RECT();
|
||||
IntPtr rawRect = Marshal.AllocHGlobal(Marshal.SizeOf(rc));
|
||||
bResult = SystemParametersInfo(SPI_GETWORKAREA, 0, rawRect, 0);
|
||||
rc = (RECT) Marshal.PtrToStructure(rawRect, rc.GetType());
|
||||
|
||||
if (bResult == 1)
|
||||
{
|
||||
Marshal.FreeHGlobal(rawRect);
|
||||
return new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
|
||||
}
|
||||
|
||||
return new Rectangle(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void GetPosition(string strClassName, string strWindowName)
|
||||
{
|
||||
m_data = new APPBARDATA();
|
||||
m_data.cbSize = (UInt32) Marshal.SizeOf(m_data.GetType());
|
||||
|
||||
IntPtr hWnd = FindWindow(strClassName, strWindowName);
|
||||
|
||||
if (hWnd != IntPtr.Zero)
|
||||
{
|
||||
UInt32 uResult = SHAppBarMessage(ABM_GETTASKBARPOS, ref m_data);
|
||||
|
||||
if (uResult != 1)
|
||||
{
|
||||
throw new Exception("Failed to communicate with the given AppBar");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Failed to find an AppBar that matched the given criteria");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void GetSystemTaskBarPosition()
|
||||
{
|
||||
GetPosition("Shell_TrayWnd", null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public enum ScreenEdge
|
||||
{
|
||||
Undefined = -1,
|
||||
Left = ABE_LEFT,
|
||||
Top = ABE_TOP,
|
||||
Right = ABE_RIGHT,
|
||||
Bottom = ABE_BOTTOM
|
||||
}
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct APPBARDATA
|
||||
{
|
||||
public UInt32 cbSize;
|
||||
public IntPtr hWnd;
|
||||
public UInt32 uCallbackMessage;
|
||||
public UInt32 uEdge;
|
||||
public RECT rc;
|
||||
public Int32 lParam;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct RECT
|
||||
{
|
||||
public Int32 left;
|
||||
public Int32 top;
|
||||
public Int32 right;
|
||||
public Int32 bottom;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,29 @@
|
||||
using System;
|
||||
// hardcodet.net NotifyIcon for WPF
|
||||
// Copyright (c) 2009 Philipp Sumi
|
||||
// Contact and Information: http://www.hardcodet.net
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the Code Project Open License (CPOL);
|
||||
// either version 1.0 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE
|
||||
|
||||
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user