using System;
using System.Runtime.InteropServices;
using System.Text;
namespace DI_Electrical.Views.CustomControl
{
public static class Win32
{
public const string
User32 = "user32.dll",
Gdi32 = "gdi32.dll",
GdiPlus = "gdiplus.dll",
Kernel32 = "kernel32.dll",
Shell32 = "shell32.dll",
MsImg = "msimg32.dll",
NTdll = "ntdll.dll",
DwmApi = "dwmapi.dll",
Winmm = "winmm.dll",
Shcore = "Shcore.dll";
//查找窗口的委托 查找逻辑
public delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr lParam);
[DllImport(User32)]
public static extern IntPtr FindWindow(string className, string winName);
[DllImport(User32)]
public static extern IntPtr SendMessageTimeout(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam,
uint fuFlage, uint timeout, IntPtr result);
[DllImport(User32)]
public static extern bool EnumWindows(EnumWindowsProc proc, IntPtr lParam);
[DllImport(User32)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string className,
string winName);
[DllImport(User32)]
public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport(User32)]
public static extern IntPtr SetParent(IntPtr hwnd, IntPtr parentHwnd);
[DllImport(User32)]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport(User32)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport(User32)]
public static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport(User32)]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport(Winmm)]
public static extern long mciSendString(string strCommand, StringBuilder strReturn,
int iReturnLength, IntPtr hwndCallback);
#region WINAPI DLL Imports
[DllImport(Gdi32, ExactSpelling = true, PreserveSig = true, SetLastError = true)]
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
[DllImport(Gdi32)]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
[DllImport(Gdi32, SetLastError = true)]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport(Gdi32)]
public static extern bool DeleteObject(IntPtr hObject);
[DllImport(Gdi32)]
public static extern IntPtr CreateBitmap(int nWidth, int nHeight, uint cPlanes, uint cBitsPerPel,
IntPtr lpvBits);
[DllImport(User32)]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport(User32)]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport(Gdi32, EntryPoint = "DeleteDC")]
public static extern IntPtr DeleteDC(IntPtr hDc);
public const int SM_CXSCREEN = 0;
public const int SM_CYSCREEN = 1;
[DllImport(User32, EntryPoint = "GetDesktopWindow")]
public static extern IntPtr GetDesktopWindow();
[DllImport(User32, EntryPoint = "GetSystemMetrics")]
public static extern int GetSystemMetrics(int abc);
[DllImport(User32, EntryPoint = "GetWindowDC")]
public static extern IntPtr GetWindowDC(int ptr);
public struct DeskTopSize
{
public int cx;
public int cy;
}
public enum TernaryRasterOperations : uint
{
/// dest = source
SRCCOPY = 0x00CC0020,
/// dest = source OR dest
SRCPAINT = 0x00EE0086,
/// dest = source AND dest
SRCAND = 0x008800C6,
/// dest = source XOR dest
SRCINVERT = 0x00660046,
/// dest = source AND (NOT dest)
SRCERASE = 0x00440328,
/// dest = (NOT source)
NOTSRCCOPY = 0x00330008,
/// dest = (NOT src) AND (NOT dest)
NOTSRCERASE = 0x001100A6,
/// dest = (source AND pattern)
MERGECOPY = 0x00C000CA,
/// dest = (NOT source) OR dest
MERGEPAINT = 0x00BB0226,
/// dest = pattern
PATCOPY = 0x00F00021,
/// dest = DPSnoo
PATPAINT = 0x00FB0A09,
/// dest = pattern XOR dest
PATINVERT = 0x005A0049,
/// dest = (NOT dest)
DSTINVERT = 0x00550009,
/// dest = BLACK
BLACKNESS = 0x00000042,
/// dest = WHITE
WHITENESS = 0x00FF0062
}
[DllImport(Gdi32)]
public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc,
int nXSrc, int nYSrc, TernaryRasterOperations dwRop);
#endregion
///
/// 设置鼠标的坐标
///
/// 横坐标
/// 纵坐标
[DllImport(User32)]
public extern static void SetCursorPos(int x, int y);
}
}