# Rendere i Documenti HTML in immagini...il codice

<datetime class="hidden">2004-06-30T00:00</datetime>

<!-- category -- mostlylucidcouk, Imported -->
Beh, dopo un po' di suonare ioM SK1ho qualcosa che funziona adesso, IoMSC3non ho WinMST4 codificatore ma sembra funzionareMSSK5

usando System;

usando il sistema.Drawing;

usando il sistema.Drawing.ImagingM SK2

usando il sistema.Colleczioni;

usando System.ComponentModel;

usando il sistema.WindowsM SK1Forms;

usando il sistema.Data;

usando mshtml;

usando il sistema.Runtime.InteropServicesM SK2

usando Microsoft.Win32;

namespace ThumbMaker

{

/// &lt;riassunto&gt;

/// Descrizione sommistica del modulo1.

/// &lt;/summario&gt;

Formula di classe pubblica1 M SK1 sistema.WindowsMST3formiMSC4forma

{

AxSHDocVw.AxWebBrowser axWeb Browser1;

/// &lt;riassunto&gt;

/// La variabile da designer necessaria.

/// &lt;/summario&gt;

sistema privato.Modello di componentiM SK1Contenere di componenti = nullo ;

Private const string urlStr =

Formula pubblica1()

{

//

// Requisito per il support di Windows Form Designer

//

Inizializzare un componente();

Oggetto o = nullo ;

Questo .Visible= falso ;

axWebBrowser1.NavigateMSC1urlStr, ref oM SK3 refoMST4 refOMSV5 ref OMSS6

}

Const int WM\_PAINT

Const int WM\_PRINTCLIENT

Const int WM\_ERASEBKGND

Const int WM\_PRINT

Const int PRF\_CHILDREN

Const int PRF\_CLIENT

vuoto pubblico GrabWindow()

{

IntPtr hWnd = questo .HandleM SK2

IntPtr hBmp;

Bitmap MyBitmap= null ;

IntPtr hDCMem = GDI32.CreareDCcompatibileM SK2IntPtri) null MSC4

IntPtr hDC =User 32.GetWindowDC(hWndM SK3

hBmp = GDI32.Creare una mappa di bit compatibileMSC2hDCM SK3IntPtrMska4axWebBrowserM Ska5Vidth ,(IntintPtriMka7axwebBrowzerMske8HeightMsek9

Userone32.ReleaseDC(hWndM SK2 hDC );

IntPtr hOld = GDIM SK1SelectObject (hDCMem, hBmpMSC4

Usuario32.SendMessage(hWndM SK2 WM\_PRINT , hDCMem, nuovo IntPtrM SK3PRF\_CLIENT  | PRF\_CHILDRENM SK1

GDI32.SelectObject (hDCMemM SK2 hOld);

GDI32.DeleteObject(hDCMemM SK2

MyBitmap = BitmapM SK1FromHbitmap (hBmp);

MyBitmap.Save( "test.png" ,ImageFormat.Png);

Questo .Close();

}

/// &lt;riassunto&gt;

/// pulire tutte le risorse usate.

/// &lt;/summario&gt;

superare protetto vuoto Dispose( bool disposing )

{

Se ( si decompose )

{

se (componenti != nullo )

{

Componenti.Disponsione();

}

}

base .Disponere(disponere  );

}

#region Code generato da Windows Form Designer

/// &lt;riassunto&gt;

/// metodo richiesto per il supporto del designer - non modificare

/// il contenuto di questo metodo con l'editore di codici.

/// &lt;/summario&gt;

Private void InitializeComponent()

{

Il sistema.Ressources.ResourceManager resources M SK2 nuovo sistema .ResurseMska4ResourcingManagerMske5 tipo Mska6FormaM Ska7

Questo .axWebBrowserM SK1 = nuovo AxSHDocVw.AxWebBbrowserSSK4

((Sistema.Modello di ComponenteM SK2Istrutto di SupportInitializzarsiMSC3 questo .axWebBrowserMST5BeginInitMst6

Questo .SuspendLayout();

//

// axWebBrowser1

//

Questo .axWebBrowserM SK1Dock =Systeme.WindowsMST4FormiMSC5DockingStyleMS.FillM;

Questo .axWebBrowser1.Configurato = vero ;

Questo .axWebBrowser1.Location = nuovo sistemaMSC3DrawingM SK4PointMST5 SST6

Questo .axWebBrowser1.OcxState = MSC3SystemaM SK4WindowsMST5FormiMS.AxHostMSC7StateMSSK8resourcesMSV9GetObjectMSL10 | | "ax WebBrowsingMSP12OccxStatesMSS13 |

Questo .axWebBrowser1.Grandezza = nuovo sistemaM SK3DrawingMSC4grandezza

Questo .axWebBrowser1.TabIndex = 0;

Questo .axWebBrowserM SK1DocumentCompleto += nuovo AxSHDocVw.DWebBbrowserEventsMSC4\_DocumentCompleteEventHandlerM SK1 questo .axWebBrowser1\_DocumentComplete);

//

Formula //

//

Questo .AutoScale = falso ;

Questo .AutoScaleBaseSize = nuovo sistemaM SK2Drawing.SizeMSC4 13);

Questo .ClientSize = nuovo sistemaM SK2Drawing.SizeMST4 SST5

Questo .ControlsM SK1Add( questo .axWebBrowserMSC4

Questo .FormBorderStyle =Systeme.WindowsM SK3FormiMSC4Form BorderStyleMST5NienteMst6

Questo .Name = "FormaM SK3 ≥;

Questo .ShowInTaskbar = falso ;

Questo .Texto = "FormaM SK3 |

((Sistema.Modello di ComponenteM SK2IsupportInitialisareMSC3 questo .axWebBrowserMST5EndInitMst6

Questo .ResumeLayout( falso );

}

#la regione finale

/// &lt;riassunto&gt;

/// Il punto di ingresso principale della domanda.

/// &lt;/summario&gt;

[STAThread]

vuoto statico Main()

{

Applicazione.RunM SK1 nuovo modulo1());

}

Private void axWebBrowser1\_DocumentComplete(espeditore di oggetti , AxSHDocVwM SK3DWebBrowserEventsMSC4\_DocumentCompleteEvent e)

{

GrabWindow();

}

}

Classe GDI32

{

[DllImport( "GDIM SK2dll" ≥)]

bool externo statico pubblico BitBlt(IntPtr hdcDest,InstPtr nXDest ,InntPtrnYDest,

IntPtr n larghezza,IntPTR naltezza,InntPtr hdcSrcM SK2

IntPtr nXSrc,IntPTR nYSrc ,InntPtr dwRop);

[DllImport( "GDIM SK2dll" ≥)]

public static extern IntPtr CreateCompatibleBitmap(IntPTR hdc,InstPtr nWidthM SK2

IntPtr naltezza);

[DllImport( "GDIM SK2dll" ≥)]

public static extern IntPtr CreateCompatibleDC(IntPTR hdc);

[DllImport( "GDIM SK2dll" ≥)]

public static extern bool DeleteDC(IntPtr hdc);

[DllImport( "GDIM SK2dll" ≥)]

public static extern bool DeleteObject(IntPtr hObject≥);

[DllImport( "GDIM SK2dll" ≥)]

public static extern IntPtr GetDeviceCaps(IntPtri hdc,InstPtr nIndexM SK2

[DllImport( "GDIM SK2dll" ≥)]

Public static extern IntPtr SelectObject(IntPTR hdc,InstPtr hgdiobjM SK2

}

Class User32

{

[DllImport( "UserM SK2dll" ≥)]

public static extern IntPtr GetDesktopWindow();

[DllImport( "UserM SK2dll" ≥)]

public static extern IntPtr GetWindowDC(IntPtri hWnd);

[DllImport( "UserM SK2dll" ≥)]

Public static extern IntPtr ReleaseDC(IntPTR hWnd,InstPtr hDC );

[DllImport( "UserM SK2dll" ≥)]

public static extern int SendMessage(IntPtr hWnd,int MsgM SK2 IntPTR wParamMSC3 InstPtr lParam≥);

}

}