Results 1 to 8 of 8

Thread: [RESOLVED] GetPixel on a WebBrowser

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    31

    Resolved [RESOLVED] GetPixel on a WebBrowser

    het solved
    Last edited by bim11; Jun 3rd, 2008 at 03:19 PM.

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: GetPixel on a WebBrowser

    To be honest I have no idea but I found some code on the web and then pieced this together, and it seems to work. Tested using a single browser control on a form.

    Code:
    Option Explicit
    
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Code:
    Private Sub Command1_Click()
    
        Dim WebDC As Long
        Dim Lcolor As Long
        Dim hWnd1 As Long, hWnd2 As Long, hwnd3 As Long
        
        Const strClass1 As String = "Shell Embedding"
        Const strClass2 As String = "Shell DocObject View"
        Const strClass3 As String = "Internet Explorer_Server"
        
        hWnd1 = FindWindowEx(Me.hwnd, 0, strClass1, vbNullString)
        hWnd2 = FindWindowEx(hWnd1, 0, strClass2, vbNullString)
        hwnd3 = FindWindowEx(hWnd2, 0, strClass3, vbNullString)
        
        WebDC = GetDC(hwnd3)
        
        If WebDC Then
            Lcolor = GetPixel(WebDC, 50, 50)
            Debug.Print Lcolor ' color @ 50,50
            ReleaseDC 0, WebDC
        End If
    
    End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    31

    Re: GetPixel on a WebBrowser

    het solved
    Last edited by bim11; Jun 3rd, 2008 at 03:20 PM.

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: GetPixel on a WebBrowser

    The only way I know how to do that would be to use the EnumChildWindows API function. You could find all the "Shell Embedding" classes in the form, then figure that Hwnd3 you need and add that to a listbox or array. Once you know what the order the browsers are in the listbox/array the rest should be pretty simple.

    I could probably post up an example later if you're still stuck.

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: GetPixel on a WebBrowser

    Well here is what I came up with, if you know a better way please post it!
    Attached Files Attached Files

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    31

    Re: GetPixel on a WebBrowser

    het solved
    Last edited by bim11; Jun 3rd, 2008 at 03:20 PM.

  7. #7
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: GetPixel on a WebBrowser

    Quote Originally Posted by bim11
    Nice code. Worked a treat


    Thanks bro.
    Glad I could help!

  8. #8
    Lively Member
    Join Date
    Aug 2008
    Location
    Between the keyboard and the chair.
    Posts
    122

    Re: [RESOLVED] GetPixel on a WebBrowser

    I realise that this post is a little old, but bim11 I can't help but want to chew you a new one... You had a valid question, and when it was answered... you erased it. Yes, given that the answers and title lead me to believe you were looking for a way to get a pixel from within a browser window, but it goes without saying, don't modify your posts when someone else could have exactly the same problem.

    FYI, this was not what I was looking for, but thats besides the point.
    If I have helped you out, be a pal and rate the helpful post!

    My CodeBank Submissions:
    Convert Color Values Between Long, RGB and Hex. Updated Sept 25th!
    Update Checker FrameWork

    My WIP Projects:
    Winsock Chat Server/Client Updated Oct 5th!

    Useful Tools:
    Aivosto.com MZ-Tools SysInternals Suite

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