andrew4582

Win32 Api

Aug 15th, 2010
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 36.16 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Windows.Forms;
  4. using System.Drawing;
  5. using System.Runtime.InteropServices;
  6.  
  7. namespace System
  8. {
  9.       /// <summary>
  10.       /// Exposes constants, structures, enumerations, and functions from the Win32 API found in the Platform SDK.
  11.       /// </summary>
  12.       public class Win32
  13.       {
  14.             public const uint MAX_PATH = 260;
  15.  
  16.             #region Hooks - user32.dll
  17.  
  18.             /// <summary>
  19.             /// Defines the layout of the MouseHookStruct
  20.             /// </summary>
  21.             [StructLayout(LayoutKind.Sequential)]
  22.             public struct MSLLHOOKSTRUCT
  23.             {
  24.                   public Point Point;
  25.                   public int MouseData;
  26.                   public int Flags;
  27.                   public int Time;
  28.                   public int ExtraInfo;
  29.             }
  30.  
  31.             /// <summary>
  32.             ///  EventArgs class for use as parameters by HookEventHandler delegates
  33.             /// </summary>
  34.             public class HookEventArgs: EventArgs
  35.             {
  36.                   private int _code;
  37.                   private IntPtr _wParam;
  38.                   private IntPtr _lParam;
  39.  
  40.                   /// <summary>
  41.                   /// Initializes a new instance of the HookEventArgs class
  42.                   /// </summary>
  43.                   /// <param name="code">the hook code</param>
  44.                   /// <param name="wParam">hook specific information</param>
  45.                   /// <param name="lParam">hook specific information</param>
  46.                   public HookEventArgs(int code, IntPtr wParam, IntPtr lParam)
  47.                   {
  48.                         _code = code;
  49.                         _wParam = wParam;
  50.                         _lParam = lParam;
  51.                   }
  52.  
  53.                   /// <summary>
  54.                   /// The hook code
  55.                   /// </summary>
  56.                   public int Code
  57.                   {
  58.                         get
  59.                         {
  60.                               return _code;
  61.                         }
  62.                   }
  63.  
  64.                   /// <summary>
  65.                   /// A pointer to data
  66.                   /// </summary>
  67.                   public IntPtr wParam
  68.                   {
  69.                         get
  70.                         {
  71.                               return _wParam;
  72.                         }
  73.                   }
  74.  
  75.                   /// <summary>
  76.                   /// A pointer to data
  77.                   /// </summary>
  78.                   public IntPtr lParam
  79.                   {
  80.                         get
  81.                         {
  82.                               return _lParam;
  83.                         }
  84.                   }
  85.             }
  86.  
  87.             /// <summary>
  88.             /// Event delegate for use with the HookEventArgs class
  89.             /// </summary>
  90.             public delegate void HookEventHandler(object sender, HookEventArgs e);
  91.  
  92.             /// <summary>
  93.             /// Defines the various types of hooks that are available in Windows
  94.             /// </summary>
  95.             public enum HookTypes: int
  96.             {
  97.                   WH_JOURNALRECORD = 0,
  98.                   WH_JOURNALPLAYBACK = 1,
  99.                   WH_KEYBOARD = 2,
  100.                   WH_GETMESSAGE = 3,
  101.                   WH_CALLWNDPROC = 4,
  102.                   WH_CBT = 5,
  103.                   WH_SYSMSGFILTER = 6,
  104.                   WH_MOUSE = 7,
  105.                   WH_HARDWARE = 8,
  106.                   WH_DEBUG = 9,
  107.                   WH_SHELL = 10,
  108.                   WH_FOREGROUNDIDLE = 11,
  109.                   WH_CALLWNDPROCRET = 12,      
  110.                   WH_KEYBOARD_LL = 13,
  111.                   WH_MOUSE_LL = 14      
  112.             }
  113.            
  114.             public enum ShellHookMessages
  115.             {
  116.                   HSHELL_WINDOWCREATED = 1,
  117.                   HSHELL_WINDOWDESTROYED = 2,
  118.                   HSHELL_ACTIVATESHELLWINDOW = 3,
  119.                   HSHELL_WINDOWACTIVATED = 4,
  120.                   HSHELL_GETMINRECT = 5,
  121.                   HSHELL_REDRAW = 6,
  122.                   HSHELL_TASKMAN = 7,
  123.                   HSHELL_LANGUAGE = 8,
  124.                   HSHELL_ACCESSIBILITYSTATE =  11
  125.             }
  126.  
  127.             public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
  128.  
  129.             [DllImport("user32.dll")]
  130.             public static extern IntPtr SetWindowsHookEx(HookTypes hookType, HookProc hookProc, IntPtr hInstance, int nThreadId);
  131.  
  132.             [DllImport("user32.dll")]
  133.             public static extern int UnhookWindowsHookEx(IntPtr hookHandle);
  134.  
  135.             [DllImport("user32.dll")]
  136.             public static extern int CallNextHookEx(IntPtr hookHandle, int nCode, IntPtr wParam, IntPtr lParam);
  137.      
  138.             [DllImport("user32.dll")]
  139.             public static extern int RegisterShellHookWindow(IntPtr hWnd);
  140.  
  141.             [DllImport("user32.dll")]
  142.             public static extern int DeregisterShellHookWindow(IntPtr hWnd);
  143.  
  144.             #endregion Hooks
  145.  
  146.             #region System - Kernel32.dll
  147.  
  148.             [DllImport("kernel32.dll", EntryPoint="GetLastError", SetLastError=true, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
  149.             public static extern Int32 GetLastError();
  150.  
  151.             #endregion
  152.  
  153.             #region Windows - user32.dll
  154.  
  155.             public const int GWL_HWNDPARENT = (-8);
  156.             public const int GWL_EXSTYLE = (-20);
  157.             public const int GWL_STYLE = (-16);
  158.             public const int GCL_HICON = (-14);
  159.             public const int GCL_HICONSM = (-34);
  160.             public const int WM_QUERYDRAGICON = 0x37;
  161.             public const int WM_GETICON = 0x7F;
  162.             public const int WM_SETICON = 0x80;
  163.             public const int ICON_SMALL = 0;
  164.             public const int ICON_BIG = 1;
  165.             public const int SMTO_ABORTIFHUNG = 0x2;
  166.             public const int TRUE = 1;
  167.             public const int FALSE = 0;
  168.      
  169.             public const int WHITE_BRUSH         = 0;
  170.             public const int LTGRAY_BRUSH        = 1;
  171.             public const int GRAY_BRUSH          = 2;
  172.             public const int DKGRAY_BRUSH        = 3;
  173.             public const int BLACK_BRUSH         = 4;
  174.             public const int NULL_BRUSH          = 5;
  175.             public const int HOLLOW_BRUSH        = NULL_BRUSH;
  176.             public const int WHITE_PEN           = 6;
  177.             public const int BLACK_PEN           = 7;
  178.             public const int NULL_PEN            = 8;
  179.             public const int OEM_FIXED_FONT      = 10;
  180.             public const int ANSI_FIXED_FONT     = 11;
  181.             public const int ANSI_VAR_FONT       = 12;
  182.             public const int SYSTEM_FONT         = 13;
  183.             public const int DEVICE_DEFAULT_FONT = 14;
  184.             public const int DEFAULT_PALETTE     = 15;
  185.             public const int SYSTEM_FIXED_FONT   = 16;
  186.  
  187.  
  188.             public const int RDW_INVALIDATE          = 0x0001;
  189.             public const int RDW_INTERNALPAINT       = 0x0002;
  190.             public const int RDW_ERASE               = 0x0004;
  191.  
  192.             public const int RDW_VALIDATE            = 0x0008;
  193.             public const int RDW_NOINTERNALPAINT     = 0x0010;
  194.             public const int RDW_NOERASE             = 0x0020;
  195.  
  196.             public const int RDW_NOCHILDREN          = 0x0040;
  197.             public const int RDW_ALLCHILDREN         = 0x0080;
  198.  
  199.             public const int RDW_UPDATENOW           = 0x0100;
  200.             public const int RDW_ERASENOW            = 0x0200;
  201.  
  202.             public const int RDW_FRAME               = 0x0400;
  203.             public const int RDW_NOFRAME             = 0x0800;
  204.  
  205.  
  206.  
  207.             public enum ShowWindowCmds
  208.             {
  209.                   SW_HIDE             =0,
  210.                   SW_SHOWNORMAL       =1,
  211.                   SW_NORMAL           =1,
  212.                   SW_SHOWMINIMIZED    =2,
  213.                   SW_SHOWMAXIMIZED    =3,
  214.                   SW_MAXIMIZE         =3,
  215.                   SW_SHOWNOACTIVATE   =4,
  216.                   SW_SHOW             =5,
  217.                   SW_MINIMIZE         =6,
  218.                   SW_SHOWMINNOACTIVE  =7,
  219.                   SW_SHOWNA           =8,
  220.                   SW_RESTORE          =9,
  221.                   SW_SHOWDEFAULT      =10,
  222.                   SW_FORCEMINIMIZE    =11,
  223.                   SW_MAX              =11
  224.             }
  225.  
  226.             public const int HIDE_WINDOW         =0;
  227.             public const int SHOW_OPENWINDOW     =1;
  228.             public const int SHOW_ICONWINDOW     =2;
  229.             public const int SHOW_FULLSCREEN     =3;
  230.             public const int SHOW_OPENNOACTIVATE =4;
  231.             public const int SW_PARENTCLOSING    =1;
  232.             public const int SW_OTHERZOOM        =2;
  233.             public const int SW_PARENTOPENING    =3;
  234.             public const int SW_OTHERUNZOOM      =4;
  235.  
  236.             public const int SWP_NOSIZE          =0x0001;
  237.             public const int SWP_NOMOVE          =0x0002;
  238.             public const int SWP_NOZORDER        =0x0004;
  239.             public const int SWP_NOREDRAW        =0x0008;
  240.             public const int SWP_NOACTIVATE      =0x0010;
  241.             public const int SWP_FRAMECHANGED    =0x0020; /* The frame changed: send WM_NCCALCSIZE */
  242.             public const int SWP_SHOWWINDOW      =0x0040;
  243.             public const int SWP_HIDEWINDOW      =0x0080;
  244.             public const int SWP_NOCOPYBITS      =0x0100;
  245.             public const int SWP_NOOWNERZORDER   =0x0200; /* Don't do owner Z ordering */
  246.             public const int SWP_NOSENDCHANGING  =0x0400;  /* Don't send WM_WINDOWPOSCHANGING */
  247.             public const int SWP_DRAWFRAME       =SWP_FRAMECHANGED;
  248.             public const int SWP_NOREPOSITION    =SWP_NOOWNERZORDER;
  249.             public const int SWP_DEFERERASE      =0x2000;
  250.             public const int SWP_ASYNCWINDOWPOS  =0x4000;
  251.      
  252.             public const int HWND_TOP        =0;
  253.             public const int HWND_BOTTOM     =1;
  254.             public const int HWND_TOPMOST    =-1;
  255.             public const int HWND_NOTOPMOST  =-2;
  256.  
  257.             public enum PeekMessageFlags
  258.             {
  259.                   PM_NOREMOVE       = 0,
  260.                   PM_REMOVE         = 1,
  261.                   PM_NOYIELD        = 2
  262.             }
  263.      
  264.             public enum WindowMessages
  265.             {
  266.                   WM_NULL                   = 0x0000,
  267.                   WM_CREATE                 = 0x0001,
  268.                   WM_DESTROY                = 0x0002,
  269.                   WM_MOVE                   = 0x0003,
  270.                   WM_SIZE                   = 0x0005,
  271.                   WM_ACTIVATE               = 0x0006,
  272.                   WM_SETFOCUS               = 0x0007,
  273.                   WM_KILLFOCUS              = 0x0008,
  274.                   WM_ENABLE                 = 0x000A,
  275.                   WM_SETREDRAW              = 0x000B,
  276.                   WM_SETTEXT                = 0x000C,
  277.                   WM_GETTEXT                = 0x000D,
  278.                   WM_GETTEXTLENGTH          = 0x000E,
  279.                   WM_PAINT                  = 0x000F,
  280.                   WM_CLOSE                  = 0x0010,
  281.                   WM_QUERYENDSESSION        = 0x0011,
  282.                   WM_QUIT                   = 0x0012,
  283.                   WM_QUERYOPEN              = 0x0013,
  284.                   WM_ERASEBKGND             = 0x0014,
  285.                   WM_SYSCOLORCHANGE         = 0x0015,
  286.                   WM_ENDSESSION             = 0x0016,
  287.                   WM_SHOWWINDOW             = 0x0018,
  288.                   WM_CTLCOLOR               = 0x0019,
  289.                   WM_WININICHANGE           = 0x001A,
  290.                   WM_SETTINGCHANGE          = 0x001A,
  291.                   WM_DEVMODECHANGE          = 0x001B,
  292.                   WM_ACTIVATEAPP            = 0x001C,
  293.                   WM_FONTCHANGE             = 0x001D,
  294.                   WM_TIMECHANGE             = 0x001E,
  295.                   WM_CANCELMODE             = 0x001F,
  296.                   WM_SETCURSOR              = 0x0020,
  297.                   WM_MOUSEACTIVATE          = 0x0021,
  298.                   WM_CHILDACTIVATE          = 0x0022,
  299.                   WM_QUEUESYNC              = 0x0023,
  300.                   WM_GETMINMAXINFO          = 0x0024,
  301.                   WM_PAINTICON              = 0x0026,
  302.                   WM_ICONERASEBKGND         = 0x0027,
  303.                   WM_NEXTDLGCTL             = 0x0028,
  304.                   WM_SPOOLERSTATUS          = 0x002A,
  305.                   WM_DRAWITEM               = 0x002B,
  306.                   WM_MEASUREITEM            = 0x002C,
  307.                   WM_DELETEITEM             = 0x002D,
  308.                   WM_VKEYTOITEM             = 0x002E,
  309.                   WM_CHARTOITEM             = 0x002F,
  310.                   WM_SETFONT                = 0x0030,
  311.                   WM_GETFONT                = 0x0031,
  312.                   WM_SETHOTKEY              = 0x0032,
  313.                   WM_GETHOTKEY              = 0x0033,
  314.                   WM_QUERYDRAGICON          = 0x0037,
  315.                   WM_COMPAREITEM            = 0x0039,
  316.                   WM_GETOBJECT              = 0x003D,
  317.                   WM_COMPACTING             = 0x0041,
  318.                   WM_COMMNOTIFY             = 0x0044 ,
  319.                   WM_WINDOWPOSCHANGING      = 0x0046,
  320.                   WM_WINDOWPOSCHANGED       = 0x0047,
  321.                   WM_POWER                  = 0x0048,
  322.                   WM_COPYDATA               = 0x004A,
  323.                   WM_CANCELJOURNAL          = 0x004B,
  324.                   WM_NOTIFY                 = 0x004E,
  325.                   WM_INPUTLANGCHANGEREQUEST = 0x0050,
  326.                   WM_INPUTLANGCHANGE        = 0x0051,
  327.                   WM_TCARD                  = 0x0052,
  328.                   WM_HELP                   = 0x0053,
  329.                   WM_USERCHANGED            = 0x0054,
  330.                   WM_NOTIFYFORMAT           = 0x0055,
  331.                   WM_CONTEXTMENU            = 0x007B,
  332.                   WM_STYLECHANGING          = 0x007C,
  333.                   WM_STYLECHANGED           = 0x007D,
  334.                   WM_DISPLAYCHANGE          = 0x007E,
  335.                   WM_GETICON                = 0x007F,
  336.                   WM_SETICON                = 0x0080,
  337.                   WM_NCCREATE               = 0x0081,
  338.                   WM_NCDESTROY              = 0x0082,
  339.                   WM_NCCALCSIZE             = 0x0083,
  340.                   WM_NCHITTEST              = 0x0084,
  341.                   WM_NCPAINT                = 0x0085,
  342.                   WM_NCACTIVATE             = 0x0086,
  343.                   WM_GETDLGCODE             = 0x0087,
  344.                   WM_SYNCPAINT              = 0x0088,
  345.                   WM_NCMOUSEMOVE            = 0x00A0,
  346.                   WM_NCLBUTTONDOWN          = 0x00A1,
  347.                   WM_NCLBUTTONUP            = 0x00A2,
  348.                   WM_NCLBUTTONDBLCLK        = 0x00A3,
  349.                   WM_NCRBUTTONDOWN          = 0x00A4,
  350.                   WM_NCRBUTTONUP            = 0x00A5,
  351.                   WM_NCRBUTTONDBLCLK        = 0x00A6,
  352.                   WM_NCMBUTTONDOWN          = 0x00A7,
  353.                   WM_NCMBUTTONUP            = 0x00A8,
  354.                   WM_NCMBUTTONDBLCLK        = 0x00A9,
  355.                   WM_KEYDOWN                = 0x0100,
  356.                   WM_KEYUP                  = 0x0101,
  357.                   WM_CHAR                   = 0x0102,
  358.                   WM_DEADCHAR               = 0x0103,
  359.                   WM_SYSKEYDOWN             = 0x0104,
  360.                   WM_SYSKEYUP               = 0x0105,
  361.                   WM_SYSCHAR                = 0x0106,
  362.                   WM_SYSDEADCHAR            = 0x0107,
  363.                   WM_KEYLAST                = 0x0108,
  364.                   WM_IME_STARTCOMPOSITION   = 0x010D,
  365.                   WM_IME_ENDCOMPOSITION     = 0x010E,
  366.                   WM_IME_COMPOSITION        = 0x010F,
  367.                   WM_IME_KEYLAST            = 0x010F,
  368.                   WM_INITDIALOG             = 0x0110,
  369.                   WM_COMMAND                = 0x0111,
  370.                   WM_SYSCOMMAND             = 0x0112,
  371.                   WM_TIMER                  = 0x0113,
  372.                   WM_HSCROLL                = 0x0114,
  373.                   WM_VSCROLL                = 0x0115,
  374.                   WM_INITMENU               = 0x0116,
  375.                   WM_INITMENUPOPUP          = 0x0117,
  376.                   WM_MENUSELECT             = 0x011F,
  377.                   WM_MENUCHAR               = 0x0120,
  378.                   WM_ENTERIDLE              = 0x0121,
  379.                   WM_MENURBUTTONUP          = 0x0122,
  380.                   WM_MENUDRAG               = 0x0123,
  381.                   WM_MENUGETOBJECT          = 0x0124,
  382.                   WM_UNINITMENUPOPUP        = 0x0125,
  383.                   WM_MENUCOMMAND            = 0x0126,
  384.                   WM_CTLCOLORMSGBOX         = 0x0132,
  385.                   WM_CTLCOLOREDIT           = 0x0133,
  386.                   WM_CTLCOLORLISTBOX        = 0x0134,
  387.                   WM_CTLCOLORBTN            = 0x0135,
  388.                   WM_CTLCOLORDLG            = 0x0136,
  389.                   WM_CTLCOLORSCROLLBAR      = 0x0137,
  390.                   WM_CTLCOLORSTATIC         = 0x0138,
  391.                   WM_MOUSEMOVE              = 0x0200,
  392.                   WM_LBUTTONDOWN            = 0x0201,
  393.                   WM_LBUTTONUP              = 0x0202,
  394.                   WM_LBUTTONDBLCLK          = 0x0203,
  395.                   WM_RBUTTONDOWN            = 0x0204,
  396.                   WM_RBUTTONUP              = 0x0205,
  397.                   WM_RBUTTONDBLCLK          = 0x0206,
  398.                   WM_MBUTTONDOWN            = 0x0207,
  399.                   WM_MBUTTONUP              = 0x0208,
  400.                   WM_MBUTTONDBLCLK          = 0x0209,
  401.                   WM_MOUSEWHEEL             = 0x020A,
  402.                   WM_PARENTNOTIFY           = 0x0210,
  403.                   WM_ENTERMENULOOP          = 0x0211,
  404.                   WM_EXITMENULOOP           = 0x0212,
  405.                   WM_NEXTMENU               = 0x0213,
  406.                   WM_SIZING                 = 0x0214,
  407.                   WM_CAPTURECHANGED         = 0x0215,
  408.                   WM_MOVING                 = 0x0216,
  409.                   WM_DEVICECHANGE           = 0x0219,
  410.                   WM_MDICREATE              = 0x0220,
  411.                   WM_MDIDESTROY             = 0x0221,
  412.                   WM_MDIACTIVATE            = 0x0222,
  413.                   WM_MDIRESTORE             = 0x0223,
  414.                   WM_MDINEXT                = 0x0224,
  415.                   WM_MDIMAXIMIZE            = 0x0225,
  416.                   WM_MDITILE                = 0x0226,
  417.                   WM_MDICASCADE             = 0x0227,
  418.                   WM_MDIICONARRANGE         = 0x0228,
  419.                   WM_MDIGETACTIVE           = 0x0229,
  420.                   WM_MDISETMENU             = 0x0230,
  421.                   WM_ENTERSIZEMOVE          = 0x0231,
  422.                   WM_EXITSIZEMOVE           = 0x0232,
  423.                   WM_DROPFILES              = 0x0233,
  424.                   WM_MDIREFRESHMENU         = 0x0234,
  425.                   WM_IME_SETCONTEXT         = 0x0281,
  426.                   WM_IME_NOTIFY             = 0x0282,
  427.                   WM_IME_CONTROL            = 0x0283,
  428.                   WM_IME_COMPOSITIONFULL    = 0x0284,
  429.                   WM_IME_SELECT             = 0x0285,
  430.                   WM_IME_CHAR               = 0x0286,
  431.                   WM_IME_REQUEST            = 0x0288,
  432.                   WM_IME_KEYDOWN            = 0x0290,
  433.                   WM_IME_KEYUP              = 0x0291,
  434.                   WM_MOUSEHOVER             = 0x02A1,
  435.                   WM_MOUSELEAVE             = 0x02A3,
  436.                   WM_CUT                    = 0x0300,
  437.                   WM_COPY                   = 0x0301,
  438.                   WM_PASTE                  = 0x0302,
  439.                   WM_CLEAR                  = 0x0303,
  440.                   WM_UNDO                   = 0x0304,
  441.                   WM_RENDERFORMAT           = 0x0305,
  442.                   WM_RENDERALLFORMATS       = 0x0306,
  443.                   WM_DESTROYCLIPBOARD       = 0x0307,
  444.                   WM_DRAWCLIPBOARD          = 0x0308,
  445.                   WM_PAINTCLIPBOARD         = 0x0309,
  446.                   WM_VSCROLLCLIPBOARD       = 0x030A,
  447.                   WM_SIZECLIPBOARD          = 0x030B,
  448.                   WM_ASKCBFORMATNAME        = 0x030C,
  449.                   WM_CHANGECBCHAIN          = 0x030D,
  450.                   WM_HSCROLLCLIPBOARD       = 0x030E,
  451.                   WM_QUERYNEWPALETTE        = 0x030F,
  452.                   WM_PALETTEISCHANGING      = 0x0310,
  453.                   WM_PALETTECHANGED         = 0x0311,
  454.                   WM_HOTKEY                 = 0x0312,
  455.                   WM_PRINT                  = 0x0317,
  456.                   WM_PRINTCLIENT            = 0x0318,
  457.                   WM_HANDHELDFIRST          = 0x0358,
  458.                   WM_HANDHELDLAST           = 0x035F,
  459.                   WM_AFXFIRST               = 0x0360,
  460.                   WM_AFXLAST                = 0x037F,
  461.                   WM_PENWINFIRST            = 0x0380,
  462.                   WM_PENWINLAST             = 0x038F,
  463.                   WM_APP                    = 0x8000,
  464.                   WM_USER                   = 0x0400,
  465.                   WM_REFLECT                = WM_USER + 0x1c00
  466.             }
  467.  
  468.             /// <summary>
  469.             /// Defines the style bits that a window can have
  470.             /// </summary>
  471.             public enum WindowStyles: uint
  472.             {
  473.                   WS_BORDER = 0x800000,
  474.                   WS_CAPTION = 0xC00000,//               '  WS_BORDER Or WS_DLGFRAME
  475.                   WS_CHILD = 0x40000000,
  476.                   WS_CHILDWINDOW = (WS_CHILD),
  477.                   WS_CLIPCHILDREN = 0x2000000,
  478.                   WS_CLIPSIBLINGS = 0x4000000,
  479.                   WS_DISABLED = 0x8000000,
  480.                   WS_DLGFRAME = 0x400000,
  481.                   WS_EX_ACCEPTFILES = 0x10,
  482.                   WS_EX_DLGMODALFRAME = 0x1,
  483.                   WS_EX_NOPARENTNOTIFY = 0x4,
  484.                   WS_EX_TOPMOST = 0x8,
  485.                   WS_EX_TRANSPARENT = 0x20,
  486.                   WS_EX_TOOLWINDOW = 0x80,
  487.                   WS_EX_APPWINDOW = 0x40000,
  488.                   WS_GROUP = 0x20000,
  489.                   WS_HSCROLL = 0x100000,
  490.                   WS_MAXIMIZE = 0x1000000,
  491.                   WS_MAXIMIZEBOX = 0x10000,
  492.                   WS_MINIMIZE = 0x20000000,
  493.                   WS_MINIMIZEBOX = 0x20000,
  494.                   WS_OVERLAPPED = 0x0,
  495.                   WS_POPUP = 0x80000000,
  496.                   WS_SYSMENU = 0x80000,
  497.                   WS_TABSTOP = 0x10000,
  498.                   WS_THICKFRAME = 0x40000,
  499.                   WS_VISIBLE = 0x10000000,
  500.                   WS_VSCROLL = 0x200000,
  501.                   WS_ICONIC = WS_MINIMIZE,
  502.                   WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU),
  503.                   WS_SIZEBOX = WS_THICKFRAME,
  504.                   WS_TILED = WS_OVERLAPPED,
  505.                   WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)  
  506.             }
  507.  
  508.             public struct WindowInfo
  509.             {
  510.                   public int size;
  511.                   public Rectangle window;
  512.                   public Rectangle client;
  513.                   public int style;
  514.                   public int exStyle;
  515.                   public int windowStatus;
  516.                   public uint xWindowBorders;
  517.                   public uint yWindowBorders;
  518.                   public short atomWindowtype;
  519.                   public short creatorVersion;
  520.             }
  521.  
  522.             public struct WindowPlacement
  523.             {
  524.                   public int length;
  525.                   public int flags;
  526.                   public int showCmd;
  527.                   public Point minPosition;
  528.                   public Point maxPosition;
  529.                   public Rectangle normalPosition;
  530.             }
  531.  
  532.             public struct Rect
  533.             {
  534.                   public int left;
  535.                   public int top;
  536.                   public int right;
  537.                   public int bottom;
  538.  
  539.                   public int Width
  540.                   {
  541.                         get
  542.                         {
  543.                               return right - left;
  544.                         }
  545.                   }
  546.  
  547.                   public int Height
  548.                   {
  549.                         get
  550.                         {
  551.                               return bottom - top;
  552.                         }
  553.                   }
  554.             }
  555.  
  556.             public delegate bool EnumWindowEventHandler(IntPtr hWnd, Int32 lParam);
  557.  
  558.             [DllImport("user32.dll")]
  559.             public static extern int GetWindowModuleFileName(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
  560.  
  561.             [DllImport("user32.dll")]
  562.             public static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
  563.  
  564.             [DllImport("user32.dll")]
  565.             public static extern bool GetWindowPlacement(IntPtr window, ref WindowPlacement position);
  566.  
  567.             [DllImport("User32.dll")]
  568.             public static extern int RegisterWindowMessage(string message);
  569.  
  570.             [DllImport("User32.dll")]
  571.             public static extern void EnumWindows(EnumWindowEventHandler callback, Int32 lParam);
  572.  
  573.             //          [DllImport("User32.dll")]
  574.             //          public static extern Int32 GetWindowText(IntPtr hWnd, StringBuilder lpString, Int32 nMaxCount);
  575.    
  576.             [DllImport("User32.dll")]
  577.             public static extern bool IsWindowVisible(IntPtr hWnd);
  578.  
  579.             [DllImport("User32.dll")]
  580.             public static extern Int32 GetWindow(IntPtr hWnd, Int32 wCmd);
  581.  
  582.             //          [DllImport("User32.dll")]
  583.             //          public static extern WindowStyles GetWindowLong(IntPtr hWnd, Int32 index);
  584.  
  585.             [DllImport("User32.dll")]
  586.             public static extern IntPtr GetParent(IntPtr hWnd);
  587.            
  588.             [DllImport("User32.dll")]
  589.             public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
  590.  
  591.             [DllImport("User32.dll")]
  592.             public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
  593.    
  594.             [DllImport("User32.dll")]
  595.             public static extern WindowStyles GetWindowLong(IntPtr hWnd, int index);
  596.  
  597.             [DllImport("User32.dll")]
  598.             public static extern int SendMessageTimeout(IntPtr hWnd, int uMsg, int wParam, int lParam, int fuFlags, int uTimeout, out int lpdwResult);
  599.            
  600.             [DllImport("User32.dll")]
  601.             public static extern int GetClassLong(IntPtr hWnd, int index);
  602.            
  603.             [DllImport("User32.dll")]
  604.             public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
  605.  
  606.             [DllImport("User32.dll")]
  607.             public static extern int SendMessage(IntPtr hWnd, int uMsg, IntPtr wParam, IntPtr lParam);
  608.            
  609.             [DllImport("User32.dll")]
  610.             public static extern int PostMessage(IntPtr hWnd, int uMsg, IntPtr wParam, IntPtr lParam);
  611.  
  612.             [DllImport("User32.dll")]
  613.             public static extern void SwitchToThisWindow(IntPtr hWnd, int altTabActivated);
  614.  
  615.             [DllImport("User32.dll")]
  616.             public static extern int ShowWindowAsync(IntPtr hWnd, int command);
  617.      
  618.             [DllImport("user32.dll")]
  619.             public static extern IntPtr GetDesktopWindow();
  620.  
  621.             [DllImport("user32.dll")]
  622.             public static extern IntPtr GetForegroundWindow();
  623.  
  624.             [DllImport("user32.dll")]
  625.             public static extern bool BringWindowToTop(IntPtr window);
  626.  
  627.             [DllImport("user32.dll")]
  628.             public static extern bool GetWindowInfo(IntPtr hwnd, ref WindowInfo info);
  629.  
  630.             [DllImport("user32.dll")]
  631.             public static extern IntPtr GetWindowDC(IntPtr hwnd);
  632.            
  633.             [DllImport("user32.dll")]
  634.             public static extern IntPtr GetDC(IntPtr hwnd);
  635.            
  636.             [DllImport("user32.dll")]
  637.             public static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
  638.            
  639.             [DllImport("user32.dll")]
  640.             public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);
  641.            
  642.             [DllImport("user32.dll")]
  643.             public static extern bool GetClientRect(IntPtr hwnd, ref Rect rectangle);
  644.  
  645.             [DllImport("user32.dll")]
  646.             public static extern IntPtr WindowFromPoint(Point pt);
  647.            
  648.             [DllImport("user32.dll")]
  649.             public static extern IntPtr SetCapture(IntPtr hWnd);
  650.  
  651.             [DllImport("user32.dll")]
  652.             public static extern int ReleaseCapture();
  653.            
  654.             [DllImport("user32.dll")]
  655.             public static extern IntPtr SelectObject(IntPtr hDc, IntPtr hObject);
  656.  
  657.             [DllImport("user32.dll")]
  658.             public static extern IntPtr GetStockObject(int nObject);
  659.  
  660.             [DllImport("user32.dll")]
  661.             public static extern int InvalidateRect(IntPtr hWnd, IntPtr lpRect, int bErase);
  662.  
  663.             [DllImport("user32.dll")]
  664.             public static extern int UpdateWindow(IntPtr hWnd);
  665.  
  666.             [DllImport("user32.dll")]
  667.             public static extern int RedrawWindow(IntPtr hWnd, IntPtr lprcUpdate, IntPtr hrgnUpdate, uint flags);
  668.  
  669.             #endregion Windows
  670.  
  671.             #region GDI - gdi32.dll
  672.  
  673.             public enum BinaryRasterOperations
  674.             {
  675.                   R2_BLACK            =1,   /*  0       */
  676.                   R2_NOTMERGEPEN      =2,   /* DPon     */
  677.                   R2_MASKNOTPEN       =3,   /* DPna     */
  678.                   R2_NOTCOPYPEN       =4,   /* PN       */
  679.                   R2_MASKPENNOT       =5,   /* PDna     */
  680.                   R2_NOT              =6,   /* Dn       */
  681.                   R2_XORPEN           =7,   /* DPx      */
  682.                   R2_NOTMASKPEN       =8,   /* DPan     */
  683.                   R2_MASKPEN          =9,   /* DPa      */
  684.                   R2_NOTXORPEN        =10,  /* DPxn     */
  685.                   R2_NOP              =11,  /* D        */
  686.                   R2_MERGENOTPEN      =12,  /* DPno     */
  687.                   R2_COPYPEN          =13,  /* P        */
  688.                   R2_MERGEPENNOT      =14,  /* PDno     */
  689.                   R2_MERGEPEN         =15,  /* DPo      */
  690.                   R2_WHITE            =16,  /*  1       */
  691.                   R2_LAST             =16
  692.             }
  693.  
  694.             public enum TernaryRasterOperations
  695.             {
  696.                   SRCCOPY            = 0x00CC0020, /* dest = source                   */
  697.                   SRCPAINT           = 0x00EE0086, /* dest = source OR dest           */
  698.                   SRCAND             = 0x008800C6, /* dest = source AND dest          */
  699.                   SRCINVERT          = 0x00660046, /* dest = source XOR dest          */
  700.                   SRCERASE           = 0x00440328, /* dest = source AND (NOT dest )   */
  701.                   NOTSRCCOPY         = 0x00330008, /* dest = (NOT source)             */
  702.                   NOTSRCERASE        = 0x001100A6, /* dest = (NOT src) AND (NOT dest) */
  703.                   MERGECOPY          = 0x00C000CA, /* dest = (source AND pattern)     */
  704.                   MERGEPAINT         = 0x00BB0226, /* dest = (NOT source) OR dest     */
  705.                   PATCOPY            = 0x00F00021, /* dest = pattern                  */
  706.                   PATPAINT           = 0x00FB0A09, /* dest = DPSnoo                   */
  707.                   PATINVERT          = 0x005A0049, /* dest = pattern XOR dest         */
  708.                   DSTINVERT          = 0x00550009, /* dest = (NOT dest)               */
  709.                   BLACKNESS          = 0x00000042, /* dest = BLACK                    */
  710.                   WHITENESS          = 0x00FF0062 /* dest = WHITE                    */
  711.  
  712.             }
  713.  
  714.             [DllImport("gdi32.dll")]
  715.             public static extern bool BitBlt(IntPtr hdcDst, int xDst, int yDst, int cx, int cy, IntPtr hdcSrc, int xSrc, int ySrc, uint ulRop);
  716.            
  717.             [DllImport("gdi32.dll")]
  718.             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);
  719.  
  720.             [DllImport("gdi32.dll")]
  721.             public static extern IntPtr CreateDC(IntPtr lpszDriver, string lpszDevice, IntPtr lpszOutput, IntPtr lpInitData);
  722.            
  723.             [DllImport("gdi32.dll")]
  724.             public static extern IntPtr DeleteDC(IntPtr hdc);
  725.  
  726.             #endregion
  727.  
  728.             #region Shlwapi.dll
  729.  
  730.             [DllImport("Shlwapi.dll")]
  731.             public static extern string PathGetArgs(string path);
  732.  
  733.             public static string SafePathGetArgs(string path)
  734.             {
  735.                   try
  736.                   {
  737.                         return Win32.PathGetArgs(path);
  738.                   }
  739.                   catch(System.Exception) {}
  740.                   return string.Empty;
  741.             }
  742.  
  743.             [DllImport("Shlwapi.dll")]
  744.             public static extern int PathCompactPathEx(
  745.                   System.Text.StringBuilder pszOut, /* Address of the string that has been altered */
  746.                   System.Text.StringBuilder pszSrc, /* Pointer to a null-terminated string of max length (MAX_PATH) that contains the path to be altered */
  747.                   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. */
  748.                   uint dwFlags);                              /* Reserved */
  749.  
  750.             public static string PathCompactPathEx(string source, uint maxChars)
  751.             {                
  752.                   StringBuilder pszOut = new StringBuilder((int)Win32.MAX_PATH);
  753.                   StringBuilder pszSrc = new StringBuilder(source);
  754.  
  755.                   int result = Win32.PathCompactPathEx(pszOut, pszSrc, maxChars, (uint)0);
  756.                   if (result == 1)
  757.                         return pszOut.ToString();
  758.                   else
  759.                   {
  760.                         System.Diagnostics.Debug.WriteLine("Win32.PathCompactPathEx failed to compact the path '" + source + "' down to '" + maxChars + "' characters.");
  761.                         return string.Empty;
  762.                   }
  763.             }
  764.  
  765.             #endregion
  766.  
  767.             #region Hotkeys
  768.  
  769.             [Flags()]
  770.                   public enum HotkeyModifiers
  771.             {
  772.                   MOD_ALT         = 0x0001,
  773.                   MOD_CONTROL     = 0x0002,
  774.                   MOD_SHIFT       = 0x0004,
  775.                   MOD_WIN         = 0x0008
  776.             }
  777.  
  778.             [DllImport("User32")]
  779.             public static extern int RegisterHotKey(IntPtr hWnd, int id, uint modifiers, uint virtualkeyCode);
  780.  
  781.             [DllImport("User32")]
  782.             public static extern int UnregisterHotKey(IntPtr hWnd, int id);
  783.  
  784.             [DllImport("Kernel32")]
  785.             public static extern short GlobalAddAtom(string atomName);
  786.  
  787.             [DllImport("Kernel32")]
  788.             public static extern short GlobalDeleteAtom(short atom);        
  789.  
  790.             #endregion
  791.  
  792.             [DllImport("User32")]
  793.             public static extern int LockWindowUpdate(IntPtr windowHandle);
  794.  
  795.             public static short MAKEWORD(byte a, byte b)
  796.             {
  797.                   return ((short)(((byte)(a & 0xff)) | ((short)((byte)(b & 0xff))) << 8));
  798.             }
  799.  
  800.             public static byte LOBYTE(short a)
  801.             {
  802.                   return ((byte)(a & 0xff));
  803.             }
  804.  
  805.             public static byte HIBYTE(short a)
  806.             {
  807.                   return ((byte)(a >> 8));
  808.             }
  809.  
  810.             public static int MAKELONG(short a, short b)
  811.             {
  812.                   return ( ((int)(a & 0xffff)) | (((int)(b & 0xffff)) << 16) );
  813.             }
  814.  
  815.             public static short HIWORD(int a)
  816.             {
  817.                   return ((short)(a >> 16));
  818.             }
  819.  
  820.             public static short LOWORD(int a)
  821.             {
  822.                   return ((short)(a & 0xffff));
  823.             }          
  824.  
  825.             [DllImport("Kernel32")]
  826.             public static extern int CopyFile(string source, string destination, int failIfExists);
  827.       }
  828.  
  829.  
  830. }
Advertisement
Add Comment
Please, Sign In to add comment