Results 1 to 2 of 2

Thread: Microsoft web browser control

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    Microsoft web browser control

    Hey all, IF YOUR A GOD THEN ANSWER THIS. if you not but manage to answer this then you deserve to be a god.....

    OK ive made a small demo project just to help people know what i wana try and do......

    The concept

    1, navigate to webpage
    2, click a button, and save the webpage as a complete image.
    3, knowing how to do this NO IDEA....

    the sample project includes the web browser and everything else just need to make the bit that will save the file as a single document......

    Everyone please just take a couple of minutes, download the code and take a look.....

    Many Thanks

    Carl
    Attached Files Attached Files
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  2. #2

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    BUMP
    BUMP
    BUMP,

    Ummm come on people why am i answering my own questions.......

    PRIRATE you dead man ?

    Just for anyone who wants to know how to do this in the future heres the complete source code below....


    OK now i understand everything whats going on how to do capture the DEVICE CONTEXT of the axwebbrowser control or mshtml control, they are probably closing the DC off and releasing the memory once painted how can this be intercepted ........

    The vb code below takes and draws the control axWebBroswer fine you only want to take small screen shots, if you want to capture the entire page then you would need to grab the DC from the control, this i dont know how to do yet...

    VB Code:
    1. Imports System
    2. Imports System.Drawing
    3. Imports System.Drawing.Drawing2D
    4. Imports System.Drawing.Imaging
    5. Imports System.Collections
    6. Imports System.ComponentModel
    7. Imports System.Windows.Forms
    8. Imports System.Data
    9. Imports System.Runtime.InteropServices
    10.  
    11.  
    12. Public Class WIN32
    13.     Inherits System.Windows.Forms.Form
    14.  
    15. #Region " Windows Form Designer generated code "
    16.  
    17.     Public Sub New()
    18.         MyBase.New()
    19.  
    20.         'This call is required by the Windows Form Designer.
    21.         InitializeComponent()
    22.  
    23.         'Add any initialization after the InitializeComponent() call
    24.  
    25.     End Sub
    26.  
    27.     'Form overrides dispose to clean up the component list.
    28.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    29.         If disposing Then
    30.             If Not (components Is Nothing) Then
    31.                 components.Dispose()
    32.             End If
    33.         End If
    34.         MyBase.Dispose(disposing)
    35.     End Sub
    36.  
    37.     'Required by the Windows Form Designer
    38.     Private components As System.ComponentModel.IContainer
    39.  
    40.     'NOTE: The following procedure is required by the Windows Form Designer
    41.     'It can be modified using the Windows Form Designer.  
    42.     'Do not modify it using the code editor.
    43.     Friend WithEvents AxWebBrowser1 As AxSHDocVw.AxWebBrowser
    44.     Friend WithEvents txtUrl As System.Windows.Forms.TextBox
    45.     Friend WithEvents btnSubmit As System.Windows.Forms.Button
    46.     Friend WithEvents Label1 As System.Windows.Forms.Label
    47.     Friend WithEvents btnCompleteSave As System.Windows.Forms.Button
    48.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    49.         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(WIN32))
    50.         Me.AxWebBrowser1 = New AxSHDocVw.AxWebBrowser
    51.         Me.txtUrl = New System.Windows.Forms.TextBox
    52.         Me.btnSubmit = New System.Windows.Forms.Button
    53.         Me.Label1 = New System.Windows.Forms.Label
    54.         Me.btnCompleteSave = New System.Windows.Forms.Button
    55.         CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).BeginInit()
    56.         Me.SuspendLayout()
    57.         '
    58.         'AxWebBrowser1
    59.         '
    60.         Me.AxWebBrowser1.Enabled = True
    61.         Me.AxWebBrowser1.Location = New System.Drawing.Point(8, 64)
    62.         Me.AxWebBrowser1.OcxState = CType(resources.GetObject("AxWebBrowser1.OcxState"), System.Windows.Forms.AxHost.State)
    63.         Me.AxWebBrowser1.Size = New System.Drawing.Size(776, 496)
    64.         Me.AxWebBrowser1.TabIndex = 0
    65.         '
    66.         'txtUrl
    67.         '
    68.         Me.txtUrl.Location = New System.Drawing.Point(16, 32)
    69.         Me.txtUrl.Name = "txtUrl"
    70.         Me.txtUrl.Size = New System.Drawing.Size(280, 20)
    71.         Me.txtUrl.TabIndex = 1
    72.         Me.txtUrl.Text = ""
    73.         '
    74.         'btnSubmit
    75.         '
    76.         Me.btnSubmit.Location = New System.Drawing.Point(304, 32)
    77.         Me.btnSubmit.Name = "btnSubmit"
    78.         Me.btnSubmit.Size = New System.Drawing.Size(75, 20)
    79.         Me.btnSubmit.TabIndex = 2
    80.         Me.btnSubmit.Text = "Submit"
    81.         '
    82.         'Label1
    83.         '
    84.         Me.Label1.Location = New System.Drawing.Point(16, 16)
    85.         Me.Label1.Name = "Label1"
    86.         Me.Label1.Size = New System.Drawing.Size(208, 23)
    87.         Me.Label1.TabIndex = 3
    88.         Me.Label1.Text = "Enter a website address below"
    89.         '
    90.         'btnCompleteSave
    91.         '
    92.         Me.btnCompleteSave.BackColor = System.Drawing.Color.Red
    93.         Me.btnCompleteSave.Location = New System.Drawing.Point(384, 32)
    94.         Me.btnCompleteSave.Name = "btnCompleteSave"
    95.         Me.btnCompleteSave.Size = New System.Drawing.Size(128, 20)
    96.         Me.btnCompleteSave.TabIndex = 4
    97.         Me.btnCompleteSave.Text = "Save as complete file"
    98.         '
    99.         'WIN32
    100.         '
    101.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    102.         Me.ClientSize = New System.Drawing.Size(792, 573)
    103.         Me.Controls.Add(Me.btnCompleteSave)
    104.         Me.Controls.Add(Me.btnSubmit)
    105.         Me.Controls.Add(Me.txtUrl)
    106.         Me.Controls.Add(Me.AxWebBrowser1)
    107.         Me.Controls.Add(Me.Label1)
    108.         Me.Name = "WIN32"
    109.         Me.Text = "Form1"
    110.         CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).EndInit()
    111.         Me.ResumeLayout(False)
    112.  
    113.     End Sub
    114.  
    115. #End Region
    116.  
    117.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    118.         Me.AxWebBrowser1.Navigate("http://www.msn.co.uk")
    119.     End Sub
    120.  
    121.  
    122.     Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
    123.         Me.AxWebBrowser1.Navigate(Me.txtUrl.Text)
    124.         MsgBox(Me.AxWebBrowser1.HWND.MaxValue.ToString)
    125.     End Sub
    126.  
    127.     Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" _
    128.           (ByVal hDestDC As Integer, ByVal x As Integer, _
    129.           ByVal y As Integer, ByVal nWidth As Integer, _
    130.           ByVal nHeight As Integer, ByVal hSrcDC As Integer, _
    131.           ByVal xSrc As Integer, ByVal ySrc As Integer, _
    132.           ByVal dwRop As Integer) As Integer
    133.  
    134.  
    135.     Public Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" _
    136.         (ByVal hwnd As Integer) As Integer
    137.  
    138.     Public Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" _
    139.         (ByVal hwnd As Integer, ByVal hdc As Integer) As Integer
    140.  
    141.     Public Const SRCCOPY As Integer = &HCC0020
    142.  
    143.     Private Sub btnCompleteSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompleteSave.Click
    144.         Dim bmp As Bitmap
    145.         Try
    146.             bmp = Hardcopy.CreateBitmap(Me.AxWebBrowser1.Document)
    147.         Catch ex As Exception
    148.             MsgBox(ex.ToString)
    149.         End Try
    150.  
    151.         bmp.Save("test.bmp")
    152.     End Sub
    153.  
    154. End Class
    155.  
    156. Public Class Hardcopy
    157.  
    158.  
    159.     Public Shared Function CreateBitmap( _
    160.                ByVal Control As Control) _
    161.                 As Bitmap
    162.  
    163.  
    164.         Dim gDest As Graphics
    165.         Dim hdcDest As IntPtr
    166.         Dim hdcSrc As Integer
    167.         Dim hWnd As Integer = Control.Handle.ToInt32
    168.  
    169.  
    170.         CreateBitmap = New Bitmap(Control.Width, Control.Height)
    171.         gDest = gDest.FromImage(CreateBitmap)
    172.  
    173.  
    174.         hdcSrc = WIN32.GetWindowDC(hWnd)
    175.         hdcDest = gDest.GetHdc
    176.  
    177.  
    178.         WIN32.BitBlt( _
    179.               hdcDest.ToInt32, 0, 0, Control.Width, Control.Height, _
    180.               hdcSrc, 0, 0, WIN32.SRCCOPY _
    181.                )
    182.  
    183.  
    184.         gDest.ReleaseHdc(hdcDest)
    185.         WIN32.ReleaseDC(hWnd, hdcSrc)
    186.  
    187.  
    188.     End Function
    189.  
    190.  
    191. End Class
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width