给网页赋值参考信息
来源:互联网 发布:mysql case 编辑:程序博客网 时间:2024/05/19 03:46
想用C#做一个Maxthon按钮插件,Maxthon按钮插件的配置文件plugin.ini如下。 [General]Name=ConsoleAppAuthor=阿良Version=1.0ModuleType=EXEFileName=ConsoleApp.exeComments=Exe type ButtonType=M2Plugin_BUTTONIcon=Icon.ico
命令行格式如下 ConsoleApp.exe -h=Maxthon的句柄 -u=当前页面URL -wie=当前页面Internet Explorer_Server的句柄
下面就是通过Internet Explorer_Server句柄获得IHTMLDocument2和IHTMLWindow2的接口。获得接口后就可以对HTML页面进行更改了。
以下是控制台项目的三个主要文件。可以在附件栏中下载。注意要添加三个引用:Accessibility,Microsoft.mshtml,SHDocVw.dll.这三个引用属性【复制本地】要设为true,做Maxthon插件时要将bin目录下生成的所有dll和ConsoleApp.exe一起复制才有作用。
Program.cs using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Text.RegularExpressions;using System.Runtime.InteropServices;using System.Windows.Forms;using SHDocVw;using mshtml;namespace ConsoleApp{ class Program { static void Main(string[] args) { string commandLine = Environment.CommandLine; string url = GetUrlFromCommandLine(commandLine); int maxthonHandle = GetMaxthonHandleFromCommandLine(commandLine); int explorerHandle = GetExplorerHandleFromCommandLine(commandLine); string message = "URL=" + url + Environment.NewLine + "MaxthonHandle=" + maxthonHandle + Environment.NewLine + "ExplorerHandle=" + explorerHandle + Environment.NewLine; IntPtr ptr = (IntPtr)explorerHandle; IHTMLDocument2 doc; IHTMLWindow2 win; GetInterfacesByHandleOfInternetExplorer_Server(ptr, out win, out doc); if (doc == null || win == null) { message += "GetInterfacesByHandleOfInternetExplorer_Server失败" + Environment.NewLine; MessageBox.Show(message); } else { message += "url from IHTMLDocument2=" + doc.url + Environment.NewLine; message += "url from IHTMLWindow2=" + win.location.href + Environment.NewLine; MessageBox.Show(message); win.execScript(@"var changeColor = confirm('真的要改背景颜色为绿色吗?'); if (changeColor) document.body.style.backgroundColor='green';", "javascript"); } } static void GetInterfacesByHandleOfInternetExplorer_Server(IntPtr hwndInterneExplorer_Server, out IHTMLWindow2 window, out IHTMLDocument2 document) { window = null; document = null; Guid IID_IWebBrowser2 = typeof(SHDocVw.IWebBrowser2).GUID; Guid IID_IServiceProvider = typeof(IServiceProvider).GUID; Guid IID_IHTMLDocument2 = typeof(IHTMLDocument2).GUID; Guid IID_IHTMLWindow2 = typeof(IHTMLWindow2).GUID; Guid SID_SWebBrowserApp = typeof(SHDocVw.IWebBrowserApp).GUID; try { int nMsg = WinApi.RegisterWindowMessage("WM_HTML_GETOBJECT"); UIntPtr lRes; WinApi.SendMessageTimeout(hwndInterneExplorer_Server, nMsg, 0, 0, WinApi.SMTO_ABORTIFHUNG, 1000, out lRes); if (!(bool)(lRes.ToUInt32() == 0)) { int hr = WinApi.ObjectFromLresult((int)lRes.ToUInt32(), ref IID_IHTMLDocument2, 0, out document); if ((document != null)) { IntPtr puk = Marshal.GetIUnknownForObject(document); IServiceProvider pro = document as IServiceProvider; //Console.Write((pro == null).ToString()); object objIWebBrowser2; pro.QueryService(ref SID_SWebBrowserApp, ref IID_IWebBrowser2, out objIWebBrowser2); IWebBrowser2 web = objIWebBrowser2 as IWebBrowser2; object objHtmlWindow; pro.QueryService(ref IID_IHTMLWindow2, ref IID_IHTMLWindow2, out objHtmlWindow); window = objHtmlWindow as IHTMLWindow2; } } } catch { } } #region static string GetUrlFromCommandLine(string commandLine) { Regex regex = new Regex(@" -u=(?<Url>.+?) -wie"); Match match = regex.Match(commandLine); if (match.Success) { return match.Groups["Url"].Value; } else { return string.Empty; } } static int GetMaxthonHandleFromCommandLine(string commandLine) { Regex regex = new Regex(@" -h=(?<Handle>/d+)"); Match match = regex.Match(commandLine); if (match.Success) { return int.Parse(match.Groups["Handle"].Value); } else { return 0; } } static int GetExplorerHandleFromCommandLine(string commandLine) { Regex regex = new Regex(@" -wie=(?<Handle>/d+)"); Match match = regex.Match(commandLine); if (match.Success) { return int.Parse(match.Groups["Handle"].Value); } else { return 0; } } #endregion }}
IServiceProvider.cs using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.InteropServices;namespace ConsoleApp{ [ ComImport, Guid("6d5140c1-7436-11ce-8034-00aa006009fa"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown) ] public interface IServiceProvider { void QueryService(ref Guid guidService, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppvObject); }}
WinApi.cs,在google code搜索的,我也不知道怎样定义的 using System;using System.Text;using System.Windows.Forms;using System.Drawing;using System.Runtime.InteropServices;using Accessibility;using mshtml;namespace ConsoleApp{ public sealed class WinApi { //Not allow to create instance private WinApi() { } public const uint MAX_PATH = 260; #region Hooks - user32.dll /// <summary> /// Defines the layout of the MouseHookStruct /// </summary> [StructLayout(LayoutKind.Sequential)] public struct MSLLHOOKSTRUCT { public Point Point; public int MouseData; public int Flags; public int Time; public int ExtraInfo; } [StructLayout(LayoutKind.Sequential)] public struct POINT { public int x; public int y; } [StructLayout(LayoutKind.Sequential)] public struct MouseHookStruct { /// <summary> /// Specifies a POINT structure that contains the x- and y-coordinates of the cursor, in screen coordinates. /// </summary> public POINT Point; public UInt32 MouseData; public UInt32 Flags; public UInt32 Time; public UInt32 ExtraInfo; } /// <summary> /// ¼üÅ̹³×Óʼþ½á¹¹¶¨Òå /// </summary> /// <remarks>Ïêϸ˵Ã÷Çë²Î¿¼MSDNÖйØÓÚ KBDLLHOOKSTRUCT µÄ˵Ã÷</remarks> [StructLayout(LayoutKind.Sequential)] public struct KeyboardHookStruct { /// <summary> /// Specifies a virtual-key code. The code must be a value in the range 1 to 254. /// </summary> public UInt32 VKCode; /// <summary> /// Specifies a hardware scan code for the key. /// </summary> public UInt32 ScanCode; /// <summary> /// Specifies the extended-key flag, event-injected flag, context code, /// and transition-state flag. This member is specified as follows. /// An application can use the following values to test the keystroke flags. /// </summary> public UInt32 Flags; /// <summary> /// Specifies the time stamp for this message. /// </summary> public UInt32 Time; /// <summary> /// Specifies extra information associated with the message. /// </summary> public UInt32 ExtraInfo; } /// <summary> /// EventArgs class for use as parameters by HookEventHandler delegates /// </summary> public class HookEventArgs : EventArgs { private int _code; private IntPtr _wParam; private IntPtr _lParam; /// <summary> /// Initializes a new instance of the HookEventArgs class /// </summary> /// <param name="code">the hook code</param> /// <param name="wParam">hook specific information</param> /// <param name="lParam">hook specific information</param> public HookEventArgs(int code, IntPtr wParam, IntPtr lParam) { _code = code; _wParam = wParam; _lParam = lParam; } /// <summary> /// The hook code /// </summary> public int Code { get { return _code; } } /// <summary> /// A pointer to data /// </summary> public IntPtr wParam { get { return _wParam; } } /// <summary> /// A pointer to data /// </summary> public IntPtr lParam { get { return _lParam; } } } /// <summary> /// Event delegate for use with the HookEventArgs class /// </summary> public delegate void HookEventHandler(object sender, HookEventArgs e); /// <summary> /// Defines the various types of hooks that are available in Windows /// </summary> public enum HookTypes : int { WH_JOURNALRECORD = 0, WH_JOURNALPLAYBACK = 1, WH_KEYBOARD = 2, WH_GETMESSAGE = 3, WH_CALLWNDPROC = 4, WH_CBT = 5, WH_SYSMSGFILTER = 6, WH_MOUSE = 7, WH_HARDWARE = 8, WH_DEBUG = 9, WH_SHELL = 10, WH_FOREGROUNDIDLE = 11, WH_CALLWNDPROCRET = 12, WH_KEYBOARD_LL = 13, WH_MOUSE_LL = 14 } public enum ShellHookMessages { HSHELL_WINDOWCREATED = 1, HSHELL_WINDOWDESTROYED = 2, HSHELL_ACTIVATESHELLWINDOW = 3, HSHELL_WINDOWACTIVATED = 4, HSHELL_GETMINRECT = 5, HSHELL_REDRAW = 6, HSHELL_TASKMAN = 7, HSHELL_LANGUAGE = 8, HSHELL_ACCESSIBILITYSTATE = 11 } public enum WM_MOUSE : int { /// <summary> /// Êó±ê¿ªÊ¼ /// </summary> WM_MOUSEFIRST = 0x200, /// <summary> /// Êó±êÒƶ¯ /// </summary> WM_MOUSEMOVE = 0x200, /// <summary> /// ×ó¼ü°´Ï /// </summary> WM_LBUTTONDOWN = 0x201, /// <summary> /// ×ó¼üÊÍ·Å /// </summary> WM_LBUTTONUP = 0x202, /// <summary> /// ×ó¼üË«»÷ /// </summary> WM_LBUTTONDBLCLK = 0x203, /// <summary> /// ÓÒ¼ü°´Ï /// </summary> WM_RBUTTONDOWN = 0x204, /// <summary> /// ÓÒ¼üÊÍ·Å /// </summary> WM_RBUTTONUP = 0x205, /// <summary> /// ÓÒ¼üË«»÷ /// </summary> WM_RBUTTONDBLCLK = 0x206, /// <summary> /// Öмü°´Ï /// </summary> WM_MBUTTONDOWN = 0x207, /// <summary> /// ÖмüÊÍ·Å /// </summary> WM_MBUTTONUP = 0x208, /// <summary> /// ÖмüË«»÷ /// </summary> WM_MBUTTONDBLCLK = 0x209, /// <summary> /// ¹öÂÖ¹ö¶¯ /// </summary> /// <remarks>WINNT4.0ÒÔÉϲÅÖ§³Ö´ËÏûÏ¢</remarks> WM_MOUSEWHEEL = 0x020A } //message for list box public enum LISTBOXMSG : int { LB_ADDSTRING = 0x0180, LB_INSERTSTRING = 0x0181, LB_DELETESTRING = 0x0182, LB_SELITEMRANGEEX = 0x0183, LB_RESETCONTENT = 0x0184, LB_SETSEL = 0x0185, LB_SETCURSEL = 0x0186, LB_GETSEL = 0x0187, LB_GETCURSEL = 0x0188, LB_GETTEXT = 0x0189, LB_GETTEXTLEN = 0x018A, LB_GETCOUNT = 0x018B, LB_SELECTSTRING = 0x018C, LB_DIR = 0x018D, LB_GETTOPINDEX = 0x018E, LB_FINDSTRING = 0x018F, LB_GETSELCOUNT = 0x0190, LB_GETSELITEMS = 0x0191, LB_SETTABSTOPS = 0x0192, LB_GETHORIZONTALEXTENT = 0x0193, LB_SETHORIZONTALEXTENT = 0x0194, LB_SETCOLUMNWIDTH = 0x0195, LB_ADDFILE = 0x0196, LB_SETTOPINDEX = 0x0197, LB_GETITEMRECT = 0x0198, LB_GETITEMDATA = 0x0199, LB_SETITEMDATA = 0x019A, LB_SELITEMRANGE = 0x019B, LB_SETANCHORINDEX = 0x019C, LB_GETANCHORINDEX = 0x019D, LB_SETCARETINDEX = 0x019E, LB_GETCARETINDEX = 0x019F, LB_SETITEMHEIGHT = 0x01A0, LB_GETITEMHEIGHT = 0x01A1, LB_FINDSTRINGEXACT = 0x01A2, LB_SETLOCALE = 0x01A5, LB_GETLOCALE = 0x01A6, LB_SETCOUNT = 0x01A7, } //message for combo box. public enum COMBOBOXMSG : int { CB_OKAY = 0, CB_ERR = (-1), CB_ERRSPACE = (-2), CBN_ERRSPACE = (-1), CBN_SELCHANGE = 1, CBN_DBLCLK = 2, CBN_SETFOCUS = 3, CBN_KILLFOCUS = 4, CBN_EDITCHANGE = 5, CBN_EDITUPDATE = 6, CBN_DROPDOWN = 7, CBN_CLOSEUP = 8, CBN_SELENDOK = 9, CBN_SELENDCANCEL = 10, CBS_SIMPLE = 0x0001, CBS_DROPDOWN = 0x0002, CBS_DROPDOWNLIST = 0x0003, CBS_OWNERDRAWFIXED = 0x0010, CBS_OWNERDRAWVARIABLE = 0x0020, CBS_AUTOHSCROLL = 0x0040, CBS_OEMCONVERT = 0x0080, CBS_SORT = 0x0100, CBS_HASSTRINGS = 0x0200, CBS_NOINTEGRALHEIGHT = 0x0400, CBS_DISABLENOSCROLL = 0x0800, CBS_UPPERCASE = 0x2000, CBS_LOWERCASE = 0x4000, CB_GETEDITSEL = 0x0140, CB_LIMITTEXT = 0x0141, CB_SETEDITSEL = 0x0142, CB_ADDSTRING = 0x0143, CB_DELETESTRING = 0x0144, CB_DIR = 0x0145, CB_GETCOUNT = 0x0146, CB_GETCURSEL = 0x0147, CB_GETLBTEXT = 0x0148, CB_GETLBTEXTLEN = 0x0149, CB_INSERTSTRING = 0x014A, CB_RESETCONTENT = 0x014B, CB_FINDSTRING = 0x014C, CB_SELECTSTRING = 0x014D, CB_SETCURSEL = 0x014E, CB_SHOWDROPDOWN = 0x014F, CB_GETITEMDATA = 0x0150, CB_SETITEMDATA = 0x0151, CB_GETDROPPEDCONTROLRECT = 0x0152, CB_SETITEMHEIGHT = 0x0153, CB_GETITEMHEIGHT = 0x0154, CB_SETEXTENDEDUI = 0x0155, CB_GETEXTENDEDUI = 0x0156, CB_GETDROPPEDSTATE = 0x0157, CB_FINDSTRINGEXACT = 0x0158, CB_SETLOCALE = 0x0159, CB_GETLOCALE = 0x015A, CB_GETTOPINDEX = 0x015b, CB_SETTOPINDEX = 0x015c, CB_GETHORIZONTALEXTENT = 0x015d, CB_SETHORIZONTALEXTENT = 0x015e, CB_GETDROPPEDWIDTH = 0x015f, CB_SETDROPPEDWIDTH = 0x0160, CB_INITSTORAGE = 0x0161, CB_MSGMAX = 0x0162, } //virtual keys public enum VKCodes : int { VK_BACK = 0x08, VK_TAB = 0x09, VK_CLEAR = 0x0C, VK_RETURN = 0x0D, VK_SHIFT = 0x10, VK_CONTROL = 0x11, VK_MENU = 0x12, VK_PAUSE = 0x13, VK_CAPITAL = 0x14, VK_KANA = 0x15, VK_HANGEUL = 0x15, VK_HANGUL = 0x15, VK_JUNJA = 0x17, VK_FINAL = 0x18, VK_HANJA = 0x19, VK_KANJI = 0x19, VK_ESCAPE = 0x1B, VK_CONVERT = 0x1C, VK_NONCONVERT = 0x1D, VK_ACCEPT = 0x1E, VK_MODECHANGE = 0x1F, VK_SPACE = 0x20, VK_PRIOR = 0x21, VK_NEXT = 0x22, VK_END = 0x23, VK_HOME = 0x24, VK_LEFT = 0x25, VK_UP = 0x26, VK_RIGHT = 0x27, VK_DOWN = 0x28, VK_SELECT = 0x29, VK_PRINT = 0x2A, VK_EXECUTE = 0x2B, VK_SNAPSHOT = 0x2C, VK_INSERT = 0x2D, VK_DELETE = 0x2E, VK_HELP = 0x2F, VK_LWIN = 0x5B, VK_RWIN = 0x5C, VK_APPS = 0x5D, VK_SLEEP = 0x5F, VK_NUMLOCK = 90, VK_NUMPAD0 = 0x60, VK_NUMPAD1 = 0x61, VK_NUMPAD2 = 0x62, VK_NUMPAD3 = 0x63, VK_NUMPAD4 = 0x64, VK_NUMPAD5 = 0x65, VK_NUMPAD6 = 0x66, VK_NUMPAD7 = 0x67, VK_NUMPAD8 = 0x68, VK_NUMPAD9 = 0x69, VK_MULTIPLY = 0x6A, VK_ADD = 0x6B, VK_SEPARATOR = 0x6C, VK_SUBTRACT = 0x6D, VK_DECIMAL = 0x6E, VK_DIVIDE = 0x6F, VK_F1 = 0x70, VK_F2 = 0x71, VK_F3 = 0x72, VK_F4 = 0x73, VK_F5 = 0x74, VK_F6 = 0x75, VK_F7 = 0x76, VK_F8 = 0x77, VK_F9 = 0x78, VK_F10 = 0x79, VK_F11 = 0x7A, VK_F12 = 0x7B, VK_F13 = 0x7C, VK_F14 = 0x7D, VK_F15 = 0x7E, VK_F16 = 0x7F, VK_F17 = 0x80, VK_F18 = 0x81, VK_F19 = 0x82, VK_F20 = 0x83, VK_F21 = 0x84, VK_F22 = 0x85, VK_F23 = 0x86, VK_F24 = 0x87 } public enum WM_KEYBOARD : int { /// <summary> /// ·Çϵͳ°´¼ü°´Ï /// </summary> WM_KEYDOWN = 0x100, /// <summary> /// ·Çϵͳ°´¼üÊÍ·Å /// </summary> WM_KEYUP = 0x101, /// <summary> /// ϵͳ°´¼ü°´Ï /// </summary> WM_SYSKEYDOWN = 0x104, /// <summary> /// ϵͳ°´¼üÊÍ·Å /// </summary> WM_SYSKEYUP = 0x105 } public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true, EntryPoint = "SetWindowsHookEx")] public static extern IntPtr SetWindowsHookEx(HookTypes hookType, HookProc hookProc, IntPtr hInstance, int nThreadId); [DllImport("user32.dll")] public static extern int UnhookWindowsHookEx(IntPtr hookHandle); [DllImport("user32.dll")] public static extern int CallNextHookEx(IntPtr hookHandle, int nCode, Int32 wParam, IntPtr lParam); [DllImport("user32.dll")] public static extern int RegisterShellHookWindow(IntPtr hWnd); [DllImport("user32.dll")] public static extern int DeregisterShellHookWindow(IntPtr hWnd); [DllImport("user32.dll")] public static extern int ToAscii(UInt32 uVirtKey, UInt32 uScanCode, byte[] lpbKeyState, byte[] lpwTransKey, UInt32 fuState); [DllImport("user32.dll")] public static extern int GetKeyboardState(byte[] pbKeyState); #endregion Hooks #region System - Kernel32.dll [DllImport("kernel32.dll", EntryPoint = "GetLastError", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] public static extern Int32 GetLastError(); #endregion #region Windows - user32.dll public const int GWL_HWNDPARENT = (-8); public const int GWL_EXSTYLE = (-20); public const int GWL_STYLE = (-16); public const int GCL_HICON = (-14); public const int GCL_HICONSM = (-34); public const int WM_QUERYDRAGICON = 0x37; public const int WM_GETICON = 0x7F; public const int WM_SETICON = 0x80; public const int ICON_SMALL = 0; public const int ICON_BIG = 1; public const int SMTO_ABORTIFHUNG = 0x2; public const int TRUE = 1; public const int FALSE = 0; public const int WHITE_BRUSH = 0; public const int LTGRAY_BRUSH = 1; public const int GRAY_BRUSH = 2; public const int DKGRAY_BRUSH = 3; public const int BLACK_BRUSH = 4; public const int NULL_BRUSH = 5; public const int HOLLOW_BRUSH = NULL_BRUSH; public const int WHITE_PEN = 6; public const int BLACK_PEN = 7; public const int NULL_PEN = 8; public const int OEM_FIXED_FONT = 10; public const int ANSI_FIXED_FONT = 11; public const int ANSI_VAR_FONT = 12; public const int SYSTEM_FONT = 13; public const int DEVICE_DEFAULT_FONT = 14; public const int DEFAULT_PALETTE = 15; public const int SYSTEM_FIXED_FONT = 16; public const int RDW_INVALIDATE = 0x0001; public const int RDW_INTERNALPAINT = 0x0002; public const int RDW_ERASE = 0x0004; public const int RDW_VALIDATE = 0x0008; public const int RDW_NOINTERNALPAINT = 0x0010; public const int RDW_NOERASE = 0x0020; public const int RDW_NOCHILDREN = 0x0040; public const int RDW_ALLCHILDREN = 0x0080; public const int RDW_UPDATENOW = 0x0100; public const int RDW_ERASENOW = 0x0200; public const int RDW_FRAME = 0x0400; public const int RDW_NOFRAME = 0x0800; //enum to how to navigate in InternetExplorer. public enum BrowserNavConstants { /// <summary> /// Open the resource or file in a new window. /// </summary> navOpenInNewWindow = 0x1, /// <summary> /// Do not add the resource or file to the history list. The new page replaces the current page in the list. /// </summary> navNoHistory = 0x2, /// <summary> /// Do not consult the Internet cache; retrieve the resource from the origin server (implies BINDF_PRAGMA_NO_CACHE and BINDF_RESYNCHRONIZE). /// </summary> navNoReadFromCache = 0x4, /// <summary> /// Do not add the downloaded resource to the Internet cache. See BINDF_NOWRITECACHE. /// </summary> navNoWriteToCache = 0x8, /// <summary> /// 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. /// </summary> navAllowAutosearch = 0x10, /// <summary> /// Causes the current Explorer Bar to navigate to the given item, if possible. /// </summary> navBrowserBar = 0x20, /// <summary> /// 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. /// </summary> navHyperlink = 0x40, /// <summary> /// Internet Explorer 6 for Windows XP SP2 and later. Force the URL into the restricted zone. /// </summary> navEnforceRestricted = 0x80, /// <summary> /// Internet Explorer 6 for Windows XP SP2 and later. Use the default Popup Manager to block pop-up windows. /// </summary> navNewWindowsManaged = 0x0100, /// <summary> /// Internet Explorer 6 for Windows XP SP2 and later. Block files that normally trigger a file download dialog box. /// </summary> navUntrustedForDownload = 0x0200, /// <summary> /// Internet Explorer 6 for Windows XP SP2 and later. Prompt for the installation of Microsoft ActiveX controls. /// </summary> navTrustedForActiveX = 0x0400, /// <summary> /// Windows Internet Explorer 7. Open the resource or file in a new tab. Allow the destination window to come to the foreground, if necessary. /// </summary> navOpenInNewTab = 0x0800, /// <summary> /// Internet Explorer 7. Open the resource or file in a new background tab; the currently active window and/or tab remains open on top. /// </summary> navOpenInBackgroundTab = 0x1000, /// <summary> /// 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. /// </summary> navKeepWordWheelText = 0x2000 } public enum ShowWindowCmds { SW_HIDE = 0, SW_SHOWNORMAL = 1, SW_NORMAL = 1, SW_SHOWMINIMIZED = 2, SW_SHOWMAXIMIZED = 3, SW_MAXIMIZE = 3, SW_SHOWNOACTIVATE = 4, SW_SHOW = 5, SW_MINIMIZE = 6, SW_SHOWMINNOACTIVE = 7, SW_SHOWNA = 8, SW_RESTORE = 9, SW_SHOWDEFAULT = 10, SW_FORCEMINIMIZE = 11, SW_MAX = 11 } [StructLayout(LayoutKind.Sequential)] public struct MOUSEINPUT { public int dx; public int dy; public uint mouseData; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; } [StructLayout(LayoutKind.Sequential)] public struct KEYBDINPUT { public ushort wVk; public ushort wScan; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; } [StructLayout(LayoutKind.Sequential)] public struct HARDWAREINPUT { public uint uMsg; public ushort wParamL; public ushort wParamH; } [StructLayout(LayoutKind.Explicit)] public struct INPUT { [FieldOffset(0)] public int type; [FieldOffset(4)] public MOUSEINPUT mi; [FieldOffset(4)] public KEYBDINPUT ki; [FieldOffset(4)] public HARDWAREINPUT hi; } public const int HIDE_WINDOW = 0; public const int SHOW_OPENWINDOW = 1; public const int SHOW_ICONWINDOW = 2; public const int SHOW_FULLSCREEN = 3; public const int SHOW_OPENNOACTIVATE = 4; public const int SW_PARENTCLOSING = 1; public const int SW_OTHERZOOM = 2; public const int SW_PARENTOPENING = 3; public const int SW_OTHERUNZOOM = 4; public const int SWP_NOSIZE = 0x0001; public const int SWP_NOMOVE = 0x0002; public const int SWP_NOZORDER = 0x0004; public const int SWP_NOREDRAW = 0x0008; public const int SWP_NOACTIVATE = 0x0010; public const int SWP_FRAMECHANGED = 0x0020; /* The frame changed: send WM_NCCALCSIZE */ public const int SWP_SHOWWINDOW = 0x0040; public const int SWP_HIDEWINDOW = 0x0080; public const int SWP_NOCOPYBITS = 0x0100; public const int SWP_NOOWNERZORDER = 0x0200; /* Don't do owner Z ordering */ public const int SWP_NOSENDCHANGING = 0x0400; /* Don't send WM_WINDOWPOSCHANGING */ public const int SWP_DRAWFRAME = SWP_FRAMECHANGED; public const int SWP_NOREPOSITION = SWP_NOOWNERZORDER; public const int SWP_DEFERERASE = 0x2000; public const int SWP_ASYNCWINDOWPOS = 0x4000; public const int HWND_TOP = 0; public const int HWND_BOTTOM = 1; public const int HWND_TOPMOST = -1; public const int HWND_NOTOPMOST = -2; public enum PeekMessageFlags { PM_NOREMOVE = 0, PM_REMOVE = 1, PM_NOYIELD = 2 } public enum MouseEventFlags { Move = 0x0001, LeftDown = 0x0002, LeftUp = 0x0004, RightDown = 0x0008, RightUp = 0x0010, MiddleDown = 0x0020, MiddleUp = 0x0040, Wheel = 0x0800, Absolute = 0x8000 } public enum ScrollBarMsg { SB_LINEUP = 0, SB_LINELEFT = 0, SB_LINEDOWN = 1, SB_LINERIGHT = 1, SB_PAGEUP = 2, SB_PAGELEFT = 2, SB_PAGEDOWN = 3, SB_PAGERIGHT = 3, SB_THUMBPOSITION = 4, SB_THUMBTRACK = 5, SB_TOP = 6, SB_LEFT = 6, SB_BOTTOM = 7, SB_RIGHT = 7, SB_ENDSCROLL = 8, WM_PAINT = 0x000F } public enum WindowMessages : int { WM_NULL = 0x0000, WM_CREATE = 0x0001, WM_DESTROY = 0x0002, WM_MOVE = 0x0003, WM_SIZE = 0x0005, WM_ACTIVATE = 0x0006, WM_SETFOCUS = 0x0007, WM_KILLFOCUS = 0x0008, WM_ENABLE = 0x000A, WM_SETREDRAW = 0x000B, WM_SETTEXT = 0x000C, WM_GETTEXT = 0x000D, WM_GETTEXTLENGTH = 0x000E, WM_PAINT = 0x000F, WM_CLOSE = 0x0010, WM_QUERYENDSESSION = 0x0011, WM_QUIT = 0x0012, WM_QUERYOPEN = 0x0013, WM_ERASEBKGND = 0x0014, WM_SYSCOLORCHANGE = 0x0015, WM_ENDSESSION = 0x0016, WM_SHOWWINDOW = 0x0018, WM_CTLCOLOR = 0x0019, WM_WININICHANGE = 0x001A, WM_SETTINGCHANGE = 0x001A, WM_DEVMODECHANGE = 0x001B, WM_ACTIVATEAPP = 0x001C, WM_FONTCHANGE = 0x001D, WM_TIMECHANGE = 0x001E, WM_CANCELMODE = 0x001F, WM_SETCURSOR = 0x0020, WM_MOUSEACTIVATE = 0x0021, WM_CHILDACTIVATE = 0x0022, WM_QUEUESYNC = 0x0023, WM_GETMINMAXINFO = 0x0024, WM_PAINTICON = 0x0026, WM_ICONERASEBKGND = 0x0027, WM_NEXTDLGCTL = 0x0028, WM_SPOOLERSTATUS = 0x002A, WM_DRAWITEM = 0x002B, WM_MEASUREITEM = 0x002C, WM_DELETEITEM = 0x002D, WM_VKEYTOITEM = 0x002E, WM_CHARTOITEM = 0x002F, WM_SETFONT = 0x0030, WM_GETFONT = 0x0031, WM_SETHOTKEY = 0x0032, WM_GETHOTKEY = 0x0033, WM_QUERYDRAGICON = 0x0037, WM_COMPAREITEM = 0x0039, WM_GETOBJECT = 0x003D, WM_COMPACTING = 0x0041, WM_COMMNOTIFY = 0x0044, WM_WINDOWPOSCHANGING = 0x0046, WM_WINDOWPOSCHANGED = 0x0047, WM_POWER = 0x0048, WM_COPYDATA = 0x004A, WM_CANCELJOURNAL = 0x004B, WM_NOTIFY = 0x004E, WM_INPUTLANGCHANGEREQUEST = 0x0050, WM_INPUTLANGCHANGE = 0x0051, WM_TCARD = 0x0052, WM_HELP = 0x0053, WM_USERCHANGED = 0x0054, WM_NOTIFYFORMAT = 0x0055, WM_CONTEXTMENU = 0x007B, WM_STYLECHANGING = 0x007C, WM_STYLECHANGED = 0x007D, WM_DISPLAYCHANGE = 0x007E, WM_GETICON = 0x007F, WM_SETICON = 0x0080, WM_NCCREATE = 0x0081, WM_NCDESTROY = 0x0082, WM_NCCALCSIZE = 0x0083, WM_NCHITTEST = 0x0084, WM_NCPAINT = 0x0085, WM_NCACTIVATE = 0x0086, WM_GETDLGCODE = 0x0087, WM_SYNCPAINT = 0x0088, WM_NCMOUSEMOVE = 0x00A0, WM_NCLBUTTONDOWN = 0x00A1, WM_NCLBUTTONUP = 0x00A2, WM_NCLBUTTONDBLCLK = 0x00A3, WM_NCRBUTTONDOWN = 0x00A4, WM_NCRBUTTONUP = 0x00A5, WM_NCRBUTTONDBLCLK = 0x00A6, WM_NCMBUTTONDOWN = 0x00A7, WM_NCMBUTTONUP = 0x00A8, WM_NCMBUTTONDBLCLK = 0x00A9, WM_KEYDOWN = 0x0100, WM_KEYUP = 0x0101, WM_CHAR = 0x0102, WM_DEADCHAR = 0x0103, WM_SYSKEYDOWN = 0x0104, WM_SYSKEYUP = 0x0105, WM_SYSCHAR = 0x0106, WM_SYSDEADCHAR = 0x0107, WM_KEYLAST = 0x0108, WM_IME_STARTCOMPOSITION = 0x010D, WM_IME_ENDCOMPOSITION = 0x010E, WM_IME_COMPOSITION = 0x010F, WM_IME_KEYLAST = 0x010F, WM_INITDIALOG = 0x0110, WM_COMMAND = 0x0111, WM_SYSCOMMAND = 0x0112, WM_TIMER = 0x0113, WM_HSCROLL = 0x0114, WM_VSCROLL = 0x0115, WM_INITMENU = 0x0116, WM_INITMENUPOPUP = 0x0117, WM_MENUSELECT = 0x011F, WM_MENUCHAR = 0x0120, WM_ENTERIDLE = 0x0121, WM_MENURBUTTONUP = 0x0122, WM_MENUDRAG = 0x0123, WM_MENUGETOBJECT = 0x0124, WM_UNINITMENUPOPUP = 0x0125, WM_MENUCOMMAND = 0x0126, WM_CTLCOLORMSGBOX = 0x0132, WM_CTLCOLOREDIT = 0x0133, WM_CTLCOLORLISTBOX = 0x0134, WM_CTLCOLORBTN = 0x0135, WM_CTLCOLORDLG = 0x0136, WM_CTLCOLORSCROLLBAR = 0x0137, WM_CTLCOLORSTATIC = 0x0138, WM_MOUSEMOVE = 0x0200, WM_LBUTTONDOWN = 0x0201, WM_LBUTTONUP = 0x0202, WM_LBUTTONDBLCLK = 0x0203, WM_RBUTTONDOWN = 0x0204, WM_RBUTTONUP = 0x0205, WM_RBUTTONDBLCLK = 0x0206, WM_MBUTTONDOWN = 0x0207, WM_MBUTTONUP = 0x0208, WM_MBUTTONDBLCLK = 0x0209, WM_MOUSEWHEEL = 0x020A, WM_PARENTNOTIFY = 0x0210, WM_ENTERMENULOOP = 0x0211, WM_EXITMENULOOP = 0x0212, WM_NEXTMENU = 0x0213, WM_SIZING = 0x0214, WM_CAPTURECHANGED = 0x0215, WM_MOVING = 0x0216, WM_DEVICECHANGE = 0x0219, WM_MDICREATE = 0x0220, WM_MDIDESTROY = 0x0221, WM_MDIACTIVATE = 0x0222, WM_MDIRESTORE = 0x0223, WM_MDINEXT = 0x0224, WM_MDIMAXIMIZE = 0x0225, WM_MDITILE = 0x0226, WM_MDICASCADE = 0x0227, WM_MDIICONARRANGE = 0x0228, WM_MDIGETACTIVE = 0x0229, WM_MDISETMENU = 0x0230, WM_ENTERSIZEMOVE = 0x0231, WM_EXITSIZEMOVE = 0x0232, WM_DROPFILES = 0x0233, WM_MDIREFRESHMENU = 0x0234, WM_IME_SETCONTEXT = 0x0281, WM_IME_NOTIFY = 0x0282, WM_IME_CONTROL = 0x0283, WM_IME_COMPOSITIONFULL = 0x0284, WM_IME_SELECT = 0x0285, WM_IME_CHAR = 0x0286, WM_IME_REQUEST = 0x0288, WM_IME_KEYDOWN = 0x0290, WM_IME_KEYUP = 0x0291, WM_MOUSEHOVER = 0x02A1, WM_MOUSELEAVE = 0x02A3, WM_CUT = 0x0300, WM_COPY = 0x0301, WM_PASTE = 0x0302, WM_CLEAR = 0x0303, WM_UNDO = 0x0304, WM_RENDERFORMAT = 0x0305, WM_RENDERALLFORMATS = 0x0306, WM_DESTROYCLIPBOARD = 0x0307, WM_DRAWCLIPBOARD = 0x0308, WM_PAINTCLIPBOARD = 0x0309, WM_VSCROLLCLIPBOARD = 0x030A, WM_SIZECLIPBOARD = 0x030B, WM_ASKCBFORMATNAME = 0x030C, WM_CHANGECBCHAIN = 0x030D, WM_HSCROLLCLIPBOARD = 0x030E, WM_QUERYNEWPALETTE = 0x030F, WM_PALETTEISCHANGING = 0x0310, WM_PALETTECHANGED = 0x0311, WM_HOTKEY = 0x0312, WM_PRINT = 0x0317, WM_PRINTCLIENT = 0x0318, WM_HANDHELDFIRST = 0x0358, WM_HANDHELDLAST = 0x035F, WM_AFXFIRST = 0x0360, WM_AFXLAST = 0x037F, WM_PENWINFIRST = 0x0380, WM_PENWINLAST = 0x038F, WM_APP = 0x8000, WM_USER = 0x0400, WM_REFLECT = WM_USER + 0x1c00 } //define the window menu message. public enum WindowMenuMessage : int { SC_SIZE = 0xF000, SC_MOVE = 0xF010, SC_MINIMIZE = 0xF020, SC_MAXIMIZE = 0xF030, SC_NEXTWINDOW = 0xF040, SC_PREVWINDOW = 0xF050, SC_CLOSE = 0xF060, SC_VSCROLL = 0xF070, SC_HSCROLL = 0xF080, SC_MOUSEMENU = 0xF090, SC_KEYMENU = 0xF100, SC_ARRANGE = 0xF110, SC_RESTORE = 0xF120, SC_TASKLIST = 0xF130, SC_SCREENSAVE = 0xF140, SC_HOTKEY = 0xF150, SC_DEFAULT = 0xF160, SC_MONITORPOWER = 0xF170, SC_CONTEXTHELP = 0xF180, SC_SEPARATOR = 0xF00F } /// <summary> /// Defines the style bits that a window can have /// </summary> public enum WindowStyles : uint { WS_BORDER = 0x800000, WS_CAPTION = 0xC00000,// ' WS_BORDER Or WS_DLGFRAME WS_CHILD = 0x40000000, WS_CHILDWINDOW = (WS_CHILD), WS_CLIPCHILDREN = 0x2000000, WS_CLIPSIBLINGS = 0x4000000, WS_DISABLED = 0x8000000, WS_DLGFRAME = 0x400000, WS_EX_ACCEPTFILES = 0x10, WS_EX_DLGMODALFRAME = 0x1, WS_EX_NOPARENTNOTIFY = 0x4, WS_EX_TOPMOST = 0x8, WS_EX_TRANSPARENT = 0x20, WS_EX_TOOLWINDOW = 0x80, WS_EX_APPWINDOW = 0x40000, WS_GROUP = 0x20000, WS_HSCROLL = 0x100000, WS_MAXIMIZE = 0x1000000, WS_MAXIMIZEBOX = 0x10000, WS_MINIMIZE = 0x20000000, WS_MINIMIZEBOX = 0x20000, WS_OVERLAPPED = 0x0, WS_POPUP = 0x80000000, WS_SYSMENU = 0x80000, WS_TABSTOP = 0x10000, WS_THICKFRAME = 0x40000, WS_VISIBLE = 0x10000000, WS_VSCROLL = 0x200000, WS_ICONIC = WS_MINIMIZE, WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU), WS_SIZEBOX = WS_THICKFRAME, WS_TILED = WS_OVERLAPPED, WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX) } public struct WindowInfo { public int size; public Rectangle window; public Rectangle client; public int style; public int exStyle; public int windowStatus; public uint xWindowBorders; public uint yWindowBorders; public short atomWindowtype; public short creatorVersion; } public struct WindowPlacement { public int length; public int flags; public int showCmd; public Point minPosition; public Point maxPosition; public Rectangle normalPosition; } public struct Rect { public int left; public int top; public int right; public int bottom; public int Width { get { return right - left; } } public int Height { get { return bottom - top; } } } //constant for IACC. public enum IACC : int { //constant for MSAA interface. OBJID_WINDOW = 0, OBJID_CLIENT = -4, } public delegate bool EnumWindowEventHandler(IntPtr hWnd, Int32 lParam); [DllImport("user32.dll", EntryPoint = "GetCursorPos")] public static extern int GetCursorPos(ref POINT lpPoint); //public static unsafe extern int GetCursorPos(POINT* lpPoint); [DllImport("User32.dll")] public extern static void mouse_event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo); [DllImport("user32.dll", EntryPoint = "SetCursorPos")] public static extern bool SetCursorPos(int x, int y); [DllImport("user32.dll", EntryPoint = "WindowFromPoint")] public static extern IntPtr WindowFromPoint(int xPoint, int yPoint); [DllImport("user32.dll", EntryPoint = "FindWindow")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", EntryPoint = "FindWindowEx")] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); //GUID of IAccessible interface public static Guid IACCUID = new Guid("618736e0-3c3d-11cf-810c-00aa00389b71"); [DllImport("oleacc.dll")] public static extern uint GetStateText(uint dwStateBit, [Out] StringBuilder lpszStateBit, uint cchStateBitMax); [DllImport("oleacc.dll")] public static extern uint GetRoleText(uint dwRole, [Out] StringBuilder lpszRole, uint cchRoleMax); [DllImport("oleacc.dll")] public static extern IntPtr AccessibleObjectFromPoint(POINT pt, [Out, MarshalAs(UnmanagedType.Interface)] out IAccessible accObj, [Out] out object ChildID); [DllImport("oleacc.dll", ExactSpelling = true, PreserveSig = false)] [return: MarshalAs(UnmanagedType.Interface)] public static extern object AccessibleObjectFromWindow(IntPtr hwnd, int dwObjectID, ref Guid riid, ref IAccessible ppvObject); [DllImport("Oleacc.dll")] public static extern int AccessibleChildren(IAccessible paccContainer, int iChildStart, int cChildren, [Out] object[] rgvarChildren, out int pcObtained); [DllImport("oleacc.dll", PreserveSig = false)] [return: MarshalAs(UnmanagedType.Interface)] public static extern object ObjectFromLresult(UIntPtr lResult, [MarshalAs(UnmanagedType.LPStruct)] Guid refiid, IntPtr wParam); [DllImport("oleacc.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] public static extern Int32 ObjectFromLresult(Int32 lResult, ref Guid riid, Int32 wParam, out IHTMLDocument2 ppvObject); [DllImport("user32.dll")] public static extern int GetWindowModuleFileName(IntPtr hWnd, StringBuilder lpString, int nMaxCount); [DllImport("user32.dll")] public static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); [DllImport("user32.dll")] public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); [DllImport("user32.dll")] public static extern bool GetWindowPlacement(IntPtr window, ref WindowPlacement position); [DllImport("User32.dll")] public static extern int RegisterWindowMessage(string message); [DllImport("User32.dll")] public static extern void EnumWindows(EnumWindowEventHandler callback, Int32 lParam); //[DllImport("User32.dll")] //public static extern Int32 GetWindowText(IntPtr hWnd, StringBuilder lpString, Int32 nMaxCount); [DllImport("User32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd); [DllImport("User32.dll")] public static extern Int32 GetWindow(IntPtr hWnd, Int32 wCmd); [DllImport("User32.dll")] public static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags); //[DllImport("User32.dll")] //public static extern WindowStyles GetWindowLong(IntPtr hWnd, Int32 index); [DllImport("User32.dll")] public static extern IntPtr GetParent(IntPtr hWnd); [DllImport("User32.dll")] public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); [DllImport("User32.dll")] public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); [DllImport("User32.dll")] public static extern WindowStyles GetWindowLong(IntPtr hWnd, int index); [DllImport("User32.dll")] public static extern int SendMessageTimeout(IntPtr hWnd, int uMsg, int wParam, int lParam, int fuFlags, int uTimeout, out UIntPtr lpdwResult); [DllImport("User32.dll")] public static extern int GetClassLong(IntPtr hWnd, int index); [DllImport("User32.dll")] public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId); [DllImport("User32.dll")] public unsafe static extern UInt32 SendInput(UInt32 nInputs, INPUT* pInputs, int cbSize); [DllImport("User32.dll")] public static extern UInt32 SendInput(UInt32 nInputs, INPUT[] pInputs, int cbSize); [DllImport("User32.dll")] public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, int lParam); [DllImport("User32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam); [DllImport("User32.dll")] public static extern int PostMessage(IntPtr hWnd, int uMsg, int wParam, int lParam); [DllImport("User32.dll")] public static extern void SwitchToThisWindow(IntPtr hWnd, int altTabActivated); [DllImport("User32.dll")] public static extern int ShowWindowAsync(IntPtr hWnd, int command); [DllImport("User32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll")] public static extern IntPtr GetDesktopWindow(); [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool BringWindowToTop(IntPtr window); [DllImport("user32.dll")] public static extern bool GetWindowInfo(IntPtr hwnd, ref WindowInfo info); [DllImport("user32.dll")] public static extern IntPtr GetWindowDC(IntPtr hwnd); [DllImport("user32.dll")] public static extern IntPtr GetDC(IntPtr hwnd); [DllImport("user32.dll")] public static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc); [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle); [DllImport("user32.dll")] public static extern bool GetClientRect(IntPtr hwnd, ref Rect rectangle); [DllImport("user32.dll")] public static extern IntPtr GetMessageExtraInfo(); //[DllImport("user32.dll")] //public static extern IntPtr WindowFromPoint(Point pt); [DllImport("user32.dll")] public static extern IntPtr SetCapture(IntPtr hWnd); [DllImport("user32.dll")] public static extern int ReleaseCapture(); //[DllImport("user32.dll")] //public static extern IntPtr SelectObject(IntPtr hDc, IntPtr hObject); [DllImport("user32.dll")] public static extern IntPtr GetStockObject(int nObject); [DllImport("user32.dll")] public static extern int InvalidateRect(IntPtr hWnd, IntPtr lpRect, int bErase); [DllImport("user32.dll")] public static extern int UpdateWindow(IntPtr hWnd); [DllImport("user32.dll")] public static extern int RedrawWindow(IntPtr hWnd, IntPtr lprcUpdate, IntPtr hrgnUpdate, uint flags); [DllImport("user32.dll")] public static extern IntPtr GetActiveWindow(); [DllImport("user32.dll")] public static extern IntPtr SetActiveWindow(IntPtr hWnd); #endregion Windows #region GDI - gdi32.dll public enum BinaryRasterOperations { R2_BLACK = 1, /* 0 */ R2_NOTMERGEPEN = 2, /* DPon */ R2_MASKNOTPEN = 3, /* DPna */ R2_NOTCOPYPEN = 4, /* PN */ R2_MASKPENNOT = 5, /* PDna */ R2_NOT = 6, /* Dn */ R2_XORPEN = 7, /* DPx */ R2_NOTMASKPEN = 8, /* DPan */ R2_MASKPEN = 9, /* DPa */ R2_NOTXORPEN = 10, /* DPxn */ R2_NOP = 11, /* D */ R2_MERGENOTPEN = 12, /* DPno */ R2_COPYPEN = 13, /* P */ R2_MERGEPENNOT = 14, /* PDno */ R2_MERGEPEN = 15, /* DPo */ R2_WHITE = 16, /* 1 */ R2_LAST = 16 } public enum TernaryRasterOperations { SRCCOPY = 0x00CC0020, /* dest = source */ SRCPAINT = 0x00EE0086, /* dest = source OR dest */ SRCAND = 0x008800C6, /* dest = source AND dest */ SRCINVERT = 0x00660046, /* dest = source XOR dest */ SRCERASE = 0x00440328, /* dest = source AND (NOT dest ) */ NOTSRCCOPY = 0x00330008, /* dest = (NOT source) */ NOTSRCERASE = 0x001100A6, /* dest = (NOT src) AND (NOT dest) */ MERGECOPY = 0x00C000CA, /* dest = (source AND pattern) */ MERGEPAINT = 0x00BB0226, /* dest = (NOT source) OR dest */ PATCOPY = 0x00F00021, /* dest = pattern */ PATPAINT = 0x00FB0A09, /* dest = DPSnoo */ PATINVERT = 0x005A0049, /* dest = pattern XOR dest */ DSTINVERT = 0x00550009, /* dest = (NOT dest) */ BLACKNESS = 0x00000042, /* dest = BLACK */ WHITENESS = 0x00FF0062 /* dest = WHITE */ } public const int SRCCOPY = 0x00CC0020; [DllImport("gdi32.dll")] public static extern bool BitBlt(IntPtr hdcDst, int xDst, int yDst, int cx, int cy, IntPtr hdcSrc, int xSrc, int ySrc, uint ulRop); [DllImport("gdi32.dll")] 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); [DllImport("gdi32.dll")] public static extern IntPtr CreateDC(IntPtr lpszDriver, string lpszDevice, IntPtr lpszOutput, IntPtr lpInitData); [DllImport("gdi32.dll")] public static extern IntPtr DeleteDC(IntPtr hdc); [DllImport("gdi32.dll")] public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth, int nHeight); [DllImport("gdi32.dll")] public static extern IntPtr CreateCompatibleDC(IntPtr hDC); [DllImport("gdi32.dll")] public static extern bool DeleteObject(IntPtr hObject); [DllImport("gdi32.dll")] public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject); #endregion #region Shlwapi.dll [DllImport("Shlwapi.dll")] public static extern string PathGetArgs(string path); public static string SafePathGetArgs(string path) { try { return WinApi.PathGetArgs(path); } catch (System.Exception) { } return string.Empty; } [DllImport("Shlwapi.dll")] public static extern int PathCompactPathEx( System.Text.StringBuilder pszOut, /* Address of the string that has been altered */ System.Text.StringBuilder pszSrc, /* Pointer to a null-terminated string of max length (MAX_PATH) that contains the path to be altered */ 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. */ uint dwFlags); /* Reserved */ public static string PathCompactPathEx(string source, uint maxChars) { StringBuilder pszOut = new StringBuilder((int)WinApi.MAX_PATH); StringBuilder pszSrc = new StringBuilder(source); int result = WinApi.PathCompactPathEx(pszOut, pszSrc, maxChars, (uint)0); if (result == 1) return pszOut.ToString(); else { System.Diagnostics.Debug.WriteLine("Win32.PathCompactPathEx failed to compact the path '" + source + "' down to '" + maxChars + "' characters."); return string.Empty; } } #endregion #region Hotkeys [Flags()] public enum HotkeyModifiers { MOD_ALT = 0x0001, MOD_CONTROL = 0x0002, MOD_SHIFT = 0x0004, MOD_WIN = 0x0008 } [DllImport("User32")] public static extern int RegisterHotKey(IntPtr hWnd, int id, uint modifiers, uint virtualkeyCode); [DllImport("User32")] public static extern int UnregisterHotKey(IntPtr hWnd, int id); [DllImport("Kernel32")] public static extern short GlobalAddAtom(string atomName); [DllImport("Kernel32")] public static extern short GlobalDeleteAtom(short atom); #endregion [DllImport("User32")] public static extern int LockWindowUpdate(IntPtr windowHandle); public static short MAKEWORD(byte a, byte b) { return ((short)(((byte)(a & 0xff)) | ((short)((byte)(b & 0xff))) << 8)); } public static byte LOBYTE(short a) { return ((byte)(a & 0xff)); } public static byte HIBYTE(short a) { return ((byte)(a >> 8)); } public static int MAKELONG(short a, short b) { return (((int)(a & 0xffff)) | (((int)(b & 0xffff)) << 16)); } public static short HIWORD(int a) { return ((short)(a >> 16)); } public static short LOWORD(int a) { return ((short)(a & 0xffff)); } [DllImport("Kernel32")] public static extern int CopyFile(string source, string destination, int failIfExists); }};
- 给网页赋值参考信息
- 怎么给网页中的元素赋值JSON
- Jquery如何给网页的title取值和赋值
- 如何从键盘输入学生信息,并赋值给数组
- jquery获取 屏幕宽度以及网页可用宽度 以及 给图片src赋值 div赋值
- 在网页中通过param name方式给ActiveX控件的属性赋值
- java 获取e.printStackTrace() 的具体信息,赋值给String 变量 并返回
- 给const对象赋值
- 给控件赋值
- 如何给fckeditor赋值?
- 给Radiobuttonlist赋值
- js如何给赋值
- Extjs给TextField赋值
- 如何给PAnsiString赋值
- 给DropDownList赋值
- 给DropDownList赋值
- 怎样给数组赋值
- 给字符串数组赋值:
- 获取客户端IP,操作系统,浏览器等
- 关于给浏览器文本框赋值的思路
- C# Panel 中加入 hScrollBar
- document.getElementById("radFs")对象为空,js判断对象是否存在?
- socket知识介绍
- 给网页赋值参考信息
- 男人拥有女人之后的几大心态
- SQL重复记录处理
- 自己看
- 速度奇慢的android模拟器
- 小主机开机启动-SVM file is missing.
- 聚沙成塔 - AEE_GET_X宏和AEE_GET_Y宏
- Unicode
- ASCII