Hi,
I'm trying to capture hidden window's data that is in IE's
AxSHDocVw.AxWebBrowser ActiveX control.
If Control and window are visible, code below works but if Control
and it's window is hidden e.g. emmedded in dll, code does not save
data as an picture. How should I handle this kind of situation?
How can I get data printed to file if AxWebBrowser is hidden and
in dll file?
Cheers,
public void CaptureWindow(AxSHDocVw.AxWebBrowser axWebBrowser1,
string fileName,
ImageFormat imageFormat)
{
// Handle to BrowserControl
IntPtr hwnd = axWebBrowser1.Handle;
// Get handle to Browser's ActiveX Window
int hdcSrc = User32.GetWindowDC(hwnd.ToInt32()),
hdcDest = GDI32.CreateCompatibleDC(hdcSrc), // Creating memory device
context
hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, // Creating Bitmpat in
memory
axWebBrowser1.Width, axWebBrowser1.Height); // Width and Heigth of the
Browser's Window
// For creating color bitmap
GDI32.SelectObject(hdcDest,hBitmap);
// Performs a bit-block transfer of the color data corresponding to a
rectangle of
// pixels from the specified source device context into a destination
device context
GDI32.BitBlt(hdcDest, 0, 0,
GDI32.GetDeviceCaps(hdcSrc,8), // Width of destination rectangle
GDI32.GetDeviceCaps(hdcSrc,10), // Heigth of destination rectangle
hdcSrc,0,0,0x00CC0020);
// Saving Bitmap as file. Format can be e.g. gif, jpeg, tiff etc.
SaveImage(hBitmap, fileName, imageFormat);
// Releasing resources
User32.ReleaseDC(hwnd.ToInt32(), hdcSrc);
GDI32.DeleteDC(hdcDest);
GDI32.DeleteObject(hBitmap);
}