📄 win32api.cs
字号:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace feiyun0112.cnblogs.com.CSDNReader.Functions
{
public static class Win32API
{
public const int EM_SETSEL = 0xb1;
public const int LVIS_FOCUSED = 1;
public const int LVIS_SELECTED = 2;
public const int LVM_FIRST = 0x1000;
public const int LVM_GETITEM = 0x1005;
public const int LVM_SETITEM = 0x1006;
public const int LVM_SETITEMSTATE = 0x102b;
public const int LVM_SUBITEMHITTEST = 0x1039;
public const int SB_LINEDOWN = 1;
public const int SB_LINEUP = 0;
public const int SC_RESTORE = 0xf120;
public const int SW_RESTORE = 9;
public const int WM_COPYDATA = 0x4a;
public const int WM_KEYDOWN = 0x100;
public const int WM_KEYUP = 0x101;
public const int WM_LBUTTONDBLCLK = 0x203;
public const int WM_LBUTTONDOWN = 0x201;
public const int WM_LBUTTONUP = 0x202;
public const int WM_MBUTTONDBLCLK = 0x209;
public const int WM_MBUTTONDOWN = 0x207;
public const int WM_MBUTTONUP = 520;
public const int WM_MOUSEWHEEL = 0x20a;
public const int WM_QUERYENDSESSION = 0x11;
public const int WM_RBUTTONDBLCLK = 0x206;
public const int WM_RBUTTONDOWN = 0x204;
public const int WM_RBUTTONUP = 0x205;
public const int WM_SYSCOMMAND = 0x112;
public const int WM_VSCROLL = 0x115;
[StructLayout(LayoutKind.Sequential)]
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal struct POINT
{
public int x;
public int y;
}
public enum ListViewItemFlags
{
LVIF_IMAGE = 2,
LVIF_INDENT = 0x10,
LVIF_NORECOMPUTE = 0x800,
LVIF_PARAM = 4,
LVIF_STATE = 8,
LVIF_TEXT = 1
}
public enum ListViewHitTestFlags
{
LVHT_NOWHERE = 1,
LVHT_ONITEMICON = 2,
LVHT_ONITEMLABEL = 4,
LVHT_ONITEMSTATEICON = 8
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal struct LV_HITTESTINFO
{
public POINT pt;
public ListViewHitTestFlags flags;
public int iItem;
public int iSubItem;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal struct LV_ITEM
{
public ListViewItemFlags mask;
public int iItem;
public int iSubItem;
public uint state;
public uint stateMask;
public IntPtr pszText;
public int cchTextMax;
public int iImage;
public int lParam;
public int iIndent;
}
[DllImport("User32.dll")]
public static extern IntPtr GetFocus();
public static int GetListViewItemIndent(ListView listView, int itemIndex)
{
LV_ITEM lvi = new LV_ITEM();
lvi.iItem = itemIndex;
lvi.mask = ListViewItemFlags.LVIF_INDENT;
SendMessage(listView.Handle, 0x1005, 0, ref lvi);
return lvi.iIndent;
}
[DllImport("User32.dll")]
public static extern IntPtr GetWindow(IntPtr hWnd, IntPtr wCmd);
[DllImport("wininet.dll")]
public static extern bool InternetGetConnectedState(out int flags, int reserved);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool IsIconic(IntPtr hWnd);
[DllImport("sensapi.dll")]
public static extern bool IsNetworkAlive(out int flags);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int PostMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, ref COPYDATASTRUCT lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, ref LV_HITTESTINFO lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, ref LV_ITEM lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
[DllImport("User32.dll")]
public static extern IntPtr SetFocus(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
public static void SetListViewItemIndent(ListView listView, int itemIndex, int level)
{
LV_ITEM lvi = new LV_ITEM();
lvi.iItem = itemIndex;
lvi.iIndent = level;
lvi.mask = ListViewItemFlags.LVIF_INDENT;
SendMessage(listView.Handle, 0x1006, 0, ref lvi);
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -