程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#網頁截圖類WebCapture(增強版)

C#網頁截圖類WebCapture(增強版)

編輯:C#入門知識

先定義三個重要的類NativeMethods、UnsafeNativeMethods和Snapshot:
NativeMethods.cs:
 程序代碼using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;

namespace WindowsApplication1
{
     /// <summary>
     /// 從 .Net 2.0 的 System.Windows.Forms.Dll 庫提取
     /// 版權所有:微軟公司
     /// </summary>
     internal static class NativeMethods
     {
         [StructLayout(LayoutKind.Sequential)]
         public sealed class tagDVTARGETDEVICE
         {
             [MarshalAs(UnmanagedType.U4)]
             public int tdSize;
             [MarshalAs(UnmanagedType.U2)]
             public short tdDriverNameOffset;
             [MarshalAs(UnmanagedType.U2)]
             public short tdDeviceNameOffset;
             [MarshalAs(UnmanagedType.U2)]
             public short tdPortNameOffset;
             [MarshalAs(UnmanagedType.U2)]
             public short tdExtDevmodeOffset;
         }

         [StructLayout(LayoutKind.Sequential)]
         public class COMRECT
         {
             public int left;
             public int top;
             public int right;
             public int bottom;
             public COMRECT()
             {
             }

             public COMRECT(Rectangle r)
             {
                 this.left = r.X;
                 this.top = r.Y;
                 this.right = r.Right;
                 this.bottom = r.Bottom;
             }

             public COMRECT(int left, int top, int right, int bottom)
             {
                 this.left = left;
                 this.top = top;
                 this.right = right;
                 this.bottom = bottom;
             }

             public static NativeMethods.COMRECT FromXYWH(int x, int y, int width, int height)
             {
                 return new NativeMethods.COMRECT(x, y, x + width, y + height);
             }

             public override string ToString()
             {
                 return string.Concat(new object[] { "Left = ", this.left, " Top ", this.top, " Right = ", this.right, " Bottom = ", this.bottom });
             }

         }

         [StructLayout(LayoutKind.Sequential)]
         public sealed class tagLOGPALETTE
         {
             [MarshalAs(UnmanagedType.U2)]
             public short palVersion;
             [MarshalAs(UnmanagedType.U2)]
             public short palNumEntries;
         }
     }
}
UnsafeNativeMethods.cs:
 程序代碼using System;
using System.Collections.Generic;
using System.Text;
using System.Security;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;

namespace WindowsApplication1
{
     /// <summary>
     /// 從 .Net 2.0 的 System.Windows.Forms.Dll 庫提取
     /// 版權所有:微軟公司
     /// </summary>
     [SuppressUnmanagedCodeSecurity]
     internal static class UnsafeNativeMethods
     {
         public static Guid IID_IViewObject = new Guid("{0000010d-0000-0000-C000-000000000046}");

         [ComImport, Guid("0000010d-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
         public interface IViewObject
         {
             [PreserveSig]
             int Draw([In, MarshalAs(UnmanagedType.U4)] int dwDrawAspect, int lindex, IntPtr pvAspect, [In] NativeMethods.tagDVTARGETDEVICE ptd, IntPtr hdcTargetDev, IntPtr hdcDraw, [In] NativeMethods.COMRECT lprcBounds, [In] NativeMeth

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved