📄 nativemethods.cs
字号:
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref RECT lParam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref POINT lParam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref TBBUTTON lParam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref TBBUTTONINFO lParam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref REBARBANDINFO lParam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
[DllImport("kernel32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
public static extern int GetCurrentThreadId();
internal delegate IntPtr HookProc(int code, IntPtr param1, IntPtr param2);
public const int WH_MSGFILTER = -1;
public const int MSGF_MENU = 2;
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SetWindowsHookEx(int hookid, HookProc pfnhook, IntPtr hinst, int threadid);
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern bool UnhookWindowsHookEx(IntPtr hhook);
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr CallNextHookEx(IntPtr hhook, int code, IntPtr wparam, IntPtr lparam);
[StructLayout(LayoutKind.Sequential)]
internal struct MSG
{
public IntPtr hwnd;
public int message;
public IntPtr wParam;
public IntPtr lParam;
public int time;
public int pt_x;
public int pt_y;
}
public const string REBARCLASSNAME = "ReBarWindow32";
public const int RBS_VARHEIGHT = 0x200;
public const int RBS_BANDBORDERS = 0x400;
public const int RBS_AUTOSIZE = 0x2000;
public const int RBN_FIRST = -831;
public const int RBN_HEIGHTCHANGE = RBN_FIRST - 0;
public const int RBN_AUTOSIZE = RBN_FIRST - 3;
public const int RBN_CHEVRONPUSHED = RBN_FIRST - 10;
public const int RB_GETBANDINFO = WM_USER + 5;
public const int RB_SETBANDINFO = WM_USER + 6;
public const int RB_GETRECT = WM_USER + 9;
public const int RB_INSERTBAND = WM_USER + 10;
public const int RB_GETBARHEIGHT = WM_USER + 27;
[StructLayout(LayoutKind.Sequential)]
internal struct REBARBANDINFO
{
public int cbSize;
public int fMask;
public int fStyle;
public int clrFore;
public int clrBack;
public IntPtr lpText;
public int cch;
public int iImage;
public IntPtr hwndChild;
public int cxMinChild;
public int cyMinChild;
public int cx;
public IntPtr hbmBack;
public int wID;
public int cyChild;
public int cyMaxChild;
public int cyIntegral;
public int cxIdeal;
public int lParam;
public int cxHeader;
}
public const int RBBIM_CHILD = 0x10;
public const int RBBIM_CHILDSIZE = 0x20;
public const int RBBIM_STYLE = 0x1;
public const int RBBIM_ID = 0x100;
public const int RBBIM_SIZE = 0x40;
public const int RBBIM_IDEALSIZE = 0x200;
public const int RBBIM_TEXT = 0x4;
public const int RBBS_BREAK = 0x1;
public const int RBBS_CHILDEDGE = 0x4;
public const int RBBS_FIXEDBMP = 0x20;
public const int RBBS_GRIPPERALWAYS = 0x80;
public const int RBBS_USECHEVRON = 0x200;
[StructLayout(LayoutKind.Sequential)]
internal struct NMREBARCHEVRON
{
public NMHDR hdr;
public int uBand;
public int wID;
public int lParam;
public RECT rc;
public int lParamNM;
}
[StructLayout(LayoutKind.Sequential)]
internal struct IMAGELISTDRAWPARAMS
{
public int cbSize;
public IntPtr himl;
public int i;
public IntPtr hdcDst;
public int x;
public int y;
public int cx;
public int cy;
public int xBitmap;
public int yBitmap;
public int rgbBk;
public int rgbFg;
public int fStyle;
public int dwRop;
public int fState;
public int Frame;
public int crEffect;
}
public const int ILD_TRANSPARENT = 0x1;
public const int ILS_SATURATE = 0x4;
[DllImport("comctl32.dll", CharSet=CharSet.Auto)]
public static extern bool ImageList_DrawIndirect(ref IMAGELISTDRAWPARAMS pimldp);
[StructLayout(LayoutKind.Sequential)]
internal struct DLLVERSIONINFO
{
public int cbSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformID;
}
[DllImport("comctl32.dll")]
public extern static int DllGetVersion(ref DLLVERSIONINFO dvi);
public const int SPI_GETFLATMENU = 0x1022;
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public extern static int SystemParametersInfo(int nAction, int nParam, ref int value, int ignore);
[DllImport("user32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
public static extern bool MessageBeep(int type);
public const int HWND_NOTOPMOST = -2;
public const int SW_SHOWNORMAL = 1;
public const int SWP_NOACTIVATE = 0x0010;
public const int SWP_NOMOVE = 0x0002;
public const int SWP_NOSIZE = 0x0001;
public const int SWP_NOZORDER = 0x0004;
public const int SWP_SHOWWINDOW = 0x0040;
[DllImport("user32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, int flags);
public const int VK_RMENU = 0xA5; // right alt key
[DllImport("user32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
public static extern short GetAsyncKeyState(int vKey);
public static void DrawImage(Graphics graphics, Image image, Point point, bool disabled)
{
if (!disabled)
{
Rectangle destination = new Rectangle(point, image.Size);
graphics.DrawImage(image, destination, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
}
else
{
// Painting a disabled gray scale image is done using ILS_SATURATE on WinXP.
// This code emulates that behaviour if comctl32 version 6 is not availble.
NativeMethods.DLLVERSIONINFO dvi = new NativeMethods.DLLVERSIONINFO();
dvi.cbSize = Marshal.SizeOf(typeof(NativeMethods.DLLVERSIONINFO));
NativeMethods.DllGetVersion(ref dvi);
if (dvi.dwMajorVersion < 6)
{
ImageAttributes attributes = new ImageAttributes();
Rectangle destination = new Rectangle(point, image.Size);
float[][] matrix = new float[5][];
matrix[0] = new float[] { 0.2222f, 0.2222f, 0.2222f, 0.0000f, 0.0000f };
matrix[1] = new float[] { 0.2222f, 0.2222f, 0.2222f, 0.0000f, 0.0000f };
matrix[2] = new float[] { 0.2222f, 0.2222f, 0.2222f, 0.0000f, 0.0000f };
matrix[3] = new float[] { 0.3333f, 0.3333f, 0.3333f, 0.7500f, 0.0000f };
matrix[4] = new float[] { 0.0000f, 0.0000f, 0.0000f, 0.0000f, 1.0000f };
attributes.SetColorMatrix(new ColorMatrix(matrix));
graphics.DrawImage(image, destination, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
}
else
{
ImageList imageList = new ImageList();
imageList.ImageSize = image.Size;
imageList.ColorDepth = ColorDepth.Depth32Bit;
imageList.Images.Add(image);
IntPtr hdc = graphics.GetHdc();
NativeMethods.IMAGELISTDRAWPARAMS ildp = new NativeMethods.IMAGELISTDRAWPARAMS();
ildp.cbSize = Marshal.SizeOf(typeof(NativeMethods.IMAGELISTDRAWPARAMS));
ildp.himl = imageList.Handle;
ildp.i = 0; // image index
ildp.hdcDst = hdc;
ildp.x = point.X;
ildp.y = point.Y;
ildp.cx = 0;
ildp.cy = 0;
ildp.xBitmap = 0;
ildp.yBitmap = 0;
ildp.fStyle = NativeMethods.ILD_TRANSPARENT;
ildp.fState = NativeMethods.ILS_SATURATE;
ildp.Frame = -100;
NativeMethods.ImageList_DrawIndirect(ref ildp);
graphics.ReleaseHdc(hdc);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -