// Author: Gockner, Simon // Created: 2021-04-06 // Copyright(c) 2021 SimonG. All Rights Reserved. using System; using System.Runtime.InteropServices; using Lib.NotifyIcon.Windows.Native.Types; using Point = Lib.NotifyIcon.Windows.Native.Types.Point; namespace Lib.NotifyIcon.Windows.Native { internal static class WindowApi { public delegate IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); [DllImport("shell32", CharSet = CharSet.Auto)] public static extern int Shell_NotifyIcon(NIM dwMessage, NotifyIconData lpData); [DllImport("user32.dll")] public static extern void PostQuitMessage(int nExitCode); [DllImport("user32.dll", ExactSpelling = true)] public static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] public static extern IntPtr CreatePopupMenu(); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern bool AppendMenu(IntPtr hMenu, MenuFlags uFlags, uint uIdNewItem, string lpNewItem); [DllImport("user32.dll")] public static extern uint TrackPopupMenuEx(IntPtr hMenu, UFlags uFlags, int x, int y, IntPtr hWnd, IntPtr lpTpm); [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr CreateWindowEx( int dwExStyle, uint lpClassName, string lpWindowName, uint dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam); [DllImport("user32.dll", EntryPoint = "DefWindowProcW")] public static extern IntPtr DefWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", SetLastError = true)] public static extern bool DestroyWindow(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool GetCursorPos(out Point lpPoint); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "RegisterClassExW")] public static extern ushort RegisterClassEx(ref WndClassEx lpWcx); [return: MarshalAs(UnmanagedType.Bool)] [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "PostMessageW")] public static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); [DllImport("kernel32.dll")] public static extern IntPtr GetModuleHandle(string lpModuleName); } }