예제 #1
0
        private void OnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            WebBrowser browser = (sender as WebBrowser);

            if (browser != null)
            {
                mshtml.IHTMLDocument2 document = (browser.Document.DomDocument as mshtml.IHTMLDocument2);
                if (document != null)
                {
                    int width = browser.Document.Body.ScrollRectangle.Width;
                    int height = browser.Document.Body.ScrollRectangle.Height;
                    browser.Width = width;
                    browser.Height = height;

                    mshtml.IHTMLElement element = (document.body as mshtml.IHTMLElement);
                    if (element != null)
                    {

                        IViewObject viewObject = (document as IViewObject);
                        if (viewObject != null) {
                            using (Graphics graphics = this.CreateGraphics())
                            {
                                IntPtr hdcDestination = graphics.GetHdc();
                                IntPtr hdcMemory = GDI32.CreateCompatibleDC(hdcDestination);
                                IntPtr bitmap = GDI32.CreateCompatibleBitmap(hdcDestination, width, height);

                                IntPtr hOld = (IntPtr)GDI32.SelectObject(hdcMemory, bitmap);

                                RECTL rect = new RECTL();
                                rect.left = 0;
                                rect.top = 0;
                                rect.right = width;
                                rect.bottom = height;
                                viewObject.Draw(
                                        DVASPECT.DVASPECT_CONTENT,
                                        -1,
                                        IntPtr.Zero,
                                        IntPtr.Zero,
                                        IntPtr.Zero,
                                        hdcMemory,
                                        ref rect,
                                        ref rect,
                                        IntPtr.Zero,
                                        (uint) 0);

                                GDI32.SelectObject(hdcMemory, hOld);
                                GDI32.DeleteDC(hdcMemory);
                                graphics.ReleaseHdc(hdcDestination);

                                SaveThumbnail(Image.FromHbitmap(bitmap));
                            }
                        }
                    }
                }
            }

            this.Dispose();
        }
예제 #2
0
파일: TrackBarEx.cs 프로젝트: dgis/CodeTV
 protected Rectangle GetThumbRect()
 {
     RECTL rectl = new RECTL();
     IntPtr lParam = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RECTL)));
     Marshal.StructureToPtr(rectl, lParam, false);
     SendMessage(Handle, TBM_GETTHUMBRECT, 0, lParam.ToInt32());
     rectl = (RECTL)Marshal.PtrToStructure(lParam, typeof(RECTL));
     Rectangle result = new Rectangle(rectl.left, rectl.top, rectl.right - rectl.left, rectl.bottom - rectl.top);
     Marshal.FreeHGlobal(lParam);
     return result;
 }
예제 #3
0
        protected Rectangle GetThumbRect()
        {
            RECTL  rectl  = new RECTL();
            IntPtr lParam = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RECTL)));

            Marshal.StructureToPtr(rectl, lParam, false);
            SendMessage(Handle, TBM_GETTHUMBRECT, 0, lParam.ToInt32());
            rectl = (RECTL)Marshal.PtrToStructure(lParam, typeof(RECTL));
            Rectangle result = new Rectangle(rectl.left, rectl.top, rectl.right - rectl.left, rectl.bottom - rectl.top);

            Marshal.FreeHGlobal(lParam);
            return(result);
        }
예제 #4
0
    /// <summary>
    /// The web browser document completed event handler which creates the screenshot for
    /// the correct URL.
    /// </summary>
    /// <param name="sender">The sender.</param>
    /// <param name="e">The <see cref="WebBrowserDocumentCompletedEventArgs"/> instance containing the event data.</param>
    private static void WebBrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
      if (e.Url == newTargetUrl)
      {
        var localBrowser = (WebBrowser)sender;

        if (localBrowser.Document == null)
        {
          return;
        }

        try
        {
          // Reset window to default size
          Size scrollSize = Document.ActiveDocument.PresentationSize;
          
          // ! This line is critical to receive correct scroll sizes
          // in the next step
          localBrowser.ClientSize = Document.ActiveDocument.PresentationSize;

          // Get maximal sizes
          GetMaxScrollSizeOfDocument(localBrowser.Document, ref scrollSize);
          if (localBrowser.Document.Window != null)
          {
            GetLargestScrollSizeOfAllFrames(localBrowser.Document.Window.Frames, ref scrollSize);
          }

          // Now update the clientsize to full size, not screen size
          localBrowser.ClientSize = scrollSize;

          // create a bitmap object 
          var bitmap = new Bitmap(scrollSize.Width, scrollSize.Height);

          // get the viewobject of the WebBrowser to draw to bitmap
          var ivo = localBrowser.Document.DomDocument as IViewObject;

          using (Graphics g = Graphics.FromImage(bitmap))
          {
            // get the handle to the device context and draw
            IntPtr hdc = g.GetHdc();

            if (ivo != null)
            {
              // get the size of the document's body
              var docRectangle = new RECTL { top = 0, left = 0, right = scrollSize.Width, bottom = scrollSize.Height };

              ivo.Draw(
                DVASPECT.DVASPECT_CONTENT, 
                -1, 
                IntPtr.Zero, 
                IntPtr.Zero, 
                IntPtr.Zero, 
                hdc, 
                ref docRectangle, 
                ref docRectangle, 
                IntPtr.Zero, 
                0);
            }

            g.ReleaseHdc(hdc);
          }

          // Alternative to IViewObject, not allowed but works...
          //// localBrowser.DrawToBitmap(bitmap, new Rectangle(0, 0, scrollSize.Width, scrollSize.Height));
          
          string filename = Path.Combine(
            Document.ActiveDocument.ExperimentSettings.SlideResourcesPath, 
            newScreenshotFilename);
          bitmap.Save(filename, ImageFormat.Png);
          bitmap.Dispose();
        }
        catch (Exception ex)
        {
          ExceptionMethods.HandleException(ex);
        }
      }
    }
예제 #5
0
        /// <summary>
        /// The web browser document completed event handler which creates the screenshot for
        /// the correct URL.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="WebBrowserDocumentCompletedEventArgs"/> instance containing the event data.</param>
        private static void WebBrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (e.Url == newTargetUrl)
            {
                var localBrowser = (WebBrowser)sender;

                if (localBrowser.Document == null)
                {
                    return;
                }

                try
                {
                    // Reset window to default size
                    Size scrollSize = Document.ActiveDocument.PresentationSize;

                    // ! This line is critical to receive correct scroll sizes
                    // in the next step
                    localBrowser.ClientSize = Document.ActiveDocument.PresentationSize;

                    // Get maximal sizes
                    GetMaxScrollSizeOfDocument(localBrowser.Document, ref scrollSize);
                    if (localBrowser.Document.Window != null)
                    {
                        GetLargestScrollSizeOfAllFrames(localBrowser.Document.Window.Frames, ref scrollSize);
                    }

                    // Now update the clientsize to full size, not screen size
                    localBrowser.ClientSize = scrollSize;

                    // create a bitmap object
                    var bitmap = new Bitmap(scrollSize.Width, scrollSize.Height);

                    // get the viewobject of the WebBrowser to draw to bitmap
                    var ivo = localBrowser.Document.DomDocument as IViewObject;

                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        // get the handle to the device context and draw
                        IntPtr hdc = g.GetHdc();

                        if (ivo != null)
                        {
                            // get the size of the document's body
                            var docRectangle = new RECTL {
                                top = 0, left = 0, right = scrollSize.Width, bottom = scrollSize.Height
                            };

                            ivo.Draw(
                                DVASPECT.DVASPECT_CONTENT,
                                -1,
                                IntPtr.Zero,
                                IntPtr.Zero,
                                IntPtr.Zero,
                                hdc,
                                ref docRectangle,
                                ref docRectangle,
                                IntPtr.Zero,
                                0);
                        }

                        g.ReleaseHdc(hdc);
                    }

                    // Alternative to IViewObject, not allowed but works...
                    //// localBrowser.DrawToBitmap(bitmap, new Rectangle(0, 0, scrollSize.Width, scrollSize.Height));

                    string filename = Path.Combine(
                        Document.ActiveDocument.ExperimentSettings.SlideResourcesPath,
                        newScreenshotFilename);
                    bitmap.Save(filename, ImageFormat.Png);
                    bitmap.Dispose();
                }
                catch (Exception ex)
                {
                    ExceptionMethods.HandleException(ex);
                }
            }
        }
예제 #6
0
파일: VGFlash.cs 프로젝트: DeSciL/Ogama
    /// <summary>
    /// This method is the kernel of this class and draws the flash activeX
    /// com object surface in the current state to the given <see cref="Graphics"/>.
    /// </summary>
    /// <remarks>Note that the <see cref="IViewObject"/> is the key to
    /// provide us with a method to draw a com object on a graphics, without beeing visible itself.</remarks>
    /// <param name="graphics">The <see cref="Graphics"/> to draw to.</param>
    /// <param name="elementBounds">The <see cref="RectangleF"/> to draw into.</param>
    private void DrawFlashObject(Graphics graphics, RectangleF elementBounds)
    {
      // Sanity check
      if (this.flashControl == null)
      {
        return;
      }

      // Some painting calls can occur when this object is beeing disposed.
      if (this.disposing)
      {
        return;
      }

      // Transform size and location with the current transform
      PointF newSize = new PointF(elementBounds.Width, elementBounds.Height);

      PointF[] mousePts = { newSize, elementBounds.Location };
      this.currentTransform.TransformPoints(mousePts);
      Point scaledSize = Point.Round(mousePts[0]);
      Point scaledLocation = Point.Round(mousePts[1]);

      // Grab IViewObject interface from the ocx.  
      Tools.Interfaces.IViewObject viewObject =
        (Tools.Interfaces.IViewObject)this.flashControl.GetOcx();

      // Check for success
      if (viewObject == null)
      {
        return;
      }

      int hr = -1;

      // Set up RECTL structure
      RECTL bounds = new RECTL();
      bounds.left = scaledLocation.X;
      bounds.top = scaledLocation.Y;
      bounds.right = scaledLocation.X + scaledSize.X;
      bounds.bottom = scaledLocation.Y + scaledSize.Y;

      // get hdc
      IntPtr hdc = graphics.GetHdc();

      // Draw
      hr = viewObject.Draw(
        DVASPECT.DVASPECT_CONTENT,
        -1,
        IntPtr.Zero,
        IntPtr.Zero,
        IntPtr.Zero,
        hdc,
        ref bounds,
        ref bounds,
        IntPtr.Zero,
        (uint)0);

      // Release HDC
      graphics.ReleaseHdc(hdc);
    }
예제 #7
0
        /// <summary>
        /// This method is the kernel of this class and draws the flash activeX
        /// com object surface in the current state to the given <see cref="Graphics"/>.
        /// </summary>
        /// <remarks>Note that the <see cref="IViewObject"/> is the key to
        /// provide us with a method to draw a com object on a graphics, without beeing visible itself.</remarks>
        /// <param name="graphics">The <see cref="Graphics"/> to draw to.</param>
        /// <param name="elementBounds">The <see cref="RectangleF"/> to draw into.</param>
        private void DrawFlashObject(Graphics graphics, RectangleF elementBounds)
        {
            // Sanity check
            if (this.flashControl == null)
            {
                return;
            }

            // Some painting calls can occur when this object is beeing disposed.
            if (this.disposing)
            {
                return;
            }

            // Transform size and location with the current transform
            PointF newSize = new PointF(elementBounds.Width, elementBounds.Height);

            PointF[] mousePts = { newSize, elementBounds.Location };
            this.currentTransform.TransformPoints(mousePts);
            Point scaledSize     = Point.Round(mousePts[0]);
            Point scaledLocation = Point.Round(mousePts[1]);

            // Grab IViewObject interface from the ocx.
            Tools.Interfaces.IViewObject viewObject =
                (Tools.Interfaces.IViewObject) this.flashControl.GetOcx();

            // Check for success
            if (viewObject == null)
            {
                return;
            }

            int hr = -1;

            // Set up RECTL structure
            RECTL bounds = new RECTL();

            bounds.left   = scaledLocation.X;
            bounds.top    = scaledLocation.Y;
            bounds.right  = scaledLocation.X + scaledSize.X;
            bounds.bottom = scaledLocation.Y + scaledSize.Y;

            // get hdc
            IntPtr hdc = graphics.GetHdc();

            // Draw
            hr = viewObject.Draw(
                DVASPECT.DVASPECT_CONTENT,
                -1,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero,
                hdc,
                ref bounds,
                ref bounds,
                IntPtr.Zero,
                (uint)0);

            // Release HDC
            graphics.ReleaseHdc(hdc);
        }
예제 #8
0
 static private string RECTLToString(RECTL rectL)
 {
     return("L: " + rectL.left + " T: " + rectL.top + " R: " + rectL.right + " B: " + rectL.bottom);
 }