Statistics
| Branch: | Revision:

root / trunk / NotifyIconWpf / Interop / WinApi.cs @ 9bae55d1

History | View | Annotate | Download (3.1 kB)

1
using System;
2
using System.Runtime.InteropServices;
3

    
4
namespace Hardcodet.Wpf.TaskbarNotification.Interop
5
{
6
  /// <summary>
7
  /// Win32 API imports.
8
  /// </summary>
9
  internal static class WinApi
10
  {
11
    /// <summary>
12
    /// Creates, updates or deletes the taskbar icon.
13
    /// </summary>
14
    [DllImport("shell32.Dll")]
15
    public static extern bool Shell_NotifyIcon(NotifyCommand cmd, [In]ref NotifyIconData data);
16

    
17

    
18
    /// <summary>
19
    /// Creates the helper window that receives messages from the taskar icon.
20
    /// </summary>
21
    [DllImport("USER32.DLL", EntryPoint = "CreateWindowExW", SetLastError = true)]
22
    public static extern IntPtr CreateWindowEx(int dwExStyle, [MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
23
                           [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, int dwStyle, int x, int y,
24
                           int nWidth, int nHeight, uint hWndParent, int hMenu, int hInstance,
25
                           int lpParam);
26

    
27

    
28
    /// <summary>
29
    /// Processes a default windows procedure.
30
    /// </summary>
31
    [DllImport("USER32.DLL")]
32
    public static extern long DefWindowProc(IntPtr hWnd, uint msg, uint wparam, uint lparam);
33
    
34
    /// <summary>
35
    /// Registers the helper window class.
36
    /// </summary>
37
    [DllImport("USER32.DLL", EntryPoint = "RegisterClassW", SetLastError = true)]
38
    public static extern short RegisterClass(ref WindowClass lpWndClass);
39

    
40
    /// <summary>
41
    /// Registers a listener for a window message.
42
    /// </summary>
43
    /// <param name="lpString"></param>
44
    /// <returns></returns>
45
    [DllImport("User32.Dll", EntryPoint = "RegisterWindowMessageW")]
46
    public static extern uint RegisterWindowMessage([MarshalAs(UnmanagedType.LPWStr)] string lpString);
47

    
48
    /// <summary>
49
    /// Used to destroy the hidden helper window that receives messages from the
50
    /// taskbar icon.
51
    /// </summary>
52
    /// <param name="hWnd"></param>
53
    /// <returns></returns>
54
    [DllImport("USER32.DLL", SetLastError = true)]
55
    public static extern bool DestroyWindow(IntPtr hWnd);
56

    
57

    
58
    /// <summary>
59
    /// Gives focus to a given window.
60
    /// </summary>
61
    /// <param name="hWnd"></param>
62
    /// <returns></returns>
63
    [DllImport("USER32.DLL")]
64
    public static extern bool SetForegroundWindow(IntPtr hWnd);
65

    
66

    
67
    /// <summary>
68
    /// Gets the maximum number of milliseconds that can elapse between a
69
    /// first click and a second click for the OS to consider the
70
    /// mouse action a double-click.
71
    /// </summary>
72
    /// <returns>The maximum amount of time, in milliseconds, that can
73
    /// elapse between a first click and a second click for the OS to
74
    /// consider the mouse action a double-click.</returns>
75
    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
76
    public static extern int GetDoubleClickTime();
77

    
78

    
79
    /// <summary>
80
    /// Gets the screen coordinates of the current mouse position.
81
    /// </summary>
82
    /// <param name="lpPoint"></param>
83
    /// <returns></returns>
84
    [DllImport("USER32.DLL", SetLastError = true)]
85
    public static extern bool GetCursorPos(ref Point lpPoint);
86
  }
87
}