📄 win32.cs
字号:
[DllImport(USER32)]
public static extern int GetDC(IntPtr hWnd);
[DllImport(USER32)]
public static extern bool ReleaseDC(IntPtr hWnd, int hDC);
public delegate void TimerProc(IntPtr hWnd, uint nMsg, int nIDEvent, int dwTime);
[DllImport(USER32)]
public static extern int SetTimer(IntPtr hWnd, int nIDEvent, int uElapse, TimerProc callback);
[DllImport(USER32)]
public static extern bool KillTimer(IntPtr hWnd, int nIDEvent);
[DllImport(USER32)]
public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rw);
[DllImport(USER32)]
public static extern bool GetClientRect(IntPtr hWnd, ref RECT rc);
[DllImport(USER32, EntryPoint = "PostMessageA")] // Win32 encapsulation
public static extern int PostMessage(IntPtr hWnd, uint dwMsg, uint wParam, int lParam);
[DllImport(USER32)]
public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, int crKey, byte bAlpha, int dwFlags);
[DllImport(USER32)]
public static extern IntPtr GetDesktopWindow();
[DllImport(USER32)]
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool bRepaint);
[DllImport(USER32)]
public static extern bool SetWindowPos(
IntPtr hWnd, // window handle
IntPtr hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
uint uFlags); // window positioning flags
[DllImport(USER32)]
public static extern bool IsWindow(IntPtr hWnd);
[DllImport(USER32, EntryPoint = "GetClassLongA")]
public static extern int GetClassLong(IntPtr hWnd, int nIndex);
[DllImport(USER32, EntryPoint = "SetClassLongA")]
public static extern int SetClassLong(IntPtr hWnd, int nIndex, int lNewLong);
[DllImport(USER32)] // Win32 encapsulation
public static extern bool GetWindowRgn(IntPtr hWnd, IntPtr hRgn);
[DllImport(GDI32)] // Win32 encapsulation
public static extern IntPtr CreateRectRgn(int x1, int y1, int x2, int y2);
[DllImport(USER32)] // Win32 encapsulation
public static extern bool SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);
[DllImport(GDI32)] // Win32 encapsulation
public static extern bool OffsetRgn(IntPtr hRgn, int x, int y);
[DllImport(GDI32)] // Win32 encapsulation
public static extern bool DeleteObject(IntPtr hObject);
[DllImport(GDI32)] // Win32 encapsulation
public static extern bool CombineRgn(IntPtr hDestRgn, IntPtr hSrcRgn1, IntPtr hSrcRgn2, int nCombineMode);
[DllImport(KERNEL32)]
public static extern bool GetVersionEx(ref OSVERSIONINFOEX o);
unsafe public static int GetOsVersion()
{
OSVERSIONINFOEX os = new OSVERSIONINFOEX();
int nRet = 0;
os.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX)); // SIZEOF
if (GetVersionEx(ref os))
{
switch (os.dwPlatformId)
{
case 1:
nRet = os.dwPlatformId;
switch (os.dwMinorVersion)
{
case 0: nRet = 95; // 95
break;
case 10: nRet = 98; // 98
break;
case 90: nRet = 100; // ME
break;
}
break;
case 2:
nRet = os.dwPlatformId;
switch (os.dwMajorVersion)
{
case 3: nRet = 351; // NT 3.51
break;
case 4: nRet = 400; // NT 4.0
break;
case 5:
nRet = 500; // 2000
if (os.dwMinorVersion == 1)
{
nRet = 501; // XP
}
break;
case 6:
nRet = 600; // VISTA
break;
}
break;
default:
nRet = -1;
break;
}
}
return nRet;
}
// Using Drop Shadow slows down display when using large window.
public static void UseDropShadow(IntPtr hWnd)
{
// Get the Operating System
if (GetOsVersion() > 499)
{ // OS NT only
if (IsWindow(hWnd))
{
int GCL_STYLE = -26;
int CS_DROPSHADOW = 131072;
int ClassLong = GetClassLong(hWnd, GCL_STYLE);
if ((ClassLong & CS_DROPSHADOW) == 0)
{
ClassLong += CS_DROPSHADOW;
SetClassLong(hWnd, GCL_STYLE, ClassLong);
}
}
//int WS_EX_COMPOSITED = 0x02000000;
//int GWL_EXSTYLE = -20;
//int WindowLong = GetWindowLong(hWnd, GWL_EXSTYLE);
//SetWindowLong(hWnd, GWL_EXSTYLE, WindowLong | WS_EX_COMPOSITED);
}
}
public static void ButtonClick(IntPtr hButton)
{
PostMessage(hButton, WM_LBUTTONDOWN, 0, 0);
PostMessage(hButton, WM_LBUTTONUP, 0, 0);
}
[DllImport(USER32, EntryPoint = "GetWindowLongA")]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport(USER32, EntryPoint = "SetWindowLongA")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int lNewLong);
[DllImport(USER32, EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr hWnd, int dwMsg, uint wParam, int lParam);
[DllImport(USER32, EntryPoint = "CallWindowProcA")]
public static extern int CallWindowProc(int lpPrevWndFunc, IntPtr hWnd, int uMsg, uint wParam, uint lParam);
//[DllImport(USER32)]
//public static extern bool InvalidateRect(IntPtr hWnd, int lprec, int erase);
//[DllImport(USER32)]
//public static extern bool UpdateWindow(IntPtr hWnd);
//[DllImport(USER32, EntryPoint = "SendMessageA")] // Win32 encapsulation
//public static extern int SendMessage(IntPtr hWnd, uint dwMsg, uint wParam, int lParam);
//[DllImport(USER32)] // Win32 encapsulation
//private static extern IntPtr GetSysColorBrush(int nIndex);
//[DllImport(USER32, EntryPoint = "SetWindowTextA")]
//public static extern int SetWindowText(IntPtr hWnd, string lpString);
//[DllImport(KERNEL32, EntryPoint = "GetModuleHandleA")]
//public static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport(USER32)]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport(USER32)]
public static extern IntPtr GetForegroundWindow();
[DllImport(USER32)]
public static extern IntPtr SetFocus(IntPtr hWnd);
[DllImport(USER32)]
public static extern IntPtr GetFocus();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -