CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2003
    Location
    Sri Lanka
    Posts
    64

    Capturing Web Page as a Image

    Hi All,

    I need to convert web page appear in IE to an image. It should capture whole web page Visible and Invisible area of web page.

    If any body has done similar things please help me.

    Thanks in advance.


    Dinesh
    --
    web : http://www.freewebs.com/dineshns

  2. #2
    Join Date
    Nov 2003
    Posts
    2,185

    Re: Capturing Web Page as a Image

    I think this thread is useful for you.

  3. #3
    Join Date
    Sep 2003
    Location
    Sri Lanka
    Posts
    64

    Re: Capturing Web Page as a Image

    HI Tischnoetentoet,

    Thanks for your response. It is done with WebBrowserControlle. I need to capture web page appear in a Top most IE window.

    Thanks,

    Dinesh
    --
    web : http://www.freewebs.com/dineshns

  4. #4
    Join Date
    Nov 2003
    Posts
    2,185

    Re: Capturing Web Page as a Image

    You have two options here:

    1) Automatically control the IE window and send Window Messages (WM_???) to scroll, etc. However, this is much easier in C++.

    2) You can write a BHO for this. You can use this article to see how to create a BHO and a Toolbar where users can click to save the webpage.

  5. #5
    Join Date
    Sep 2003
    Location
    Sri Lanka
    Posts
    64

    Re: Capturing Web Page as a Image

    Hi Tischnoetentoet,

    Thanks For the reply.

    I was try up with the first solution you mentioned. The problem arose with the scrollbar. It is not the real WIn32 Scroll bar. So we cant scroll with Windows Messages (WM_????).

    The second option is new for me. I will look at it.

    Thanks.

    Dinesh
    --
    web : http://www.freewebs.com/dineshns

  6. #6
    Join Date
    Nov 2003
    Posts
    2,185

    Re: Capturing Web Page as a Image

    but you can find the right class by using spy++, so that shouldn't be a problem at all.

  7. #7
    Join Date
    Sep 2003
    Location
    Sri Lanka
    Posts
    64

    Re: Capturing Web Page as a Image

    Hi ,

    I try with Spy++. There is no WM_?? messages fires for Scrolling. After I Just Try with Notepad, There is WM_?? for Scrolling.

    Have you tested it with Spy++ ? If you have do it please help me to Find it out.

    Thanks

    Dinesh
    --
    web : http://www.freewebs.com/dineshns

  8. #8
    Join Date
    Nov 2003
    Posts
    2,185

    Re: Capturing Web Page as a Image

    I have researched this a bit, and written a small C++ application that allows you to scroll pages in internet explorer (7).

    Code:
    void CIEScrollTestDlg::ScrollIEWindow()
    {
    	// Declare variables
    	HWND hWndIEFrame = NULL;
    	HWND hWndTabWindowClass = NULL;
    	HWND hWndShellDocObjectView = NULL; 
    	HWND hWndIEServer = NULL;
    
    	// Find all windows
    	hWndIEFrame = ::FindWindow(_T("IEFrame"), NULL);
    	hWndTabWindowClass = ::FindWindowEx(hWndIEFrame, NULL, _T("TabWindowClass"), NULL);
    	hWndShellDocObjectView = ::FindWindowEx(hWndTabWindowClass, NULL, _T("Shell DocObject View"), NULL);
    	hWndIEServer = ::FindWindowEx(hWndShellDocObjectView, NULL, _T("Internet Explorer_Server"), NULL);
    
    	// Did we find the frame?
    	if (hWndIEServer != NULL)
    	{
    		// Yes, scroll down
    		::PostMessage(hWndIEServer, WM_VSCROLL, SB_LINEDOWN, 0);
    	}
    }
    It should be really easy to port this code to C# (by importing the API functions).

  9. #9
    Join Date
    Sep 2003
    Location
    Sri Lanka
    Posts
    64

    Re: Capturing Web Page as a Image

    Hi Tischnoetentoet,

    Thanks for the code you posted. I did convert it to C# and it works fine.
    But I cant Get scroll bar Information with GetScrollInfo().

    Code:
               
    
            public struct SCROLLINFO
            {
                public int cbSize;
                public int fMask;
                public int nMin;
                public int nMax;
                public int nPage;
                public int nPos;
                public int nTrackPos;
            }
    
            [DllImport("user32.dll", SetLastError = true)]
            private static extern int GetScrollInfo(IntPtr hWnd, int n, ref    SCROLLINFO lpScrollInfo);
     
    
                SCROLLINFO si = new SCROLLINFO();
                si.fMask = SIF_ALL;
                si.cbSize = Marshal.SizeOf(si);
                GetScrollInfo(hWndIEServer, SB_VERT, ref si);
    
                MessageBox.Show(si.nPage.ToString());
    I check the above with Notepad Handle It works well. What could be the reason.

    Is there any method to get scroll position and information.

    Thanks
    --
    web : http://www.freewebs.com/dineshns

  10. #10
    Join Date
    Nov 2003
    Posts
    2,185

    Re: Capturing Web Page as a Image

    Sorry for my late reply, I was on vacation.

    I think this documentation on PInvoke.net is very useful for you, it contains example code.

  11. #11
    Join Date
    Sep 2003
    Location
    Sri Lanka
    Posts
    64

    Re: Capturing Web Page as a Image

    Hi Tischnoetentoet,

    Hope you enjoyed well. Thanks for the link.

    The code which I have posted is also working for Notepad. But not for IE. What could be the reason ?


    Tnaks

    Dinesh
    --
    web : http://www.freewebs.com/dineshns

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

Featured