zoukankan      html  css  js  c++  java
  • C# WebBrowser NativeMethods

    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace HttpBrowserApp
    {
        class NativeMethods
        {
            [ComImport]
            [Guid("0000010D-0000-0000-C000-000000000046")]
            [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            interface IViewObject
            {
                void Draw([MarshalAs(UnmanagedType.U4)] uint dwAspect, int lindex, IntPtr pvAspect, [In] IntPtr ptd, IntPtr hdcTargetDev, IntPtr hdcDraw, [MarshalAs(UnmanagedType.Struct)] ref RECT lprcBounds, [In] IntPtr lprcWBounds, IntPtr pfnContinue, [MarshalAs(UnmanagedType.U4)] uint dwContinue);
            }
    
            [StructLayout(LayoutKind.Sequential, Pack = 4)]
            struct RECT
            {
                public int Left;
                public int Top;
                public int Right;
                public int Bottom;
            }
    
            public static void GetImage(object obj, Image destination, Color backgroundColor)
            {
                using (Graphics graphics = Graphics.FromImage(destination))
                {
                    IntPtr deviceContextHandle = IntPtr.Zero;
                    RECT rectangle = new RECT();
    
                    rectangle.Right = destination.Width;
                    rectangle.Bottom = destination.Height;
    
                    graphics.Clear(backgroundColor);
    
                    try
                    {
                        deviceContextHandle = graphics.GetHdc();
    
                        IViewObject viewObject = obj as IViewObject;
                        viewObject.Draw(1, -1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, deviceContextHandle, ref rectangle, IntPtr.Zero, IntPtr.Zero, 0);
                    }
                    finally
                    {
                        if (deviceContextHandle != IntPtr.Zero)
                        {
                            graphics.ReleaseHdc(deviceContextHandle);
                        }
                    }
                }
            }
        }
    }
  • 相关阅读:
    xfce4-windowck-plugin的替代品
    git使用Beyond Compare作为diff和merge工具
    Visual Studio设置多个快捷键
    scrapy参数-COOKIES_ENABLED 最权威解释, 帮你避坑
    Linux基础使用
    python 所有的库整理
    Nginx配置详解
    15个常用的javaScript正则表达式
    Redis开发建议
    mysql 同步大量数据小技巧
  • 原文地址:https://www.cnblogs.com/Googler/p/3723564.html
Copyright © 2011-2022 走看看