Squashed 'NotifyIconWpf/' content from commit f64d48e
git-subtree-dir: NotifyIconWpf git-subtree-split: f64d48ec604eef26e5dc1e7c2d5e1e91b329ffac
This commit is contained in:
91
NotifyIconWpf/Interop/WinApi.cs
Normal file
91
NotifyIconWpf/Interop/WinApi.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
||||
{
|
||||
/// <summary>
|
||||
/// Win32 API imports.
|
||||
/// </summary>
|
||||
internal static class WinApi
|
||||
{
|
||||
private const string User32 = "user32.dll";
|
||||
|
||||
/// <summary>
|
||||
/// Creates, updates or deletes the taskbar icon.
|
||||
/// </summary>
|
||||
[DllImport("shell32.Dll", CharSet = CharSet.Unicode)]
|
||||
public static extern bool Shell_NotifyIcon(NotifyCommand cmd, [In] ref NotifyIconData data);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates the helper window that receives messages from the taskar icon.
|
||||
/// </summary>
|
||||
[DllImport(User32, EntryPoint = "CreateWindowExW", SetLastError = true)]
|
||||
public static extern IntPtr CreateWindowEx(int dwExStyle, [MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
|
||||
[MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, int dwStyle, int x, int y,
|
||||
int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance,
|
||||
IntPtr lpParam);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Processes a default windows procedure.
|
||||
/// </summary>
|
||||
[DllImport(User32)]
|
||||
public static extern IntPtr DefWindowProc(IntPtr hWnd, uint msg, IntPtr wparam, IntPtr lparam);
|
||||
|
||||
/// <summary>
|
||||
/// Registers the helper window class.
|
||||
/// </summary>
|
||||
[DllImport(User32, EntryPoint = "RegisterClassW", SetLastError = true)]
|
||||
public static extern short RegisterClass(ref WindowClass lpWndClass);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a listener for a window message.
|
||||
/// </summary>
|
||||
/// <param name="lpString"></param>
|
||||
/// <returns>uint</returns>
|
||||
[DllImport(User32, EntryPoint = "RegisterWindowMessageW")]
|
||||
public static extern uint RegisterWindowMessage([MarshalAs(UnmanagedType.LPWStr)] string lpString);
|
||||
|
||||
/// <summary>
|
||||
/// Used to destroy the hidden helper window that receives messages from the
|
||||
/// taskbar icon.
|
||||
/// </summary>
|
||||
/// <param name="hWnd"></param>
|
||||
/// <returns>bool</returns>
|
||||
[DllImport(User32, SetLastError = true)]
|
||||
public static extern bool DestroyWindow(IntPtr hWnd);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gives focus to a given window.
|
||||
/// </summary>
|
||||
/// <param name="hWnd"></param>
|
||||
/// <returns>bool</returns>
|
||||
[DllImport(User32)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum number of milliseconds that can elapse between a
|
||||
/// first click and a second click for the OS to consider the
|
||||
/// mouse action a double-click.
|
||||
/// </summary>
|
||||
/// <returns>The maximum amount of time, in milliseconds, that can
|
||||
/// elapse between a first click and a second click for the OS to
|
||||
/// consider the mouse action a double-click.</returns>
|
||||
[DllImport(User32, CharSet = CharSet.Auto, ExactSpelling = true)]
|
||||
public static extern int GetDoubleClickTime();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the screen coordinates of the current mouse position.
|
||||
/// </summary>
|
||||
[DllImport(User32, SetLastError = true)]
|
||||
public static extern bool GetPhysicalCursorPos(ref Point lpPoint);
|
||||
|
||||
|
||||
[DllImport(User32, SetLastError = true)]
|
||||
public static extern bool GetCursorPos(ref Point lpPoint);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user