/// <summary>
        /// Here the logic for capturing the IE Content is located
        /// </summary>
        /// <param name="capture">ICapture where the capture needs to be stored</param>
        /// <returns>ICapture with the content (if any)</returns>
        public static ICapture CaptureIE(ICapture capture)
        {
            WindowDetails activeWindow = WindowDetails.GetActiveWindow();

            // Show backgroundform after retrieving the active window..
            BackgroundForm backgroundForm = new BackgroundForm(Language.GetString(LangKey.contextmenu_captureie), Language.GetString(LangKey.wait_ie_capture));
            backgroundForm.Show();
            //BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(language.GetString(LangKey.contextmenu_captureie), language.GetString(LangKey.wait_ie_capture));
            try {
                //Get IHTMLDocument2 for the current active window
                DocumentContainer documentContainer = GetDocument(activeWindow);

                // Nothing found
                if (documentContainer == null) {
                    LOG.Debug("Nothing to capture found");
                    return null;
                }
                LOG.DebugFormat("Window class {0}", documentContainer.ContentWindow.ClassName);
                LOG.DebugFormat("Window location {0}", documentContainer.ContentWindow.Location);

                // The URL is available unter "document2.url" and can be used to enhance the meta-data etc.
                capture.CaptureDetails.AddMetaData("url", documentContainer.Url);

                // bitmap to return
                Bitmap returnBitmap = null;
                Size pageSize = Size.Empty;
                try {
                    pageSize = PrepareCapture(documentContainer, capture);
                    returnBitmap = capturePage(documentContainer, capture, pageSize);
                } catch (Exception captureException) {
                    LOG.Error("Exception found, ignoring and returning nothing! Error was: ", captureException);
                }
                // Capture the element on the page
                try {
                    if (configuration.IEFieldCapture && capture.CaptureDetails.HasDestination("Editor")) {
                        // clear the current elements, as they are for the window itself
                        capture.Elements.Clear();
                        CaptureElement documentCaptureElement = documentContainer.CreateCaptureElements(pageSize);
                        foreach(DocumentContainer frameDocument in documentContainer.Frames) {
                            CaptureElement frameCaptureElement = frameDocument.CreateCaptureElements(Size.Empty);
                            if (frameCaptureElement != null) {
                                documentCaptureElement.Children.Add(frameCaptureElement);
                            }
                        }
                        capture.AddElement(documentCaptureElement);
                        // Offset the elements, as they are "back offseted" later...
                        Point windowLocation = documentContainer.ContentWindow.WindowRectangle.Location;
                        capture.MoveElements(-(capture.ScreenBounds.Location.X-windowLocation.X), -(capture.ScreenBounds.Location.Y-windowLocation.Y));
                    }
                } catch (Exception elementsException) {
                    LOG.Warn("An error occurred while creating the capture elements: ", elementsException);
                }

                if (returnBitmap == null) {
                    return null;
                }

                // Store the bitmap for further processing
                capture.Image = returnBitmap;
                // Store the location of the window
                capture.Location = documentContainer.ContentWindow.Location;

                // Store the title of the page
                if (documentContainer.Name != null) {
                    capture.CaptureDetails.Title = documentContainer.Name;
                } else {
                    capture.CaptureDetails.Title = activeWindow.Text;
                }

                // Store the URL of the page
                if (documentContainer.Url != null) {
                    Uri uri = new Uri(documentContainer.Url);
                    capture.CaptureDetails.AddMetaData("URL", uri.OriginalString);
                    // As the URL can hardly be used in a filename, the following can be used
                    if (!string.IsNullOrEmpty(uri.Scheme)) {
                        capture.CaptureDetails.AddMetaData("URL_SCHEME", uri.Scheme);
                    }
                    if (!string.IsNullOrEmpty(uri.DnsSafeHost)) {
                        capture.CaptureDetails.AddMetaData("URL_HOSTNAME", uri.DnsSafeHost);
                    }
                    if (!string.IsNullOrEmpty(uri.AbsolutePath)) {
                        capture.CaptureDetails.AddMetaData("URL_PATH", uri.AbsolutePath);
                    }
                    if (!string.IsNullOrEmpty(uri.Query)) {
                        capture.CaptureDetails.AddMetaData("URL_QUERY", uri.Query);
                    }
                    if (!string.IsNullOrEmpty(uri.UserInfo)) {
                        capture.CaptureDetails.AddMetaData("URL_USER", uri.UserInfo);
                    }
                    capture.CaptureDetails.AddMetaData("URL_PORT", uri.Port.ToString());
                }

                // Only move the mouse to correct for the capture offset
                capture.MoveMouseLocation(-documentContainer.ViewportRectangle.X, -documentContainer.ViewportRectangle.Y);
                // Used to be: capture.MoveMouseLocation(-(capture.Location.X + documentContainer.CaptureOffset.X), -(capture.Location.Y + documentContainer.CaptureOffset.Y));
            } finally {
                // Always close the background form
                backgroundForm.CloseDialog();
            }
            return capture;
        }
        /// <summary>
        /// Here the logic for capturing the IE Content is located
        /// </summary>
        /// <param name="capture">ICapture where the capture needs to be stored</param>
        /// <returns>ICapture with the content (if any)</returns>
        public static ICapture CaptureIE(ICapture capture)
        {
            WindowDetails activeWindow = WindowDetails.GetActiveWindow();

            // Show backgroundform after retrieving the active window..
            BackgroundForm backgroundForm = new BackgroundForm(Language.GetString(LangKey.contextmenu_captureie), Language.GetString(LangKey.wait_ie_capture));

            backgroundForm.Show();
            //BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(language.GetString(LangKey.contextmenu_captureie), language.GetString(LangKey.wait_ie_capture));
            try {
                //Get IHTMLDocument2 for the current active window
                DocumentContainer documentContainer = GetDocument(activeWindow);

                // Nothing found
                if (documentContainer == null)
                {
                    LOG.Debug("Nothing to capture found");
                    return(null);
                }
                LOG.DebugFormat("Window class {0}", documentContainer.ContentWindow.ClassName);
                LOG.DebugFormat("Window location {0}", documentContainer.ContentWindow.Location);

                // The URL is available unter "document2.url" and can be used to enhance the meta-data etc.
                capture.CaptureDetails.AddMetaData("url", documentContainer.Url);

                // bitmap to return
                Bitmap returnBitmap = null;
                Size   pageSize     = Size.Empty;
                try {
                    pageSize     = PrepareCapture(documentContainer, capture);
                    returnBitmap = capturePage(documentContainer, capture, pageSize);
                } catch (Exception captureException) {
                    LOG.Error("Exception found, ignoring and returning nothing! Error was: ", captureException);
                }
                // Capture the element on the page
                try {
                    if (configuration.IEFieldCapture && capture.CaptureDetails.HasDestination("Editor"))
                    {
                        // clear the current elements, as they are for the window itself
                        capture.Elements.Clear();
                        CaptureElement documentCaptureElement = documentContainer.CreateCaptureElements(pageSize);
                        foreach (DocumentContainer frameDocument in documentContainer.Frames)
                        {
                            CaptureElement frameCaptureElement = frameDocument.CreateCaptureElements(Size.Empty);
                            if (frameCaptureElement != null)
                            {
                                documentCaptureElement.Children.Add(frameCaptureElement);
                            }
                        }
                        capture.AddElement(documentCaptureElement);
                        // Offset the elements, as they are "back offseted" later...
                        Point windowLocation = documentContainer.ContentWindow.WindowRectangle.Location;
                        capture.MoveElements(-(capture.ScreenBounds.Location.X - windowLocation.X), -(capture.ScreenBounds.Location.Y - windowLocation.Y));
                    }
                } catch (Exception elementsException) {
                    LOG.Warn("An error occurred while creating the capture elements: ", elementsException);
                }


                if (returnBitmap == null)
                {
                    return(null);
                }

                // Store the bitmap for further processing
                capture.Image = returnBitmap;
                // Store the location of the window
                capture.Location = documentContainer.ContentWindow.Location;

                // Store the title of the page
                if (documentContainer.Name != null)
                {
                    capture.CaptureDetails.Title = documentContainer.Name;
                }
                else
                {
                    capture.CaptureDetails.Title = activeWindow.Text;
                }

                // Store the URL of the page
                if (documentContainer.Url != null)
                {
                    Uri uri = new Uri(documentContainer.Url);
                    capture.CaptureDetails.AddMetaData("URL", uri.OriginalString);
                    // As the URL can hardly be used in a filename, the following can be used
                    if (!string.IsNullOrEmpty(uri.Scheme))
                    {
                        capture.CaptureDetails.AddMetaData("URL_SCHEME", uri.Scheme);
                    }
                    if (!string.IsNullOrEmpty(uri.DnsSafeHost))
                    {
                        capture.CaptureDetails.AddMetaData("URL_HOSTNAME", uri.DnsSafeHost);
                    }
                    if (!string.IsNullOrEmpty(uri.AbsolutePath))
                    {
                        capture.CaptureDetails.AddMetaData("URL_PATH", uri.AbsolutePath);
                    }
                    if (!string.IsNullOrEmpty(uri.Query))
                    {
                        capture.CaptureDetails.AddMetaData("URL_QUERY", uri.Query);
                    }
                    if (!string.IsNullOrEmpty(uri.UserInfo))
                    {
                        capture.CaptureDetails.AddMetaData("URL_USER", uri.UserInfo);
                    }
                    capture.CaptureDetails.AddMetaData("URL_PORT", uri.Port.ToString());
                }

                // Only move the mouse to correct for the capture offset
                capture.MoveMouseLocation(-documentContainer.ViewportRectangle.X, -documentContainer.ViewportRectangle.Y);
                // Used to be: capture.MoveMouseLocation(-(capture.Location.X + documentContainer.CaptureOffset.X), -(capture.Location.Y + documentContainer.CaptureOffset.Y));
            } finally {
                // Always close the background form
                backgroundForm.CloseDialog();
            }
            return(capture);
        }