WinApi.cs

来源:互联网 发布:淘宝投诉店铺空挂 编辑:程序博客网 时间:2024/05/14 09:40
  1. using System;   
  2. using System.Text;   
  3. using System.Windows.Forms;   
  4. using System.Drawing;   
  5. using System.Runtime.InteropServices;   
  6. using Accessibility;   
  7. using mshtml;   
  8.   
  9. namespace ConsoleApp   
  10. {   
  11.     public sealed class WinApi   
  12.     {   
  13.         //Not allow to create instance   
  14.   
  15.         private WinApi()   
  16.         {   
  17.   
  18.         }   
  19.   
  20.   
  21.         public const uint MAX_PATH = 260;  
  22.  
  23.         #region Hooks - user32.dll   
  24.   
  25.         /// <summary>   
  26.         /// Defines the layout of the MouseHookStruct   
  27.         /// </summary>   
  28.         [StructLayout(LayoutKind.Sequential)]   
  29.         public struct MSLLHOOKSTRUCT   
  30.         {   
  31.             public Point Point;   
  32.             public int MouseData;   
  33.             public int Flags;   
  34.             public int Time;   
  35.             public int ExtraInfo;   
  36.         }   
  37.   
  38.         [StructLayout(LayoutKind.Sequential)]   
  39.         public struct POINT   
  40.         {   
  41.             public int x;   
  42.             public int y;   
  43.         }   
  44.   
  45.   
  46.         [StructLayout(LayoutKind.Sequential)]   
  47.         public struct MouseHookStruct   
  48.         {   
  49.             /// <summary>   
  50.             /// Specifies a POINT structure that contains the x- and y-coordinates of the cursor, in screen coordinates.   
  51.             /// </summary>   
  52.             public POINT Point;   
  53.   
  54.             public UInt32 MouseData;   
  55.             public UInt32 Flags;   
  56.             public UInt32 Time;   
  57.             public UInt32 ExtraInfo;   
  58.         }   
  59.   
  60.         /// <summary>   
  61.         /// &frac14;ü&Aring;&Igrave;&sup1;&sup3;×&Oacute;&Ecirc;&Acirc;&frac14;&thorn;&frac12;á&sup1;&sup1;&para;¨&Ograve;&aring;   
  62.         /// </summary>   
  63.         /// <remarks>&Iuml;ê&Iuml;&cedil;&Euml;&micro;&Atilde;÷&Ccedil;&euml;&sup2;&Icirc;&iquest;&frac14;MSDN&Ouml;&ETH;&sup1;&Oslash;&Oacute;&Uacute; KBDLLHOOKSTRUCT &micro;&Auml;&Euml;&micro;&Atilde;÷</remarks>   
  64.         [StructLayout(LayoutKind.Sequential)]   
  65.         public struct KeyboardHookStruct   
  66.         {   
  67.             /// <summary>   
  68.             /// Specifies a virtual-key code. The code must be a value in the range 1 to 254.   
  69.             /// </summary>   
  70.             public UInt32 VKCode;   
  71.   
  72.             /// <summary>   
  73.             /// Specifies a hardware scan code for the key.   
  74.             /// </summary>   
  75.             public UInt32 ScanCode;   
  76.   
  77.             /// <summary>   
  78.             /// Specifies the extended-key flag, event-injected flag, context code,   
  79.             /// and transition-state flag. This member is specified as follows.   
  80.             /// An application can use the following values to test the keystroke flags.   
  81.             /// </summary>   
  82.             public UInt32 Flags;   
  83.   
  84.             /// <summary>   
  85.             /// Specifies the time stamp for this message.   
  86.             /// </summary>   
  87.             public UInt32 Time;   
  88.   
  89.             /// <summary>   
  90.             /// Specifies extra information associated with the message.   
  91.             /// </summary>   
  92.             public UInt32 ExtraInfo;   
  93.         }   
  94.   
  95.         /// <summary>   
  96.         ///  EventArgs class for use as parameters by HookEventHandler delegates   
  97.         /// </summary>   
  98.         public class HookEventArgs : EventArgs   
  99.         {   
  100.             private int _code;   
  101.             private IntPtr _wParam;   
  102.             private IntPtr _lParam;   
  103.   
  104.             /// <summary>   
  105.             /// Initializes a new instance of the HookEventArgs class   
  106.             /// </summary>   
  107.             /// <param name="code">the hook code</param>   
  108.             /// <param name="wParam">hook specific information</param>   
  109.             /// <param name="lParam">hook specific information</param>   
  110.             public HookEventArgs(int code, IntPtr wParam, IntPtr lParam)   
  111.             {   
  112.                 _code = code;   
  113.                 _wParam = wParam;   
  114.                 _lParam = lParam;   
  115.             }   
  116.   
  117.             /// <summary>   
  118.             /// The hook code   
  119.             /// </summary>   
  120.             public int Code   
  121.             {   
  122.                 get  
  123.                 {   
  124.                     return _code;   
  125.                 }   
  126.             }   
  127.   
  128.             /// <summary>   
  129.             /// A pointer to data   
  130.             /// </summary>   
  131.             public IntPtr wParam   
  132.             {   
  133.                 get  
  134.                 {   
  135.                     return _wParam;   
  136.                 }   
  137.             }   
  138.   
  139.             /// <summary>   
  140.             /// A pointer to data   
  141.             /// </summary>   
  142.             public IntPtr lParam   
  143.             {   
  144.                 get  
  145.                 {   
  146.                     return _lParam;   
  147.                 }   
  148.             }   
  149.         }   
  150.   
  151.         /// <summary>   
  152.         /// Event delegate for use with the HookEventArgs class   
  153.         /// </summary>   
  154.         public delegate void HookEventHandler(object sender, HookEventArgs e);   
  155.   
  156.         /// <summary>   
  157.         /// Defines the various types of hooks that are available in Windows   
  158.         /// </summary>   
  159.         public enum HookTypes : int  
  160.         {   
  161.             WH_JOURNALRECORD = 0,   
  162.             WH_JOURNALPLAYBACK = 1,   
  163.             WH_KEYBOARD = 2,   
  164.             WH_GETMESSAGE = 3,   
  165.             WH_CALLWNDPROC = 4,   
  166.             WH_CBT = 5,   
  167.             WH_SYSMSGFILTER = 6,   
  168.             WH_MOUSE = 7,   
  169.             WH_HARDWARE = 8,   
  170.             WH_DEBUG = 9,   
  171.             WH_SHELL = 10,   
  172.             WH_FOREGROUNDIDLE = 11,   
  173.             WH_CALLWNDPROCRET = 12,   
  174.             WH_KEYBOARD_LL = 13,   
  175.             WH_MOUSE_LL = 14   
  176.         }   
  177.   
  178.         public enum ShellHookMessages   
  179.         {   
  180.             HSHELL_WINDOWCREATED = 1,   
  181.             HSHELL_WINDOWDESTROYED = 2,   
  182.             HSHELL_ACTIVATESHELLWINDOW = 3,   
  183.             HSHELL_WINDOWACTIVATED = 4,   
  184.             HSHELL_GETMINRECT = 5,   
  185.             HSHELL_REDRAW = 6,   
  186.             HSHELL_TASKMAN = 7,   
  187.             HSHELL_LANGUAGE = 8,   
  188.             HSHELL_ACCESSIBILITYSTATE = 11   
  189.         }   
  190.         public enum WM_MOUSE : int  
  191.         {   
  192.             /// <summary>   
  193.             /// &Ecirc;ó±ê&iquest;&ordf;&Ecirc;&frac14;   
  194.             /// </summary>   
  195.             WM_MOUSEFIRST = 0x200,   
  196.   
  197.             /// <summary>   
  198.             /// &Ecirc;ó±ê&Ograve;&AElig;&para;&macr;   
  199.             /// </summary>   
  200.             WM_MOUSEMOVE = 0x200,   
  201.   
  202.             /// <summary>   
  203.             /// ×ó&frac14;ü°&acute;&Iuml;&Acirc;   
  204.             /// </summary>   
  205.             WM_LBUTTONDOWN = 0x201,   
  206.   
  207.             /// <summary>   
  208.             /// ×ó&frac14;ü&Ecirc;&Iacute;·&Aring;   
  209.             /// </summary>   
  210.             WM_LBUTTONUP = 0x202,   
  211.   
  212.             /// <summary>   
  213.             /// ×ó&frac14;ü&Euml;&laquo;&raquo;÷   
  214.             /// </summary>   
  215.             WM_LBUTTONDBLCLK = 0x203,   
  216.   
  217.             /// <summary>   
  218.             /// &Oacute;&Ograve;&frac14;ü°&acute;&Iuml;&Acirc;   
  219.             /// </summary>   
  220.             WM_RBUTTONDOWN = 0x204,   
  221.   
  222.             /// <summary>   
  223.             /// &Oacute;&Ograve;&frac14;ü&Ecirc;&Iacute;·&Aring;   
  224.             /// </summary>   
  225.             WM_RBUTTONUP = 0x205,   
  226.   
  227.             /// <summary>   
  228.             /// &Oacute;&Ograve;&frac14;ü&Euml;&laquo;&raquo;÷   
  229.             /// </summary>   
  230.             WM_RBUTTONDBLCLK = 0x206,   
  231.   
  232.             /// <summary>   
  233.             /// &Ouml;&ETH;&frac14;ü°&acute;&Iuml;&Acirc;   
  234.             /// </summary>   
  235.             WM_MBUTTONDOWN = 0x207,   
  236.   
  237.             /// <summary>   
  238.             /// &Ouml;&ETH;&frac14;ü&Ecirc;&Iacute;·&Aring;   
  239.             /// </summary>   
  240.             WM_MBUTTONUP = 0x208,   
  241.   
  242.             /// <summary>   
  243.             /// &Ouml;&ETH;&frac14;ü&Euml;&laquo;&raquo;÷   
  244.             /// </summary>   
  245.             WM_MBUTTONDBLCLK = 0x209,   
  246.   
  247.             /// <summary>   
  248.             /// &sup1;&ouml;&Acirc;&Ouml;&sup1;&ouml;&para;&macr;   
  249.             /// </summary>   
  250.             /// <remarks>WINNT4.0&Ograve;&Ocirc;&Eacute;&Iuml;&sup2;&Aring;&Ouml;§&sup3;&Ouml;&acute;&Euml;&Iuml;&ucirc;&Iuml;&cent;</remarks>   
  251.             WM_MOUSEWHEEL = 0x020A   
  252.         }   
  253.   
  254.         //message for list box   
  255.         public enum LISTBOXMSG : int  
  256.         {   
  257.             LB_ADDSTRING = 0x0180,   
  258.             LB_INSERTSTRING = 0x0181,   
  259.             LB_DELETESTRING = 0x0182,   
  260.             LB_SELITEMRANGEEX = 0x0183,   
  261.             LB_RESETCONTENT = 0x0184,   
  262.             LB_SETSEL = 0x0185,   
  263.             LB_SETCURSEL = 0x0186,   
  264.             LB_GETSEL = 0x0187,   
  265.             LB_GETCURSEL = 0x0188,   
  266.             LB_GETTEXT = 0x0189,   
  267.             LB_GETTEXTLEN = 0x018A,   
  268.             LB_GETCOUNT = 0x018B,   
  269.             LB_SELECTSTRING = 0x018C,   
  270.             LB_DIR = 0x018D,   
  271.             LB_GETTOPINDEX = 0x018E,   
  272.             LB_FINDSTRING = 0x018F,   
  273.             LB_GETSELCOUNT = 0x0190,   
  274.             LB_GETSELITEMS = 0x0191,   
  275.             LB_SETTABSTOPS = 0x0192,   
  276.             LB_GETHORIZONTALEXTENT = 0x0193,   
  277.             LB_SETHORIZONTALEXTENT = 0x0194,   
  278.             LB_SETCOLUMNWIDTH = 0x0195,   
  279.             LB_ADDFILE = 0x0196,   
  280.             LB_SETTOPINDEX = 0x0197,   
  281.             LB_GETITEMRECT = 0x0198,   
  282.             LB_GETITEMDATA = 0x0199,   
  283.             LB_SETITEMDATA = 0x019A,   
  284.             LB_SELITEMRANGE = 0x019B,   
  285.             LB_SETANCHORINDEX = 0x019C,   
  286.             LB_GETANCHORINDEX = 0x019D,   
  287.             LB_SETCARETINDEX = 0x019E,   
  288.             LB_GETCARETINDEX = 0x019F,   
  289.             LB_SETITEMHEIGHT = 0x01A0,   
  290.             LB_GETITEMHEIGHT = 0x01A1,   
  291.             LB_FINDSTRINGEXACT = 0x01A2,   
  292.             LB_SETLOCALE = 0x01A5,   
  293.             LB_GETLOCALE = 0x01A6,   
  294.             LB_SETCOUNT = 0x01A7,   
  295.         }   
  296.   
  297.   
  298.         //message for combo box.   
  299.         public enum COMBOBOXMSG : int  
  300.         {   
  301.             CB_OKAY = 0,   
  302.             CB_ERR = (-1),   
  303.             CB_ERRSPACE = (-2),   
  304.             CBN_ERRSPACE = (-1),   
  305.             CBN_SELCHANGE = 1,   
  306.             CBN_DBLCLK = 2,   
  307.             CBN_SETFOCUS = 3,   
  308.             CBN_KILLFOCUS = 4,   
  309.             CBN_EDITCHANGE = 5,   
  310.             CBN_EDITUPDATE = 6,   
  311.             CBN_DROPDOWN = 7,   
  312.             CBN_CLOSEUP = 8,   
  313.             CBN_SELENDOK = 9,   
  314.             CBN_SELENDCANCEL = 10,   
  315.             CBS_SIMPLE = 0x0001,   
  316.             CBS_DROPDOWN = 0x0002,   
  317.             CBS_DROPDOWNLIST = 0x0003,   
  318.             CBS_OWNERDRAWFIXED = 0x0010,   
  319.             CBS_OWNERDRAWVARIABLE = 0x0020,   
  320.             CBS_AUTOHSCROLL = 0x0040,   
  321.             CBS_OEMCONVERT = 0x0080,   
  322.             CBS_SORT = 0x0100,   
  323.             CBS_HASSTRINGS = 0x0200,   
  324.             CBS_NOINTEGRALHEIGHT = 0x0400,   
  325.             CBS_DISABLENOSCROLL = 0x0800,   
  326.             CBS_UPPERCASE = 0x2000,   
  327.             CBS_LOWERCASE = 0x4000,   
  328.             CB_GETEDITSEL = 0x0140,   
  329.             CB_LIMITTEXT = 0x0141,   
  330.             CB_SETEDITSEL = 0x0142,   
  331.             CB_ADDSTRING = 0x0143,   
  332.             CB_DELETESTRING = 0x0144,   
  333.             CB_DIR = 0x0145,   
  334.             CB_GETCOUNT = 0x0146,   
  335.             CB_GETCURSEL = 0x0147,   
  336.             CB_GETLBTEXT = 0x0148,   
  337.             CB_GETLBTEXTLEN = 0x0149,   
  338.             CB_INSERTSTRING = 0x014A,   
  339.             CB_RESETCONTENT = 0x014B,   
  340.             CB_FINDSTRING = 0x014C,   
  341.             CB_SELECTSTRING = 0x014D,   
  342.             CB_SETCURSEL = 0x014E,   
  343.             CB_SHOWDROPDOWN = 0x014F,   
  344.             CB_GETITEMDATA = 0x0150,   
  345.             CB_SETITEMDATA = 0x0151,   
  346.             CB_GETDROPPEDCONTROLRECT = 0x0152,   
  347.             CB_SETITEMHEIGHT = 0x0153,   
  348.             CB_GETITEMHEIGHT = 0x0154,   
  349.             CB_SETEXTENDEDUI = 0x0155,   
  350.             CB_GETEXTENDEDUI = 0x0156,   
  351.             CB_GETDROPPEDSTATE = 0x0157,   
  352.             CB_FINDSTRINGEXACT = 0x0158,   
  353.             CB_SETLOCALE = 0x0159,   
  354.             CB_GETLOCALE = 0x015A,   
  355.             CB_GETTOPINDEX = 0x015b,   
  356.             CB_SETTOPINDEX = 0x015c,   
  357.             CB_GETHORIZONTALEXTENT = 0x015d,   
  358.             CB_SETHORIZONTALEXTENT = 0x015e,   
  359.             CB_GETDROPPEDWIDTH = 0x015f,   
  360.             CB_SETDROPPEDWIDTH = 0x0160,   
  361.             CB_INITSTORAGE = 0x0161,   
  362.             CB_MSGMAX = 0x0162,   
  363.         }   
  364.   
  365.         //virtual keys   
  366.         public enum VKCodes : int  
  367.         {   
  368.             VK_BACK = 0x08,   
  369.             VK_TAB = 0x09,   
  370.   
  371.             VK_CLEAR = 0x0C,   
  372.             VK_RETURN = 0x0D,   
  373.   
  374.             VK_SHIFT = 0x10,   
  375.             VK_CONTROL = 0x11,   
  376.             VK_MENU = 0x12,   
  377.             VK_PAUSE = 0x13,   
  378.             VK_CAPITAL = 0x14,   
  379.   
  380.             VK_KANA = 0x15,   
  381.             VK_HANGEUL = 0x15,   
  382.             VK_HANGUL = 0x15,   
  383.             VK_JUNJA = 0x17,   
  384.             VK_FINAL = 0x18,   
  385.             VK_HANJA = 0x19,   
  386.             VK_KANJI = 0x19,   
  387.   
  388.             VK_ESCAPE = 0x1B,   
  389.   
  390.             VK_CONVERT = 0x1C,   
  391.             VK_NONCONVERT = 0x1D,   
  392.             VK_ACCEPT = 0x1E,   
  393.             VK_MODECHANGE = 0x1F,   
  394.   
  395.             VK_SPACE = 0x20,   
  396.             VK_PRIOR = 0x21,   
  397.             VK_NEXT = 0x22,   
  398.             VK_END = 0x23,   
  399.             VK_HOME = 0x24,   
  400.             VK_LEFT = 0x25,   
  401.             VK_UP = 0x26,   
  402.             VK_RIGHT = 0x27,   
  403.             VK_DOWN = 0x28,   
  404.             VK_SELECT = 0x29,   
  405.             VK_PRINT = 0x2A,   
  406.             VK_EXECUTE = 0x2B,   
  407.             VK_SNAPSHOT = 0x2C,   
  408.             VK_INSERT = 0x2D,   
  409.             VK_DELETE = 0x2E,   
  410.             VK_HELP = 0x2F,   
  411.   
  412.   
  413.             VK_LWIN = 0x5B,   
  414.             VK_RWIN = 0x5C,   
  415.             VK_APPS = 0x5D,   
  416.   
  417.   
  418.             VK_SLEEP = 0x5F,   
  419.             VK_NUMLOCK = 90,   
  420.             VK_NUMPAD0 = 0x60,   
  421.             VK_NUMPAD1 = 0x61,   
  422.             VK_NUMPAD2 = 0x62,   
  423.             VK_NUMPAD3 = 0x63,   
  424.             VK_NUMPAD4 = 0x64,   
  425.             VK_NUMPAD5 = 0x65,   
  426.             VK_NUMPAD6 = 0x66,   
  427.             VK_NUMPAD7 = 0x67,   
  428.             VK_NUMPAD8 = 0x68,   
  429.             VK_NUMPAD9 = 0x69,   
  430.             VK_MULTIPLY = 0x6A,   
  431.             VK_ADD = 0x6B,   
  432.             VK_SEPARATOR = 0x6C,   
  433.             VK_SUBTRACT = 0x6D,   
  434.             VK_DECIMAL = 0x6E,   
  435.             VK_DIVIDE = 0x6F,   
  436.             VK_F1 = 0x70,   
  437.             VK_F2 = 0x71,   
  438.             VK_F3 = 0x72,   
  439.             VK_F4 = 0x73,   
  440.             VK_F5 = 0x74,   
  441.             VK_F6 = 0x75,   
  442.             VK_F7 = 0x76,   
  443.             VK_F8 = 0x77,   
  444.             VK_F9 = 0x78,   
  445.             VK_F10 = 0x79,   
  446.             VK_F11 = 0x7A,   
  447.             VK_F12 = 0x7B,   
  448.             VK_F13 = 0x7C,   
  449.             VK_F14 = 0x7D,   
  450.             VK_F15 = 0x7E,   
  451.             VK_F16 = 0x7F,   
  452.             VK_F17 = 0x80,   
  453.             VK_F18 = 0x81,   
  454.             VK_F19 = 0x82,   
  455.             VK_F20 = 0x83,   
  456.             VK_F21 = 0x84,   
  457.             VK_F22 = 0x85,   
  458.             VK_F23 = 0x86,   
  459.             VK_F24 = 0x87   
  460.         }   
  461.   
  462.   
  463.         public enum WM_KEYBOARD : int  
  464.         {   
  465.             /// <summary>   
  466.             /// ·&Ccedil;&Iuml;&micro;&Iacute;&sup3;°&acute;&frac14;ü°&acute;&Iuml;&Acirc;   
  467.             /// </summary>   
  468.             WM_KEYDOWN = 0x100,   
  469.   
  470.             /// <summary>   
  471.             /// ·&Ccedil;&Iuml;&micro;&Iacute;&sup3;°&acute;&frac14;ü&Ecirc;&Iacute;·&Aring;   
  472.             /// </summary>   
  473.             WM_KEYUP = 0x101,   
  474.   
  475.             /// <summary>   
  476.             /// &Iuml;&micro;&Iacute;&sup3;°&acute;&frac14;ü°&acute;&Iuml;&Acirc;   
  477.             /// </summary>   
  478.             WM_SYSKEYDOWN = 0x104,   
  479.   
  480.             /// <summary>   
  481.             /// &Iuml;&micro;&Iacute;&sup3;°&acute;&frac14;ü&Ecirc;&Iacute;·&Aring;   
  482.             /// </summary>   
  483.             WM_SYSKEYUP = 0x105   
  484.         }   
  485.         public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);   
  486.   
  487.         [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true, EntryPoint = "SetWindowsHookEx")]   
  488.         public static extern IntPtr SetWindowsHookEx(HookTypes hookType, HookProc hookProc, IntPtr hInstance, int nThreadId);   
  489.   
  490.         [DllImport("user32.dll")]   
  491.         public static extern int UnhookWindowsHookEx(IntPtr hookHandle);   
  492.   
  493.         [DllImport("user32.dll")]   
  494.         public static extern int CallNextHookEx(IntPtr hookHandle, int nCode, Int32 wParam, IntPtr lParam);   
  495.   
  496.         [DllImport("user32.dll")]   
  497.         public static extern int RegisterShellHookWindow(IntPtr hWnd);   
  498.   
  499.         [DllImport("user32.dll")]   
  500.         public static extern int DeregisterShellHookWindow(IntPtr hWnd);   
  501.   
  502.         [DllImport("user32.dll")]   
  503.         public static extern int ToAscii(UInt32 uVirtKey, UInt32 uScanCode,   
  504.             byte[] lpbKeyState, byte[] lpwTransKey, UInt32 fuState);   
  505.   
  506.         [DllImport("user32.dll")]   
  507.         public static extern int GetKeyboardState(byte[] pbKeyState);  
  508.  
  509.         #endregion Hooks  
  510.  
  511.         #region System - Kernel32.dll   
  512.   
  513.         [DllImport("kernel32.dll", EntryPoint = "GetLastError", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]   
  514.         public static extern Int32 GetLastError();  
  515.  
  516.         #endregion  
  517.  
  518.         #region Windows - user32.dll   
  519.   
  520.         public const int GWL_HWNDPARENT = (-8);   
  521.         public const int GWL_EXSTYLE = (-20);   
  522.         public const int GWL_STYLE = (-16);   
  523.         public const int GCL_HICON = (-14);   
  524.         public const int GCL_HICONSM = (-34);   
  525.         public const int WM_QUERYDRAGICON = 0x37;   
  526.         public const int WM_GETICON = 0x7F;   
  527.         public const int WM_SETICON = 0x80;   
  528.         public const int ICON_SMALL = 0;   
  529.         public const int ICON_BIG = 1;   
  530.         public const int SMTO_ABORTIFHUNG = 0x2;   
  531.         public const int TRUE = 1;   
  532.         public const int FALSE = 0;   
  533.   
  534.         public const int WHITE_BRUSH = 0;   
  535.         public const int LTGRAY_BRUSH = 1;   
  536.         public const int GRAY_BRUSH = 2;   
  537.         public const int DKGRAY_BRUSH = 3;   
  538.         public const int BLACK_BRUSH = 4;   
  539.         public const int NULL_BRUSH = 5;   
  540.         public const int HOLLOW_BRUSH = NULL_BRUSH;   
  541.         public const int WHITE_PEN = 6;   
  542.         public const int BLACK_PEN = 7;   
  543.         public const int NULL_PEN = 8;   
  544.         public const int OEM_FIXED_FONT = 10;   
  545.         public const int ANSI_FIXED_FONT = 11;   
  546.         public const int ANSI_VAR_FONT = 12;   
  547.         public const int SYSTEM_FONT = 13;   
  548.         public const int DEVICE_DEFAULT_FONT = 14;   
  549.         public const int DEFAULT_PALETTE = 15;   
  550.         public const int SYSTEM_FIXED_FONT = 16;   
  551.   
  552.   
  553.         public const int RDW_INVALIDATE = 0x0001;   
  554.         public const int RDW_INTERNALPAINT = 0x0002;   
  555.         public const int RDW_ERASE = 0x0004;   
  556.   
  557.         public const int RDW_VALIDATE = 0x0008;   
  558.         public const int RDW_NOINTERNALPAINT = 0x0010;   
  559.         public const int RDW_NOERASE = 0x0020;   
  560.   
  561.         public const int RDW_NOCHILDREN = 0x0040;   
  562.         public const int RDW_ALLCHILDREN = 0x0080;   
  563.   
  564.         public const int RDW_UPDATENOW = 0x0100;   
  565.         public const int RDW_ERASENOW = 0x0200;   
  566.   
  567.         public const int RDW_FRAME = 0x0400;   
  568.         public const int RDW_NOFRAME = 0x0800;   
  569.   
  570.         //enum to how to navigate in InternetExplorer.   
  571.         public enum BrowserNavConstants   
  572.         {   
  573.             /// <summary>   
  574.             /// Open the resource or file in a new window.   
  575.             /// </summary>   
  576.             navOpenInNewWindow = 0x1,   
  577.             /// <summary>   
  578.             /// Do not add the resource or file to the history list. The new page replaces the current page in the list.   
  579.             /// </summary>   
  580.             navNoHistory = 0x2,   
  581.             /// <summary>   
  582.             /// Do not consult the Internet cache; retrieve the resource from the origin server (implies BINDF_PRAGMA_NO_CACHE and BINDF_RESYNCHRONIZE).   
  583.             /// </summary>   
  584.             navNoReadFromCache = 0x4,   
  585.             /// <summary>   
  586.             /// Do not add the downloaded resource to the Internet cache. See BINDF_NOWRITECACHE.   
  587.             /// </summary>   
  588.             navNoWriteToCache = 0x8,   
  589.             /// <summary>   
  590.             /// If the navigation fails, the autosearch functionality attempts to navigate common root domains (.com, .edu, and so on). If this also fails, the URL is passed to a search engine.   
  591.             /// </summary>   
  592.             navAllowAutosearch = 0x10,   
  593.             /// <summary>   
  594.             /// Causes the current Explorer Bar to navigate to the given item, if possible.   
  595.             /// </summary>   
  596.             navBrowserBar = 0x20,   
  597.             /// <summary>   
  598.             /// Microsoft Internet Explorer 6 for Microsoft Windows XP Service Pack 2 (SP2) and later. If the navigation fails when a hyperlink is being followed, this constant specifies that the resource should then be bound to the moniker using the BINDF_HYPERLINK flag.   
  599.             /// </summary>   
  600.             navHyperlink = 0x40,   
  601.             /// <summary>   
  602.             /// Internet Explorer 6 for Windows XP SP2 and later. Force the URL into the restricted zone.   
  603.             /// </summary>   
  604.             navEnforceRestricted = 0x80,   
  605.             /// <summary>   
  606.             /// Internet Explorer 6 for Windows XP SP2 and later. Use the default Popup Manager to block pop-up windows.   
  607.             /// </summary>   
  608.             navNewWindowsManaged = 0x0100,   
  609.             /// <summary>   
  610.             /// Internet Explorer 6 for Windows XP SP2 and later. Block files that normally trigger a file download dialog box.   
  611.             /// </summary>   
  612.             navUntrustedForDownload = 0x0200,   
  613.             /// <summary>   
  614.             /// Internet Explorer 6 for Windows XP SP2 and later. Prompt for the installation of Microsoft ActiveX controls.   
  615.             /// </summary>   
  616.             navTrustedForActiveX = 0x0400,   
  617.             /// <summary>   
  618.             /// Windows Internet Explorer 7. Open the resource or file in a new tab. Allow the destination window to come to the foreground, if necessary.   
  619.             /// </summary>   
  620.             navOpenInNewTab = 0x0800,   
  621.             /// <summary>   
  622.             /// Internet Explorer 7. Open the resource or file in a new background tab; the currently active window and/or tab remains open on top.   
  623.             /// </summary>   
  624.             navOpenInBackgroundTab = 0x1000,   
  625.             /// <summary>   
  626.             /// Internet Explorer 7. Maintain state for dynamic navigation based on the filter string entered in the search band text box (wordwheel). Restore the wordwheel text when the navigation completes.   
  627.             /// </summary>   
  628.             navKeepWordWheelText = 0x2000   
  629.         }   
  630.   
  631.         public enum ShowWindowCmds   
  632.         {   
  633.             SW_HIDE = 0,   
  634.             SW_SHOWNORMAL = 1,   
  635.             SW_NORMAL = 1,   
  636.             SW_SHOWMINIMIZED = 2,   
  637.             SW_SHOWMAXIMIZED = 3,   
  638.             SW_MAXIMIZE = 3,   
  639.             SW_SHOWNOACTIVATE = 4,   
  640.             SW_SHOW = 5,   
  641.             SW_MINIMIZE = 6,   
  642.             SW_SHOWMINNOACTIVE = 7,   
  643.             SW_SHOWNA = 8,   
  644.             SW_RESTORE = 9,   
  645.             SW_SHOWDEFAULT = 10,   
  646.             SW_FORCEMINIMIZE = 11,   
  647.             SW_MAX = 11   
  648.         }   
  649.   
  650.         [StructLayout(LayoutKind.Sequential)]   
  651.         public struct MOUSEINPUT   
  652.         {   
  653.             public int dx;   
  654.             public int dy;   
  655.             public uint mouseData;   
  656.             public uint dwFlags;   
  657.             public uint time;   
  658.             public IntPtr dwExtraInfo;   
  659.         }   
  660.   
  661.         [StructLayout(LayoutKind.Sequential)]   
  662.         public struct KEYBDINPUT   
  663.         {   
  664.             public ushort wVk;   
  665.             public ushort wScan;   
  666.             public uint dwFlags;   
  667.             public uint time;   
  668.             public IntPtr dwExtraInfo;   
  669.         }   
  670.   
  671.         [StructLayout(LayoutKind.Sequential)]   
  672.         public struct HARDWAREINPUT   
  673.         {   
  674.             public uint uMsg;   
  675.             public ushort wParamL;   
  676.             public ushort wParamH;   
  677.         }   
  678.   
  679.   
  680.         [StructLayout(LayoutKind.Explicit)]   
  681.         public struct INPUT   
  682.         {   
  683.             [FieldOffset(0)]   
  684.             public int type;   
  685.             [FieldOffset(4)]   
  686.             public MOUSEINPUT mi;   
  687.             [FieldOffset(4)]   
  688.             public KEYBDINPUT ki;   
  689.             [FieldOffset(4)]   
  690.             public HARDWAREINPUT hi;   
  691.         }   
  692.   
  693.         public const int HIDE_WINDOW = 0;   
  694.         public const int SHOW_OPENWINDOW = 1;   
  695.         public const int SHOW_ICONWINDOW = 2;   
  696.         public const int SHOW_FULLSCREEN = 3;   
  697.         public const int SHOW_OPENNOACTIVATE = 4;   
  698.         public const int SW_PARENTCLOSING = 1;   
  699.         public const int SW_OTHERZOOM = 2;   
  700.         public const int SW_PARENTOPENING = 3;   
  701.         public const int SW_OTHERUNZOOM = 4;   
  702.   
  703.         public const int SWP_NOSIZE = 0x0001;   
  704.         public const int SWP_NOMOVE = 0x0002;   
  705.         public const int SWP_NOZORDER = 0x0004;   
  706.         public const int SWP_NOREDRAW = 0x0008;   
  707.         public const int SWP_NOACTIVATE = 0x0010;   
  708.         public const int SWP_FRAMECHANGED = 0x0020; /* The frame changed: send WM_NCCALCSIZE */  
  709.         public const int SWP_SHOWWINDOW = 0x0040;   
  710.         public const int SWP_HIDEWINDOW = 0x0080;   
  711.         public const int SWP_NOCOPYBITS = 0x0100;   
  712.         public const int SWP_NOOWNERZORDER = 0x0200; /* Don't do owner Z ordering */  
  713.         public const int SWP_NOSENDCHANGING = 0x0400;  /* Don't send WM_WINDOWPOSCHANGING */  
  714.         public const int SWP_DRAWFRAME = SWP_FRAMECHANGED;   
  715.         public const int SWP_NOREPOSITION = SWP_NOOWNERZORDER;   
  716.         public const int SWP_DEFERERASE = 0x2000;   
  717.         public const int SWP_ASYNCWINDOWPOS = 0x4000;   
  718.   
  719.         public const int HWND_TOP = 0;   
  720.         public const int HWND_BOTTOM = 1;   
  721.         public const int HWND_TOPMOST = -1;   
  722.         public const int HWND_NOTOPMOST = -2;   
  723.   
  724.         public enum PeekMessageFlags   
  725.         {   
  726.             PM_NOREMOVE = 0,   
  727.             PM_REMOVE = 1,   
  728.             PM_NOYIELD = 2   
  729.         }   
  730.   
  731.         public enum MouseEventFlags   
  732.         {   
  733.             Move = 0x0001,   
  734.             LeftDown = 0x0002,   
  735.             LeftUp = 0x0004,   
  736.             RightDown = 0x0008,   
  737.             RightUp = 0x0010,   
  738.             MiddleDown = 0x0020,   
  739.             MiddleUp = 0x0040,   
  740.             Wheel = 0x0800,   
  741.             Absolute = 0x8000   
  742.         }   
  743.   
  744.         public enum ScrollBarMsg   
  745.         {   
  746.             SB_LINEUP = 0,   
  747.             SB_LINELEFT = 0,   
  748.             SB_LINEDOWN = 1,   
  749.             SB_LINERIGHT = 1,   
  750.             SB_PAGEUP = 2,   
  751.             SB_PAGELEFT = 2,   
  752.             SB_PAGEDOWN = 3,   
  753.             SB_PAGERIGHT = 3,   
  754.             SB_THUMBPOSITION = 4,   
  755.             SB_THUMBTRACK = 5,   
  756.             SB_TOP = 6,   
  757.             SB_LEFT = 6,   
  758.             SB_BOTTOM = 7,   
  759.             SB_RIGHT = 7,   
  760.             SB_ENDSCROLL = 8,   
  761.             WM_PAINT = 0x000F   
  762.         }   
  763.   
  764.         public enum WindowMessages : int  
  765.         {   
  766.             WM_NULL = 0x0000,   
  767.             WM_CREATE = 0x0001,   
  768.             WM_DESTROY = 0x0002,   
  769.             WM_MOVE = 0x0003,   
  770.             WM_SIZE = 0x0005,   
  771.             WM_ACTIVATE = 0x0006,   
  772.             WM_SETFOCUS = 0x0007,   
  773.             WM_KILLFOCUS = 0x0008,   
  774.             WM_ENABLE = 0x000A,   
  775.             WM_SETREDRAW = 0x000B,   
  776.             WM_SETTEXT = 0x000C,   
  777.             WM_GETTEXT = 0x000D,   
  778.             WM_GETTEXTLENGTH = 0x000E,   
  779.             WM_PAINT = 0x000F,   
  780.             WM_CLOSE = 0x0010,   
  781.             WM_QUERYENDSESSION = 0x0011,   
  782.             WM_QUIT = 0x0012,   
  783.             WM_QUERYOPEN = 0x0013,   
  784.             WM_ERASEBKGND = 0x0014,   
  785.             WM_SYSCOLORCHANGE = 0x0015,   
  786.             WM_ENDSESSION = 0x0016,   
  787.             WM_SHOWWINDOW = 0x0018,   
  788.             WM_CTLCOLOR = 0x0019,   
  789.             WM_WININICHANGE = 0x001A,   
  790.             WM_SETTINGCHANGE = 0x001A,   
  791.             WM_DEVMODECHANGE = 0x001B,   
  792.             WM_ACTIVATEAPP = 0x001C,   
  793.             WM_FONTCHANGE = 0x001D,   
  794.             WM_TIMECHANGE = 0x001E,   
  795.             WM_CANCELMODE = 0x001F,   
  796.             WM_SETCURSOR = 0x0020,   
  797.             WM_MOUSEACTIVATE = 0x0021,   
  798.             WM_CHILDACTIVATE = 0x0022,   
  799.             WM_QUEUESYNC = 0x0023,   
  800.             WM_GETMINMAXINFO = 0x0024,   
  801.             WM_PAINTICON = 0x0026,   
  802.             WM_ICONERASEBKGND = 0x0027,   
  803.             WM_NEXTDLGCTL = 0x0028,   
  804.             WM_SPOOLERSTATUS = 0x002A,   
  805.             WM_DRAWITEM = 0x002B,   
  806.             WM_MEASUREITEM = 0x002C,   
  807.             WM_DELETEITEM = 0x002D,   
  808.             WM_VKEYTOITEM = 0x002E,   
  809.             WM_CHARTOITEM = 0x002F,   
  810.             WM_SETFONT = 0x0030,   
  811.             WM_GETFONT = 0x0031,   
  812.             WM_SETHOTKEY = 0x0032,   
  813.             WM_GETHOTKEY = 0x0033,   
  814.             WM_QUERYDRAGICON = 0x0037,   
  815.             WM_COMPAREITEM = 0x0039,   
  816.             WM_GETOBJECT = 0x003D,   
  817.             WM_COMPACTING = 0x0041,   
  818.             WM_COMMNOTIFY = 0x0044,   
  819.             WM_WINDOWPOSCHANGING = 0x0046,   
  820.             WM_WINDOWPOSCHANGED = 0x0047,   
  821.             WM_POWER = 0x0048,   
  822.             WM_COPYDATA = 0x004A,   
  823.             WM_CANCELJOURNAL = 0x004B,   
  824.             WM_NOTIFY = 0x004E,   
  825.             WM_INPUTLANGCHANGEREQUEST = 0x0050,   
  826.             WM_INPUTLANGCHANGE = 0x0051,   
  827.             WM_TCARD = 0x0052,   
  828.             WM_HELP = 0x0053,   
  829.             WM_USERCHANGED = 0x0054,   
  830.             WM_NOTIFYFORMAT = 0x0055,   
  831.             WM_CONTEXTMENU = 0x007B,   
  832.             WM_STYLECHANGING = 0x007C,   
  833.             WM_STYLECHANGED = 0x007D,   
  834.             WM_DISPLAYCHANGE = 0x007E,   
  835.             WM_GETICON = 0x007F,   
  836.             WM_SETICON = 0x0080,   
  837.             WM_NCCREATE = 0x0081,   
  838.             WM_NCDESTROY = 0x0082,   
  839.             WM_NCCALCSIZE = 0x0083,   
  840.             WM_NCHITTEST = 0x0084,   
  841.             WM_NCPAINT = 0x0085,   
  842.             WM_NCACTIVATE = 0x0086,   
  843.             WM_GETDLGCODE = 0x0087,   
  844.             WM_SYNCPAINT = 0x0088,   
  845.             WM_NCMOUSEMOVE = 0x00A0,   
  846.             WM_NCLBUTTONDOWN = 0x00A1,   
  847.             WM_NCLBUTTONUP = 0x00A2,   
  848.             WM_NCLBUTTONDBLCLK = 0x00A3,   
  849.             WM_NCRBUTTONDOWN = 0x00A4,   
  850.             WM_NCRBUTTONUP = 0x00A5,   
  851.             WM_NCRBUTTONDBLCLK = 0x00A6,   
  852.             WM_NCMBUTTONDOWN = 0x00A7,   
  853.             WM_NCMBUTTONUP = 0x00A8,   
  854.             WM_NCMBUTTONDBLCLK = 0x00A9,   
  855.             WM_KEYDOWN = 0x0100,   
  856.             WM_KEYUP = 0x0101,   
  857.             WM_CHAR = 0x0102,   
  858.             WM_DEADCHAR = 0x0103,   
  859.             WM_SYSKEYDOWN = 0x0104,   
  860.             WM_SYSKEYUP = 0x0105,   
  861.             WM_SYSCHAR = 0x0106,   
  862.             WM_SYSDEADCHAR = 0x0107,   
  863.             WM_KEYLAST = 0x0108,   
  864.             WM_IME_STARTCOMPOSITION = 0x010D,   
  865.             WM_IME_ENDCOMPOSITION = 0x010E,   
  866.             WM_IME_COMPOSITION = 0x010F,   
  867.             WM_IME_KEYLAST = 0x010F,   
  868.             WM_INITDIALOG = 0x0110,   
  869.             WM_COMMAND = 0x0111,   
  870.             WM_SYSCOMMAND = 0x0112,   
  871.             WM_TIMER = 0x0113,   
  872.             WM_HSCROLL = 0x0114,   
  873.             WM_VSCROLL = 0x0115,   
  874.             WM_INITMENU = 0x0116,   
  875.             WM_INITMENUPOPUP = 0x0117,   
  876.             WM_MENUSELECT = 0x011F,   
  877.             WM_MENUCHAR = 0x0120,   
  878.             WM_ENTERIDLE = 0x0121,   
  879.             WM_MENURBUTTONUP = 0x0122,   
  880.             WM_MENUDRAG = 0x0123,   
  881.             WM_MENUGETOBJECT = 0x0124,   
  882.             WM_UNINITMENUPOPUP = 0x0125,   
  883.             WM_MENUCOMMAND = 0x0126,   
  884.             WM_CTLCOLORMSGBOX = 0x0132,   
  885.             WM_CTLCOLOREDIT = 0x0133,   
  886.             WM_CTLCOLORLISTBOX = 0x0134,   
  887.             WM_CTLCOLORBTN = 0x0135,   
  888.             WM_CTLCOLORDLG = 0x0136,   
  889.             WM_CTLCOLORSCROLLBAR = 0x0137,   
  890.             WM_CTLCOLORSTATIC = 0x0138,   
  891.             WM_MOUSEMOVE = 0x0200,   
  892.             WM_LBUTTONDOWN = 0x0201,   
  893.             WM_LBUTTONUP = 0x0202,   
  894.             WM_LBUTTONDBLCLK = 0x0203,   
  895.             WM_RBUTTONDOWN = 0x0204,   
  896.             WM_RBUTTONUP = 0x0205,   
  897.             WM_RBUTTONDBLCLK = 0x0206,   
  898.             WM_MBUTTONDOWN = 0x0207,   
  899.             WM_MBUTTONUP = 0x0208,   
  900.             WM_MBUTTONDBLCLK = 0x0209,   
  901.             WM_MOUSEWHEEL = 0x020A,   
  902.             WM_PARENTNOTIFY = 0x0210,   
  903.             WM_ENTERMENULOOP = 0x0211,   
  904.             WM_EXITMENULOOP = 0x0212,   
  905.             WM_NEXTMENU = 0x0213,   
  906.             WM_SIZING = 0x0214,   
  907.             WM_CAPTURECHANGED = 0x0215,   
  908.             WM_MOVING = 0x0216,   
  909.             WM_DEVICECHANGE = 0x0219,   
  910.             WM_MDICREATE = 0x0220,   
  911.             WM_MDIDESTROY = 0x0221,   
  912.             WM_MDIACTIVATE = 0x0222,   
  913.             WM_MDIRESTORE = 0x0223,   
  914.             WM_MDINEXT = 0x0224,   
  915.             WM_MDIMAXIMIZE = 0x0225,   
  916.             WM_MDITILE = 0x0226,   
  917.             WM_MDICASCADE = 0x0227,   
  918.             WM_MDIICONARRANGE = 0x0228,   
  919.             WM_MDIGETACTIVE = 0x0229,   
  920.             WM_MDISETMENU = 0x0230,   
  921.             WM_ENTERSIZEMOVE = 0x0231,   
  922.             WM_EXITSIZEMOVE = 0x0232,   
  923.             WM_DROPFILES = 0x0233,   
  924.             WM_MDIREFRESHMENU = 0x0234,   
  925.             WM_IME_SETCONTEXT = 0x0281,   
  926.             WM_IME_NOTIFY = 0x0282,   
  927.             WM_IME_CONTROL = 0x0283,   
  928.             WM_IME_COMPOSITIONFULL = 0x0284,   
  929.             WM_IME_SELECT = 0x0285,   
  930.             WM_IME_CHAR = 0x0286,   
  931.             WM_IME_REQUEST = 0x0288,   
  932.             WM_IME_KEYDOWN = 0x0290,   
  933.             WM_IME_KEYUP = 0x0291,   
  934.             WM_MOUSEHOVER = 0x02A1,   
  935.             WM_MOUSELEAVE = 0x02A3,   
  936.             WM_CUT = 0x0300,   
  937.             WM_COPY = 0x0301,   
  938.             WM_PASTE = 0x0302,   
  939.             WM_CLEAR = 0x0303,   
  940.             WM_UNDO = 0x0304,   
  941.             WM_RENDERFORMAT = 0x0305,   
  942.             WM_RENDERALLFORMATS = 0x0306,   
  943.             WM_DESTROYCLIPBOARD = 0x0307,   
  944.             WM_DRAWCLIPBOARD = 0x0308,   
  945.             WM_PAINTCLIPBOARD = 0x0309,   
  946.             WM_VSCROLLCLIPBOARD = 0x030A,   
  947.             WM_SIZECLIPBOARD = 0x030B,   
  948.             WM_ASKCBFORMATNAME = 0x030C,   
  949.             WM_CHANGECBCHAIN = 0x030D,   
  950.             WM_HSCROLLCLIPBOARD = 0x030E,   
  951.             WM_QUERYNEWPALETTE = 0x030F,   
  952.             WM_PALETTEISCHANGING = 0x0310,   
  953.             WM_PALETTECHANGED = 0x0311,   
  954.             WM_HOTKEY = 0x0312,   
  955.             WM_PRINT = 0x0317,   
  956.             WM_PRINTCLIENT = 0x0318,   
  957.             WM_HANDHELDFIRST = 0x0358,   
  958.             WM_HANDHELDLAST = 0x035F,   
  959.             WM_AFXFIRST = 0x0360,   
  960.             WM_AFXLAST = 0x037F,   
  961.             WM_PENWINFIRST = 0x0380,   
  962.             WM_PENWINLAST = 0x038F,   
  963.             WM_APP = 0x8000,   
  964.             WM_USER = 0x0400,   
  965.             WM_REFLECT = WM_USER + 0x1c00   
  966.         }   
  967.   
  968.   
  969.         //define the window menu message.   
  970.         public enum WindowMenuMessage : int  
  971.         {   
  972.             SC_SIZE = 0xF000,   
  973.             SC_MOVE = 0xF010,   
  974.             SC_MINIMIZE = 0xF020,   
  975.             SC_MAXIMIZE = 0xF030,   
  976.             SC_NEXTWINDOW = 0xF040,   
  977.             SC_PREVWINDOW = 0xF050,   
  978.             SC_CLOSE = 0xF060,   
  979.             SC_VSCROLL = 0xF070,   
  980.             SC_HSCROLL = 0xF080,   
  981.             SC_MOUSEMENU = 0xF090,   
  982.             SC_KEYMENU = 0xF100,   
  983.             SC_ARRANGE = 0xF110,   
  984.             SC_RESTORE = 0xF120,   
  985.             SC_TASKLIST = 0xF130,   
  986.             SC_SCREENSAVE = 0xF140,   
  987.             SC_HOTKEY = 0xF150,   
  988.             SC_DEFAULT = 0xF160,   
  989.             SC_MONITORPOWER = 0xF170,   
  990.             SC_CONTEXTHELP = 0xF180,   
  991.             SC_SEPARATOR = 0xF00F   
  992.         }   
  993.   
  994.         /// <summary>   
  995.         /// Defines the style bits that a window can have   
  996.         /// </summary>   
  997.         public enum WindowStyles : uint  
  998.         {   
  999.             WS_BORDER = 0x800000,   
  1000.             WS_CAPTION = 0xC00000,//               '  WS_BORDER Or WS_DLGFRAME   
  1001.             WS_CHILD = 0x40000000,   
  1002.             WS_CHILDWINDOW = (WS_CHILD),   
  1003.             WS_CLIPCHILDREN = 0x2000000,   
  1004.             WS_CLIPSIBLINGS = 0x4000000,   
  1005.             WS_DISABLED = 0x8000000,   
  1006.             WS_DLGFRAME = 0x400000,   
  1007.             WS_EX_ACCEPTFILES = 0x10,   
  1008.             WS_EX_DLGMODALFRAME = 0x1,   
  1009.             WS_EX_NOPARENTNOTIFY = 0x4,   
  1010.             WS_EX_TOPMOST = 0x8,   
  1011.             WS_EX_TRANSPARENT = 0x20,   
  1012.             WS_EX_TOOLWINDOW = 0x80,   
  1013.             WS_EX_APPWINDOW = 0x40000,   
  1014.             WS_GROUP = 0x20000,   
  1015.             WS_HSCROLL = 0x100000,   
  1016.             WS_MAXIMIZE = 0x1000000,   
  1017.             WS_MAXIMIZEBOX = 0x10000,   
  1018.             WS_MINIMIZE = 0x20000000,   
  1019.             WS_MINIMIZEBOX = 0x20000,   
  1020.             WS_OVERLAPPED = 0x0,   
  1021.             WS_POPUP = 0x80000000,   
  1022.             WS_SYSMENU = 0x80000,   
  1023.             WS_TABSTOP = 0x10000,   
  1024.             WS_THICKFRAME = 0x40000,   
  1025.             WS_VISIBLE = 0x10000000,   
  1026.             WS_VSCROLL = 0x200000,   
  1027.             WS_ICONIC = WS_MINIMIZE,   
  1028.             WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU),   
  1029.             WS_SIZEBOX = WS_THICKFRAME,   
  1030.             WS_TILED = WS_OVERLAPPED,   
  1031.             WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)   
  1032.         }   
  1033.   
  1034.         public struct WindowInfo   
  1035.         {   
  1036.             public int size;   
  1037.             public Rectangle window;   
  1038.             public Rectangle client;   
  1039.             public int style;   
  1040.             public int exStyle;   
  1041.             public int windowStatus;   
  1042.             public uint xWindowBorders;   
  1043.             public uint yWindowBorders;   
  1044.             public short atomWindowtype;   
  1045.             public short creatorVersion;   
  1046.         }   
  1047.   
  1048.         public struct WindowPlacement   
  1049.         {   
  1050.             public int length;   
  1051.             public int flags;   
  1052.             public int showCmd;   
  1053.             public Point minPosition;   
  1054.             public Point maxPosition;   
  1055.             public Rectangle normalPosition;   
  1056.         }   
  1057.   
  1058.         public struct Rect   
  1059.         {   
  1060.             public int left;   
  1061.             public int top;   
  1062.             public int right;   
  1063.             public int bottom;   
  1064.   
  1065.             public int Width   
  1066.             {   
  1067.                 get  
  1068.                 {   
  1069.                     return right - left;   
  1070.                 }   
  1071.             }   
  1072.   
  1073.             public int Height   
  1074.             {   
  1075.                 get  
  1076.                 {   
  1077.                     return bottom - top;   
  1078.                 }   
  1079.             }   
  1080.         }   
  1081.   
  1082.         //constant for IACC.   
  1083.         public enum IACC : int  
  1084.         {   
  1085.             //constant for MSAA interface.   
  1086.             OBJID_WINDOW = 0,   
  1087.             OBJID_CLIENT = -4,   
  1088.         }   
  1089.   
  1090.         public delegate bool EnumWindowEventHandler(IntPtr hWnd, Int32 lParam);   
  1091.   
  1092.         [DllImport("user32.dll", EntryPoint = "GetCursorPos")]   
  1093.         public static extern int GetCursorPos(ref POINT lpPoint);   
  1094.         //public static unsafe extern int GetCursorPos(POINT* lpPoint);   
  1095.   
  1096.         [DllImport("User32.dll")]   
  1097.         public extern static void mouse_event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);   
  1098.   
  1099.         [DllImport("user32.dll", EntryPoint = "SetCursorPos")]   
  1100.         public static extern bool SetCursorPos(int x, int y);   
  1101.   
  1102.         [DllImport("user32.dll", EntryPoint = "WindowFromPoint")]   
  1103.         public static extern IntPtr WindowFromPoint(int xPoint, int yPoint);   
  1104.   
  1105.         [DllImport("user32.dll", EntryPoint = "FindWindow")]   
  1106.         public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);   
  1107.   
  1108.         [DllImport("user32.dll", EntryPoint = "FindWindowEx")]   
  1109.         public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);   
  1110.   
  1111.         //GUID of IAccessible interface   
  1112.         public static Guid IACCUID = new Guid("618736e0-3c3d-11cf-810c-00aa00389b71");   
  1113.   
  1114.         [DllImport("oleacc.dll")]   
  1115.         public static extern uint GetStateText(uint dwStateBit, [Out] StringBuilder lpszStateBit, uint cchStateBitMax);   
  1116.   
  1117.         [DllImport("oleacc.dll")]   
  1118.         public static extern uint GetRoleText(uint dwRole, [Out] StringBuilder lpszRole, uint cchRoleMax);   
  1119.   
  1120.         [DllImport("oleacc.dll")]   
  1121.         public static extern IntPtr AccessibleObjectFromPoint(POINT pt, [Out, MarshalAs(UnmanagedType.Interface)] out IAccessible accObj, [Out] out object ChildID);   
  1122.   
  1123.         [DllImport("oleacc.dll", ExactSpelling = true, PreserveSig = false)]   
  1124.         [return: MarshalAs(UnmanagedType.Interface)]   
  1125.         public static extern object AccessibleObjectFromWindow(IntPtr hwnd, int dwObjectID, ref Guid riid, ref IAccessible ppvObject);   
  1126.   
  1127.         [DllImport("Oleacc.dll")]   
  1128.         public static extern int AccessibleChildren(IAccessible paccContainer, int iChildStart, int cChildren, [Out] object[] rgvarChildren, out int pcObtained);   
  1129.   
  1130.         [DllImport("oleacc.dll", PreserveSig = false)]   
  1131.         [return: MarshalAs(UnmanagedType.Interface)]   
  1132.         public static extern object ObjectFromLresult(UIntPtr lResult,   
  1133.              [MarshalAs(UnmanagedType.LPStruct)] Guid refiid, IntPtr wParam);   
  1134.   
  1135.         [DllImport("oleacc.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]   
  1136.         public  static extern Int32 ObjectFromLresult(Int32 lResult, ref Guid riid, Int32 wParam, out IHTMLDocument2 ppvObject);   
  1137.   
  1138.         [DllImport("user32.dll")]   
  1139.         public static extern int GetWindowModuleFileName(IntPtr hWnd, StringBuilder lpString, int nMaxCount);   
  1140.   
  1141.         [DllImport("user32.dll")]   
  1142.         public static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);   
  1143.   
  1144.         [DllImport("user32.dll")]   
  1145.         public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);   
  1146.   
  1147.         [DllImport("user32.dll")]   
  1148.         public static extern bool GetWindowPlacement(IntPtr window, ref WindowPlacement position);   
  1149.   
  1150.         [DllImport("User32.dll")]   
  1151.         public static extern int RegisterWindowMessage(string message);   
  1152.   
  1153.         [DllImport("User32.dll")]   
  1154.         public static extern void EnumWindows(EnumWindowEventHandler callback, Int32 lParam);   
  1155.   
  1156.         //      [DllImport("User32.dll")]   
  1157.         //      public static extern Int32 GetWindowText(IntPtr hWnd, StringBuilder lpString, Int32 nMaxCount);   
  1158.   
  1159.         [DllImport("User32.dll")]   
  1160.         public static extern bool IsWindowVisible(IntPtr hWnd);   
  1161.   
  1162.         [DllImport("User32.dll")]   
  1163.         public static extern Int32 GetWindow(IntPtr hWnd, Int32 wCmd);   
  1164.   
  1165.         [DllImport("User32.dll")]   
  1166.         public static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);   
  1167.   
  1168.         //      [DllImport("User32.dll")]   
  1169.         //      public static extern WindowStyles GetWindowLong(IntPtr hWnd, Int32 index);   
  1170.   
  1171.         [DllImport("User32.dll")]   
  1172.         public static extern IntPtr GetParent(IntPtr hWnd);   
  1173.   
  1174.         [DllImport("User32.dll")]   
  1175.         public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);   
  1176.   
  1177.         [DllImport("User32.dll")]   
  1178.         public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);   
  1179.   
  1180.         [DllImport("User32.dll")]   
  1181.         public static extern WindowStyles GetWindowLong(IntPtr hWnd, int index);   
  1182.   
  1183.         [DllImport("User32.dll")]   
  1184.         public static extern int SendMessageTimeout(IntPtr hWnd, int uMsg, int wParam, int lParam, int fuFlags, int uTimeout, out UIntPtr lpdwResult);   
  1185.   
  1186.         [DllImport("User32.dll")]   
  1187.         public static extern int GetClassLong(IntPtr hWnd, int index);   
  1188.   
  1189.         [DllImport("User32.dll")]   
  1190.         public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);   
  1191.   
  1192.         [DllImport("User32.dll")]   
  1193.         public unsafe static extern UInt32 SendInput(UInt32 nInputs, INPUT* pInputs, int cbSize);   
  1194.   
  1195.         [DllImport("User32.dll")]   
  1196.         public static extern UInt32 SendInput(UInt32 nInputs, INPUT[] pInputs, int cbSize);   
  1197.   
  1198.         [DllImport("User32.dll")]   
  1199.         public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, int lParam);   
  1200.   
  1201.         [DllImport("User32.dll")]   
  1202.         public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);   
  1203.   
  1204.         [DllImport("User32.dll")]   
  1205.         public static extern int PostMessage(IntPtr hWnd, int uMsg, int wParam, int lParam);   
  1206.   
  1207.         [DllImport("User32.dll")]   
  1208.         public static extern void SwitchToThisWindow(IntPtr hWnd, int altTabActivated);   
  1209.   
  1210.         [DllImport("User32.dll")]   
  1211.         public static extern int ShowWindowAsync(IntPtr hWnd, int command);   
  1212.   
  1213.         [DllImport("User32.dll")]   
  1214.         public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);   
  1215.   
  1216.         [DllImport("user32.dll")]   
  1217.         public static extern IntPtr GetDesktopWindow();   
  1218.   
  1219.         [DllImport("user32.dll")]   
  1220.         public static extern IntPtr GetForegroundWindow();   
  1221.   
  1222.         [DllImport("user32.dll")]   
  1223.         public static extern bool SetForegroundWindow(IntPtr hWnd);   
  1224.   
  1225.         [DllImport("user32.dll")]   
  1226.         public static extern bool BringWindowToTop(IntPtr window);   
  1227.   
  1228.         [DllImport("user32.dll")]   
  1229.         public static extern bool GetWindowInfo(IntPtr hwnd, ref WindowInfo info);   
  1230.   
  1231.         [DllImport("user32.dll")]   
  1232.         public static extern IntPtr GetWindowDC(IntPtr hwnd);   
  1233.   
  1234.         [DllImport("user32.dll")]   
  1235.         public static extern IntPtr GetDC(IntPtr hwnd);   
  1236.   
  1237.         [DllImport("user32.dll")]   
  1238.         public static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);   
  1239.   
  1240.         [DllImport("user32.dll")]   
  1241.         public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);   
  1242.   
  1243.         [DllImport("user32.dll")]   
  1244.         public static extern bool GetClientRect(IntPtr hwnd, ref Rect rectangle);   
  1245.   
  1246.         [DllImport("user32.dll")]   
  1247.         public static extern IntPtr GetMessageExtraInfo();   
  1248.   
  1249.         //[DllImport("user32.dll")]   
  1250.         //public static extern IntPtr WindowFromPoint(Point pt);   
  1251.   
  1252.         [DllImport("user32.dll")]   
  1253.         public static extern IntPtr SetCapture(IntPtr hWnd);   
  1254.   
  1255.         [DllImport("user32.dll")]   
  1256.         public static extern int ReleaseCapture();   
  1257.   
  1258.         //[DllImport("user32.dll")]   
  1259.         //public static extern IntPtr SelectObject(IntPtr hDc, IntPtr hObject);   
  1260.   
  1261.         [DllImport("user32.dll")]   
  1262.         public static extern IntPtr GetStockObject(int nObject);   
  1263.   
  1264.         [DllImport("user32.dll")]   
  1265.         public static extern int InvalidateRect(IntPtr hWnd, IntPtr lpRect, int bErase);   
  1266.   
  1267.         [DllImport("user32.dll")]   
  1268.         public static extern int UpdateWindow(IntPtr hWnd);   
  1269.   
  1270.         [DllImport("user32.dll")]   
  1271.         public static extern int RedrawWindow(IntPtr hWnd, IntPtr lprcUpdate, IntPtr hrgnUpdate, uint flags);   
  1272.   
  1273.         [DllImport("user32.dll")]   
  1274.         public static extern IntPtr GetActiveWindow();   
  1275.   
  1276.         [DllImport("user32.dll")]   
  1277.         public static extern IntPtr SetActiveWindow(IntPtr hWnd);  
  1278.  
  1279.         #endregion Windows  
  1280.  
  1281.         #region GDI - gdi32.dll   
  1282.   
  1283.         public enum BinaryRasterOperations   
  1284.         {   
  1285.             R2_BLACK = 1,   /*  0       */  
  1286.             R2_NOTMERGEPEN = 2,   /* DPon     */  
  1287.             R2_MASKNOTPEN = 3,   /* DPna     */  
  1288.             R2_NOTCOPYPEN = 4,   /* PN       */  
  1289.             R2_MASKPENNOT = 5,   /* PDna     */  
  1290.             R2_NOT = 6,   /* Dn       */  
  1291.             R2_XORPEN = 7,   /* DPx      */  
  1292.             R2_NOTMASKPEN = 8,   /* DPan     */  
  1293.             R2_MASKPEN = 9,   /* DPa      */  
  1294.             R2_NOTXORPEN = 10,  /* DPxn     */  
  1295.             R2_NOP = 11,  /* D        */  
  1296.             R2_MERGENOTPEN = 12,  /* DPno     */  
  1297.             R2_COPYPEN = 13,  /* P        */  
  1298.             R2_MERGEPENNOT = 14,  /* PDno     */  
  1299.             R2_MERGEPEN = 15,  /* DPo      */  
  1300.             R2_WHITE = 16,  /*  1       */  
  1301.             R2_LAST = 16   
  1302.         }   
  1303.   
  1304.         public enum TernaryRasterOperations   
  1305.         {   
  1306.             SRCCOPY = 0x00CC0020, /* dest = source                   */  
  1307.             SRCPAINT = 0x00EE0086, /* dest = source OR dest           */  
  1308.             SRCAND = 0x008800C6, /* dest = source AND dest          */  
  1309.             SRCINVERT = 0x00660046, /* dest = source XOR dest          */  
  1310.             SRCERASE = 0x00440328, /* dest = source AND (NOT dest )   */  
  1311.             NOTSRCCOPY = 0x00330008, /* dest = (NOT source)             */  
  1312.             NOTSRCERASE = 0x001100A6, /* dest = (NOT src) AND (NOT dest) */  
  1313.             MERGECOPY = 0x00C000CA, /* dest = (source AND pattern)     */  
  1314.             MERGEPAINT = 0x00BB0226, /* dest = (NOT source) OR dest     */  
  1315.             PATCOPY = 0x00F00021, /* dest = pattern                  */  
  1316.             PATPAINT = 0x00FB0A09, /* dest = DPSnoo                   */  
  1317.             PATINVERT = 0x005A0049, /* dest = pattern XOR dest         */  
  1318.             DSTINVERT = 0x00550009, /* dest = (NOT dest)               */  
  1319.             BLACKNESS = 0x00000042, /* dest = BLACK                    */  
  1320.             WHITENESS = 0x00FF0062 /* dest = WHITE                    */  
  1321.   
  1322.         }   
  1323.   
  1324.         public const int SRCCOPY = 0x00CC0020;   
  1325.   
  1326.         [DllImport("gdi32.dll")]   
  1327.         public static extern bool BitBlt(IntPtr hdcDst, int xDst, int yDst, int cx, int cy, IntPtr hdcSrc, int xSrc, int ySrc, uint ulRop);   
  1328.   
  1329.         [DllImport("gdi32.dll")]   
  1330.         public static extern bool StretchBlt(IntPtr hdcDst, int xDst, int yDst, int cx, int cy, IntPtr hdcSrc, int xSrc, int ySrc, int cxSrc, int cySrc, uint ulRop);   
  1331.   
  1332.         [DllImport("gdi32.dll")]   
  1333.         public static extern IntPtr CreateDC(IntPtr lpszDriver, string lpszDevice, IntPtr lpszOutput, IntPtr lpInitData);   
  1334.   
  1335.         [DllImport("gdi32.dll")]   
  1336.         public static extern IntPtr DeleteDC(IntPtr hdc);   
  1337.   
  1338.         [DllImport("gdi32.dll")]   
  1339.         public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth, int nHeight);   
  1340.   
  1341.         [DllImport("gdi32.dll")]   
  1342.         public static extern IntPtr CreateCompatibleDC(IntPtr hDC);   
  1343.   
  1344.         [DllImport("gdi32.dll")]   
  1345.         public static extern bool DeleteObject(IntPtr hObject);   
  1346.   
  1347.         [DllImport("gdi32.dll")]   
  1348.         public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);  
  1349.  
  1350.         #endregion  
  1351.  
  1352.         #region Shlwapi.dll   
  1353.   
  1354.         [DllImport("Shlwapi.dll")]   
  1355.         public static extern string PathGetArgs(string path);   
  1356.   
  1357.         public static string SafePathGetArgs(string path)   
  1358.         {   
  1359.             try  
  1360.             {   
  1361.                 return WinApi.PathGetArgs(path);   
  1362.             }   
  1363.             catch (System.Exception) { }   
  1364.             return string.Empty;   
  1365.         }   
  1366.   
  1367.         [DllImport("Shlwapi.dll")]   
  1368.         public static extern int PathCompactPathEx(   
  1369.             System.Text.StringBuilder pszOut, /* Address of the string that has been altered */  
  1370.             System.Text.StringBuilder pszSrc, /* Pointer to a null-terminated string of max length (MAX_PATH) that contains the path to be altered */  
  1371.             uint cchMax,                      /* Maximum number of chars to be contained in the new string, including the null character. Example: cchMax = 8, then 7 chars will be returned, the last for the null character. */  
  1372.             uint dwFlags);                    /* Reserved */  
  1373.   
  1374.         public static string PathCompactPathEx(string source, uint maxChars)   
  1375.         {   
  1376.             StringBuilder pszOut = new StringBuilder((int)WinApi.MAX_PATH);   
  1377.             StringBuilder pszSrc = new StringBuilder(source);   
  1378.   
  1379.             int result = WinApi.PathCompactPathEx(pszOut, pszSrc, maxChars, (uint)0);   
  1380.             if (result == 1)   
  1381.                 return pszOut.ToString();   
  1382.             else  
  1383.             {   
  1384.                 System.Diagnostics.Debug.WriteLine("Win32.PathCompactPathEx failed to compact the path '" + source + "' down to '" + maxChars + "' characters.");   
  1385.                 return string.Empty;   
  1386.             }   
  1387.         }  
  1388.  
  1389.         #endregion  
  1390.  
  1391.         #region Hotkeys   
  1392.   
  1393.         [Flags()]   
  1394.         public enum HotkeyModifiers   
  1395.         {   
  1396.             MOD_ALT = 0x0001,   
  1397.             MOD_CONTROL = 0x0002,   
  1398.             MOD_SHIFT = 0x0004,   
  1399.             MOD_WIN = 0x0008   
  1400.         }   
  1401.   
  1402.         [DllImport("User32")]   
  1403.         public static extern int RegisterHotKey(IntPtr hWnd, int id, uint modifiers, uint virtualkeyCode);   
  1404.   
  1405.         [DllImport("User32")]   
  1406.         public static extern int UnregisterHotKey(IntPtr hWnd, int id);   
  1407.   
  1408.         [DllImport("Kernel32")]   
  1409.         public static extern short GlobalAddAtom(string atomName);   
  1410.   
  1411.         [DllImport("Kernel32")]   
  1412.         public static extern short GlobalDeleteAtom(short atom);  
  1413.  
  1414.         #endregion   
  1415.   
  1416.         [DllImport("User32")]   
  1417.         public static extern int LockWindowUpdate(IntPtr windowHandle);   
  1418.   
  1419.         public static short MAKEWORD(byte a, byte b)   
  1420.         {   
  1421.             return ((short)(((byte)(a & 0xff)) | ((short)((byte)(b & 0xff))) << 8));   
  1422.         }   
  1423.   
  1424.         public static byte LOBYTE(short a)   
  1425.         {   
  1426.             return ((byte)(a & 0xff));   
  1427.         }   
  1428.   
  1429.         public static byte HIBYTE(short a)   
  1430.         {   
  1431.             return ((byte)(a >> 8));   
  1432.         }   
  1433.   
  1434.         public static int MAKELONG(short a, short b)   
  1435.         {   
  1436.             return (((int)(a & 0xffff)) | (((int)(b & 0xffff)) << 16));   
  1437.         }   
  1438.   
  1439.         public static short HIWORD(int a)   
  1440.         {   
  1441.             return ((short)(a >> 16));   
  1442.         }   
  1443.   
  1444.         public static short LOWORD(int a)   
  1445.         {   
  1446.             return ((short)(a & 0xffff));   
  1447.         }   
  1448.   
  1449.         [DllImport("Kernel32")]   
  1450.         public static extern int CopyFile(string source, string destination, int failIfExists);   
  1451.     }   
  1452.   
  1453. };  
原创粉丝点击