Back to "Het omzetten van HTML-documenten in afbeeldingen...de code"

This is a viewer only at the moment see the article on how this works.

To update the preview hit Ctrl-Alt-R (or ⌘-Alt-R on Mac) or Enter to refresh. The Save icon lets you save the markdown file to disk

This is a preview from the server running through my markdig pipeline

Imported mostlylucidcouk

Het omzetten van HTML-documenten in afbeeldingen...de code

Wednesday, 30 June 2004

Nou, na een beetje spelen heb ik iets aan de hand nu, Ik ben geen Win32 coder maar dit lijkt te werken:

gebruik van systeem;

gebruik van System.Drawing;

het gebruik van System.Drawing.Imaging;

het gebruik van System.Collecties;

gebruik van System.ComponentModel;

gebruik van System.Windows.Forms;

gebruik van System.Data;

gebruik van mshtml;

gebruik van System.Runtime.InteropServices;

het gebruik van Microsoft.Win32;

namespace ThumbMaker

{

/// <samenvatting>

/// Samenvatting van de beschrijving van formulier 1.

/// <Samenvatting>

publieke klasse Form1 : System.Windows.Forms.Formulier

{

privé AxSHDocVw.AxWebBrowser axWebBrowser1;

/// <samenvatting>

/// Vereiste ontwerper variabele.

/// <Samenvatting>

private System.ComponentModel.Container componenten = nul;

private const string urlStr = "http://news.bbc.co.uk/" ;

openbaar formulier1()

{

//

// Vereist voor ondersteuning voor Windows-formulierontwerpers

//

InitialiserenComponent();

object o = nul;

.Visible= false ;

axWebBrowser1.Navigeren(urlStr, ref o, ref o, ref o, ref o);

}

const int WM_PAINT = 0x000F;

const int WM_PRINTCLIENT = 0x0318;

const int WM_ERASEVKGND = 0x0014;

const int WM_PRINT = 0x0317;

const int PRF_CHILLEN = 0x00000010;

const int PRF_CLIENT = 0x00000004;

publieke leegte GrabWindow()

{

IntPtr hWnd = deze .Handle;

IntPtr hBmp;

Bitmap MyBitmap= null;

IntPtr hDCMem = GDI32.CreateCompatibleDC((IntPtr) null );

IntPtr hDC = User32.GetWindowDC(hWnd);

hBmp = GDI32.CreateCompatibleBitmap(hDC,(IntPtr)axWebBrowser1.Breedte ,(IntPtr)axWebBrowser1.Hoogte);

Gebruiker32.ReleaseDC(hWnd, hDC);

IntPtr hOld = GDI32.SelectObject(hDCMem, hBmp);

Gebruiker32.SendMessage(hWnd, WM_PRINT, hDCMem, nieuwe IntPtr(PRF_cliënt PRF_KILLEN));

GDI32.SelectObject(hDCMem, hOld);

GDI32.DeleteObject(hDCMem);

MyBitmap = Bitmap.FromHbitmap(hBmp);

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

Dit .Close();

}

/// <samenvatting>

// Maak alle gebruikte middelen schoon.

/// <Samenvatting>

Beschermde override leegte Gooien(bool afvoeren)

{

indien (verdwenen)

{

als (componenten != nul)

{

componenten.Dispose();

}

}

base .Dispose(disposing );

}

#region Windows Form Designer gegenereerde code

/// <samenvatting>

/// Vereiste methode voor ondersteuning van ontwerpers - niet wijzigen

// de inhoud van deze methode met de code-editor.

/// <Samenvatting>

prive leegte InitializeComponent()

{

System.Resources.ResourceManager resources = new System.Resources.ResourceManager( typeof (Form1));

deze .axWebBrowser1 = nieuwe AxSHDocVw.AxWebBrowser();

((System.ComponentModel.ISupportInitialize)(dit .axWebBrowser1)).BeginInit();

.SuspendLayout();

//

// axWebBrowser1

//

.axWebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;

deze .axWebBrowser1.Ingeschakeld = waar;

.axWebBrowser1.Locatie = nieuw System.Drawing.Point(0, 0);

.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject( "axWebBrowser1.OcxState" )));

deze .axWebBrowser1.Size = nieuw System.Drawing.Size(1024, 768);

deze .axWebBrowser1.TabIndex = 0;

deze .axWebBrowser1.DocumentComplete += nieuwe AxSHDocVw.DWebbrowserEvents2_DocumentCompleteEventHandler( this .axWebBrowser1_Documentvoltooien);

//

Formulier 1

//

.AutoScale = false ;

.AutoScaleBaseSize = nieuw System.Drawing.Size(5, 13);

deze .ClientSize = nieuw System.Drawing.Size(1024, 768);

.Controls.Add( this .axWebBrowser1);

deze .FormBorderStyle = System.Windows.Forms.Form BorderStyle.Geen;

.Naam = "Form1" ;

deze .ShowInTaskbar = false;

deze .Tekst = "Form1" ;

((System.ComponentModel.ISupportInitialize)(dit .axWebBrowser1)).EndInit();

deze .ResumeLayout( false );

}

#endregion

/// <samenvatting>

// Het hoofdingangspunt voor de aanvraag.

/// <Samenvatting>

[STATHread]

statische leegte Main()

{

Application.Run( new Form1());

}

privé leegte axWebBrowser1_DocumentComplete( object afzender, AxSHDocVw.DWebbrowserEvents2_Documentvoltooidevent e)

{

GrabWindow();

}

}

klasse GDI32

{

[DllImport( "GDI32.dll" )]

publieke statische externe bool BitBlt(IntPtr hdcDest,IntPtr nXDest,IntPtr nYDest,

IntPtr nWidth,IntPtr nHeight,IntPtr hdcSrc,

IntPtr nXSrc,IntPtr nYSrc,IntPtr dwRop);

[DllImport( "GDI32.dll" )]

public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc,IntPtr nWidth,

IntPtr nHeight);

[DllImport( "GDI32.dll" )]

publieke statische externe IntPtr CreateCompatibleDC(IntPtr hdc);

[DllImport( "GDI32.dll" )]

publieke statische externe bool DeleteDC(IntPtr hdc);

[DllImport( "GDI32.dll" )]

publieke statische externe bool DeleteObject(IntPtr hObject);

[DllImport( "GDI32.dll" )]

publieke statische externe IntPtr GetDeviceCaps(IntPtr hdc,IntPtr nIndex);

[DllImport( "GDI32.dll" )]

publieke statische externe IntPtr SelectObject(IntPtr hdc,IntPtr hgdiobj);

}

klasse Gebruiker32

{

[DllImport( "User32.dll" )]

publieke statische externe IntPtr GetDesktopWindow();

[DllImport( "User32.dll" )]

publieke statische externe IntPtr GetWindowDC(IntPtr hWnd);

[DllImport( "User32.dll" )]

publieke statische extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDC);

[DllImport( "User32.dll" )]

publieke statische externe int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

}

}

logo

© 2026 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.