Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServices
Public Class WIN32
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents AxWebBrowser1 As AxSHDocVw.AxWebBrowser
Friend WithEvents txtUrl As System.Windows.Forms.TextBox
Friend WithEvents btnSubmit As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents btnCompleteSave As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(WIN32))
Me.AxWebBrowser1 = New AxSHDocVw.AxWebBrowser
Me.txtUrl = New System.Windows.Forms.TextBox
Me.btnSubmit = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.btnCompleteSave = New System.Windows.Forms.Button
CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'AxWebBrowser1
'
Me.AxWebBrowser1.Enabled = True
Me.AxWebBrowser1.Location = New System.Drawing.Point(8, 64)
Me.AxWebBrowser1.OcxState = CType(resources.GetObject("AxWebBrowser1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxWebBrowser1.Size = New System.Drawing.Size(776, 496)
Me.AxWebBrowser1.TabIndex = 0
'
'txtUrl
'
Me.txtUrl.Location = New System.Drawing.Point(16, 32)
Me.txtUrl.Name = "txtUrl"
Me.txtUrl.Size = New System.Drawing.Size(280, 20)
Me.txtUrl.TabIndex = 1
Me.txtUrl.Text = ""
'
'btnSubmit
'
Me.btnSubmit.Location = New System.Drawing.Point(304, 32)
Me.btnSubmit.Name = "btnSubmit"
Me.btnSubmit.Size = New System.Drawing.Size(75, 20)
Me.btnSubmit.TabIndex = 2
Me.btnSubmit.Text = "Submit"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(208, 23)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Enter a website address below"
'
'btnCompleteSave
'
Me.btnCompleteSave.BackColor = System.Drawing.Color.Red
Me.btnCompleteSave.Location = New System.Drawing.Point(384, 32)
Me.btnCompleteSave.Name = "btnCompleteSave"
Me.btnCompleteSave.Size = New System.Drawing.Size(128, 20)
Me.btnCompleteSave.TabIndex = 4
Me.btnCompleteSave.Text = "Save as complete file"
'
'WIN32
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(792, 573)
Me.Controls.Add(Me.btnCompleteSave)
Me.Controls.Add(Me.btnSubmit)
Me.Controls.Add(Me.txtUrl)
Me.Controls.Add(Me.AxWebBrowser1)
Me.Controls.Add(Me.Label1)
Me.Name = "WIN32"
Me.Text = "Form1"
CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.AxWebBrowser1.Navigate("http://www.msn.co.uk")
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Me.AxWebBrowser1.Navigate(Me.txtUrl.Text)
MsgBox(Me.AxWebBrowser1.HWND.MaxValue.ToString)
End Sub
Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" _
(ByVal hDestDC As Integer, ByVal x As Integer, _
ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal hSrcDC As Integer, _
ByVal xSrc As Integer, ByVal ySrc As Integer, _
ByVal dwRop As Integer) As Integer
Public Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" _
(ByVal hwnd As Integer) As Integer
Public Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" _
(ByVal hwnd As Integer, ByVal hdc As Integer) As Integer
Public Const SRCCOPY As Integer = &HCC0020
Private Sub btnCompleteSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompleteSave.Click
Dim bmp As Bitmap
Try
bmp = Hardcopy.CreateBitmap(Me.AxWebBrowser1.Document)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
bmp.Save("test.bmp")
End Sub
End Class
Public Class Hardcopy
Public Shared Function CreateBitmap( _
ByVal Control As Control) _
As Bitmap
Dim gDest As Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer
Dim hWnd As Integer = Control.Handle.ToInt32
CreateBitmap = New Bitmap(Control.Width, Control.Height)
gDest = gDest.FromImage(CreateBitmap)
hdcSrc = WIN32.GetWindowDC(hWnd)
hdcDest = gDest.GetHdc
WIN32.BitBlt( _
hdcDest.ToInt32, 0, 0, Control.Width, Control.Height, _
hdcSrc, 0, 0, WIN32.SRCCOPY _
)
gDest.ReleaseHdc(hdcDest)
WIN32.ReleaseDC(hWnd, hdcSrc)
End Function
End Class