Results 1 to 7 of 7

Thread: Web Browser Control...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    113

    Web Browser Control...

    First, I have a web browser control that loads a webpage.

    Once the webpage is loaded I then need to make a copy of that webpage and store it as a bitmap image in root drive c:\ of local machine.

    Here's what I have so far... (Select, Copy, Clear selection)
    But how do you create/save selection as image from clipboard ??
    Is their a better way to do what I need ??

    Code:
      ' Select all from webbrowser
      WebBrowser1.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DONTPROMPTUSER
      ' Copy the text to Clipboard
      WebBrowser1.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER
      ' Clear the selection
      WebBrowser1.ExecWB OLECMDID_CLEARSELECTION, OLECMDEXECOPT_DONTPROMPTUSER

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Web Browser Control...

    Try this
    Code:
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _ 
    ByVal dwFlags As Long, ByVal dwExtraInfo As Long) 
    
    Private Const VK_SNAPSHOT = &H2C 
    
    Private Function SaveScreen(ByVal pstrFileName As String) As Boolean 
    
    'To get the Entire Screen 
    Call keybd_event(vbKeySnapshot, 1, 0, 0) 
    
    'To get the Active Window 
    'Call keybd_event(vbKeySnapshot, 0, 0, 0) 
    
    SavePicture Clipboard.GetData(vbCFBitmap), pstrFileName 
    
    SaveScreen = True 
     
    End Function 
    
    Private Sub Command1_Click()
    Call SaveScreen("C:\Windows\Desktop\shot1.bmp") 
    End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    113

    Smile Re: Web Browser Control...

    Hack...

    First off, thanks for your helpful code and quick reply !!!

    I have tried out you code and it works great... However I really need to be able to capture only what is contained within the web browser control and not the entire form.

    Thanks Again !!!

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Web Browser Control...

    If you notice that the code I posted gives you two options.

    Entire Screen is active.

    Comment that out, and use the other one which is just the Active Window. See how that works.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    113

    Re: Web Browser Control...

    Hack,

    I must be doing something wrong because it gives me the same image as before (the entire screen).

    I first thought maybe I needed to "setfocus" to the web browser control before calling your routine but that was no help...

    Code:
     
      WebBrowser1.SetFocus
      Call SaveScreen("C:\" & Format(Now, "HHMMSS") & ".bmp")
      
      Clipboard.Clear  ' <-- doesn't seem to clear clipboard ??

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Web Browser Control...

    Arey you using Call keybd_event(vbKeySnapshot, 0, 0, 0) instead of Call keybd_event(vbKeySnapshot, 1, 0, 0)

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    113

    Re: Web Browser Control...

    Yup... Calling the correct line.

    Call keybd_event(vbKeySnapshot, 0, 0, 0)

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