geboshi_V1/LeatherProject/LeatherApp/API.cs

347 lines
16 KiB
C#
Raw Normal View History

2024-03-07 14:03:22 +08:00
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;
namespace LeatherApp
{
public class API
{
[StructLayout(LayoutKind.Sequential)]
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;//lpData大小
public IntPtr lpData;
}
public const int WM_COPYDATA = 0x004A;
public const int WM_CLOSE = 0x10;
//定义常数用作函数StretechBlt中正常色彩复制的光栅操作码
public const int Srccopy = 0xCC0020;
//'定义常数用作函数StretechBlt中反色复制的光栅操作码
public const int NotSrccopy = 0x330008;
//定义常数用作函数SetWindowPos中使窗口位于所有窗口最上面一层避免被其它窗口遮挡
public const int HWND_TOPMOST = -1;
public const int SWP_NOMOVE = 2;
public const int SWP_NOSIZE = 1;
public const int SWP_NOACTIVATE = 0x10;
public const int HWND_TOP = 0;
public const int HWND_NOTOPMOST = -2;
//SetStretchBltMode模式
public const int STRETCH_ANDSCANS = 1;
public const int STRETCH_DELETESCANS = 3;
public const int STRETCH_ORSCANS = 2;
public const int STRETCH_HALFTONE = 4;
//
[DllImport("User32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
public const int WS_SHOWNORMAL = 1;
[DllImport("shell32.dll")]
public static extern int ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);
[DllImport("user32.dll")]
public static extern IntPtr GetActiveWindow();
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern bool IsWindow(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern int GetClassName(IntPtr hwnd, StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll")]
public static extern int DrawText(IntPtr hdc, string lpStr, int nCount, RECT lpRect, int wFormat);
public const int DT_CENTER = 0x1;
public const int DT_BOTTOM = 0x8;
public const int DT_SINGLELINE = 0x20;
public const int GWL_STYLE = -16;
public const UInt32 WS_MINIMIZEBOX = 0x20000;
public const UInt32 WS_MAXIMIZEBOX = 0x10000;
public const UInt32 WS_SYSMENU = 0x80000;
public const UInt32 WS_CAPTION = 0xC00000;
public const int GWL_EXSTYLE = -20;
public const int LWA_COLORKEY = 1;
public const int LWA_ALPHA = 2;
public const int WS_EX_LAYERED = 0x80000;
[DllImport("user32.dll")]
public static extern UInt32 GetWindowLong(IntPtr hwnd, int nIndex);
[DllImport("user32.dll")]
public static extern UInt32 SetWindowLong(IntPtr hwnd, int nIndex, UInt32 dwNewLong);
[DllImport("user32.dll")]
public static extern UInt32 SetLayeredWindowAttributes(IntPtr hwnd, int cKey, int bAlpha, int dwFlags);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeleteFile(string lpFileName);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CopyFile(string lpExistingFileName, string lpNewFileName, bool bFailIfExists);
//窗体拖动
public const UInt32 WM_SYSCOMMAND = 0x112;
public const UInt32 SC_MOVE = 0xF010;
public const UInt32 HTCAPTION = 0x2;
[DllImport("user32.dll")]
public static extern UInt32 ReleaseCapture();
[DllImport("user32.dll")]
public static extern UInt32 SendMessage(IntPtr hWnd, UInt32 wMsg, UInt32 wParam, IntPtr lParam);
[DllImport("user32.dll")]//函数声明,用于将窗口置于最上方
public static extern int SetWindowPos(IntPtr hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
[DllImport("user32.dll")]//函数声明,用于获得整个屏幕的窗口句柄,以作为绘制的源
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]//函数声明,用于用于获得指定窗口一个设备环境。
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("gdi32.dll")]//
public static extern int SetStretchBltMode(IntPtr hdc, int nStretchMode);
[DllImport("gdi32.dll")]//函数声明,用于将屏幕任意位置的一个矩形位置复制到另一个位置并实现镜像翻转
public static extern int StretchBlt(IntPtr hdc, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, int dwRop);
[DllImport("user32.dll")]//函数声明,释放窗口的设备环境
public static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
//最前显示4个
[DllImport("user32.dll")]
public static extern int SetActiveWindow(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern int SetFocus(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern int BringWindowToTop(IntPtr hwnd);
//
[DllImport("user32.dll")]
public static extern IntPtr LoadCursorFromFile(string lpFileName);
[DllImport("user32.dll")]
public static extern IntPtr SetCursor(IntPtr cursorHandle);
[DllImport("user32.dll")]
public static extern uint DestroyCursor(IntPtr cursorHandle);
public struct POINTAPI
{
public int x;
public int y;
}
[DllImport("user32.dll")]
public static extern int SetCursorPos(int x, int y);
[DllImport("user32.dll")]
public static extern int GetCursorPos(ref POINTAPI lpPoint);
[DllImport("user32.dll")]
public static extern IntPtr GetCursor();
public struct ICONINFO
{
public bool fIcon; // Specifies whether this structure defines an icon or a cursor. A value of TRUE specifies
public Int32 xHotspot; // Specifies the x-coordinate of a cursor's hot spot. If this structure defines an icon, the hot
public Int32 yHotspot; // Specifies the y-coordinate of the cursor's hot spot. If this structure defines an icon, the hot
public IntPtr hbmMask; // (HBITMAP) Specifies the icon bitmask bitmap. If this structure defines a black and white icon,
public IntPtr hbmColor; // (HBITMAP) Handle to the icon color bitmap. This member can be optional if this
}
public struct CURSORINFO
{
public Int32 cbSize;
public Int32 flags;
public Int32 hCursor;
public POINTAPI ptScreenPos;
}
[DllImport("user32.dll", EntryPoint = "GetIconInfo")]
public static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO piconinfo);
[DllImport("user32.dll")]
public static extern bool GetCursorInfo(out CURSORINFO pci);
[DllImport("user32.dll")]
public static extern bool DrawIcon(IntPtr hDC, int X, int Y, IntPtr hIcon);
public const int DI_MASK = 0x0001;
public const int DI_IMAGE = 0x0002;
public const int DI_NORMAL = 0x0003;
public const int DI_COMPAT = 0x0004;
public const int DI_DEFAULTSIZE = 0x0008;
[DllImport("user32.dll")]
public static extern int DrawIconEx(IntPtr hdc, int xLeft, int yTop, IntPtr hIcon, int cxWidth, int cyWidth, int istepIfAniCur, int hbrFlickerFreeDraw, int diFlags);
[DllImport("gdi32.dll")]
public static extern int DeleteObject(IntPtr hObject);
[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(int xPoint, int yPoint);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
[DllImport("kernel32.dll")]
public static extern IntPtr GetCurrentThreadId();
[DllImport("user32.dll")]
public static extern int AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, bool fAttach);
[DllImport("user32.dll")]
public static extern int MoveWindow(IntPtr hwnd, int x, int y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32.dll")]
public static extern bool IsZoomed(IntPtr hwnd);//判断窗口是否为最大化
[DllImport("user32.dll")]
public static extern bool IsIconic(IntPtr hwnd);//判断窗口是否为最小化
//控制播放器
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("kernel32.dll")]
public static extern void Sleep(int i);
[DllImport("User32.dll", EntryPoint = "PostMessage")]
public static extern int PostMessage(
IntPtr hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
public const int WM_USER = 0x0400;
public const int WMU_WLQ = WM_USER + 88;
public const int PARA_PLAY = 0x1;
public const int PARA_STOP = 0x2;
public const int PARA_FULL = 0x4;
public const int PARA_MIN = 0x8;
public const int PARA_MAX = 0x10;
public const int PARA_MOVEL = 0x20;
public const int PARA_MOVER = 0x40;
//
//播放器消息命令:
public const int PLAYER_PLAY = WM_USER + 0x0001;//播放
public const int PLAYER_BREAK = WM_USER + 0x0002;//暂停
public const int PLAYER_FULL = WM_USER + 0x0004;//全屏
public const int PLAYER_NOFULL = WM_USER + 0x0008;//退出全屏
public const int PLAYER_STOP = WM_USER + 0x0010;//停止
public const int PLAYER_EXIT = WM_USER + 0x0020;//退出
public const int PLAYER_SHOW = WM_USER + 0x0040;//显示窗体
public const int PLAYER_HIDE = WM_USER + 0x0080;//隐藏窗体
public const int PLAYER_PLAY_FULL = WM_USER + 0x0021;//播放并全屏
public const int PLAYER_BREAK_HIDE = WM_USER + 0x0022;//暂停并隐藏
//
public const int SW_HIDE = 0;
public const int SW_SHOWNORMAL = 1;
public const int SW_NORMAL = 1;
public const int SW_SHOWMINIMIZED = 2;
public const int SW_SHOWMAXIMIZED = 3;
public const int SW_MAXIMIZE = 3;
public const int SW_SHOWNOACTIVATE = 4;
public const int SW_SHOW = 5;
public const int SW_MINIMIZE = 6;
public const int SW_SHOWMINNOACTIVE = 7;
public const int SW_SHOWNA = 8;
public const int SW_RESTORE = 9;
public const int SW_SHOWDEFAULT = 10;
public const int SW_FORCEMINIMIZE = 11;
public const int SW_MAX = 11;
//自定义消息
public const int WM_MOVENEXT = WM_USER + 5;//dsd纸用、电信最初屏幕上签名版本[to副屏]
public const int WM_MOVEFIRST = WM_USER + 6;//dsd纸用、电信最初屏幕上签名版本[to主屏]
public const int WM_MOVENEXT1 = WM_USER + 7;//电信最新[切屏]到副屏
public const int WM_MOVEFIRST1 = WM_USER + 8;//电信最新[签名完成]到主屏
public const int WM_ShowSignWin = WM_USER + 10;//电信最新[打印小票]弹出半透明窗口(扩展屏)
public const int WM_HideSignWin = WM_USER + 11;//电信最新[半透明窗口左上角对号图片按钮](扩展屏)
public const int WM_ShowSignWin2 = WM_USER + 12;//电信最新[打印小票]弹出半透明窗口(主屏)
public const int WM_HideSignWin2 = WM_USER + 13;//电信最新[半透明窗口左上角对号图片按钮](主屏)
public const int WM_LookPrimaryScreen = WM_USER + 20;//电信最新[副屏监视主屏]
public const int WM_UnLookPrimaryScreen = WM_USER + 21;//电信最新[取消副屏监视主屏]
//声明读写INI文件的API函数
[DllImport("kernel32")]
public static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
//
public const UInt32 MF_BYPOSITION = 0x400;
public const UInt32 MF_BYCOMMAND = 0x0;
public const UInt32 SC_CLOSE = 0xF060;
public const UInt32 SC_MAXIMIZE = 0xF030;
public const UInt32 SC_MINIMIZE = 0xF020;
public const UInt32 WS_EX_APPWINDOW = 0x40000;
[DllImport("user32.dll")]
public static extern IntPtr GetSystemMenu(IntPtr hwnd, bool bRevert);
[DllImport("user32.dll")]
public static extern int RemoveMenu(IntPtr hMenu, UInt32 nPosition, UInt32 wFlags);
[DllImport("user32.dll")]
public static extern int ModifyMenu(IntPtr hMenu, int nPosition, int wFlags, int wIDNewItem, int lpString);
[DllImport("user32.dll")]
public static extern UInt32 SetWindowText(IntPtr hwnd, string lpString);
public struct RECT
{
public RECT(int _left, int _top, int _right, int _bottom)
{
Left = _left;
Top = _top;
Right = _right;
Bottom = _bottom;
}
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[DllImport("user32.dll")]
public static extern int GetWindowRect(IntPtr hwnd, out API.RECT lpRect);
[DllImport("user32.dll")]
public static extern int ClipCursor(RECT lpRect);
public const int WM_KEYDOWN = 0x100;
public const int WM_KEYUP = 0x101;
//HOT KEY
[DllImport("kernel32.dll")]
public static extern uint GlobalAddAtom(string lpHotKeyName);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool RegisterHotKey(
IntPtr hWnd, //要定义热键的窗口的句柄
uint id, //定义热键ID不能与其它ID重复
KeyModifiers fsModifiers, //标识热键是否在按Alt、Ctrl、Shift、Windows等键时才会生效
System.Windows.Forms.Keys vk //定义热键的内容
);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool UnregisterHotKey(
IntPtr hWnd, //要取消热键的窗口的句柄
uint id //要取消热键的ID
);
//定义了辅助键的名称(将数字转变为字符以便于记忆,也可去除此枚举而直接使用数值)
[Flags()]
public enum KeyModifiers
{
None = 0,
Alt = 1,
Ctrl = 2,
Shift = 4,
WindowsKey = 8
}
//====================
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
//标题栏厚度
public const int SM_CYCAPTION = 4;
//边框宽度
public const int SM_CYBORDER = 6;
[DllImport("user32.dll", SetLastError = true)]
public static extern int GetSystemMetrics(int nIndex);
[DllImport("kernel32.dll")]
public static extern void OutputDebugString(string lpOutputString);
}
}