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
[248 byte] By [
dineshns] at [2007-11-20 9:59:35]

# 1 Re: Capturing Web Page as a Image
I think this thread ( http://www.dev-archive.com/forum/showthread.php?t=429981) is useful for you.
# 2 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
# 3 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 (http://www.codeproject.com/csharp/BandObjects20.asp) to see how to create a BHO and a Toolbar where users can click to save the webpage.
# 4 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
# 5 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.
# 6 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
# 7 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).
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).
# 8 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().
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
# 9 Re: Capturing Web Page as a Image
Sorry for my late reply, I was on vacation.
I think this documentation on PInvoke.net ( http://www.pinvoke.net/default.aspx/user32/GetScrollInfo.html) is very useful for you, it contains example code.
# 10 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