예제 #1
0
 public void SetParameters(IHTMLElement _elem, tagRECT _rect, int _elemcorner)
 {
     Element = _elem;
     ElemRect = _rect;
     ElemCorner = (ELEMENT_CORNER)_elemcorner;
 }
예제 #2
0
 public static extern bool GetClientRect(IntPtr hWnd, out tagRECT lpRect);
예제 #3
0
 public static extern bool CopyRect(
     [In, Out, MarshalAs(UnmanagedType.Struct)] ref tagRECT lprcDst,
     [In, MarshalAs(UnmanagedType.Struct)] ref tagRECT lprcSrc);
예제 #4
0
 int IDocHostUIHandler.ResizeBorder(ref tagRECT rect, IOleInPlaceUIWindow doc, bool fFrameWindow)
 {
     return Hresults.E_NOTIMPL;
 }
예제 #5
0
 public static extern void SendMessage(HandleRef hWnd, uint msg,
                                       IntPtr wParam, ref tagRECT lParam);
예제 #6
0
 int IOleInPlaceSite.GetWindowContext(out IOleInPlaceFrame ppFrame, out IOleInPlaceUIWindow ppDoc, ref tagRECT lprcPosRect, ref tagRECT lprcClipRect, ref tagOIFI lpFrameInfo)
 {
     ppDoc = null;
     ppFrame = null;
     return Hresults.E_NOTIMPL;
 }
예제 #7
0
 int IOleInPlaceSite.OnPosRectChange(ref tagRECT lprcPosRect)
 {
     return Hresults.E_NOTIMPL;
 }
예제 #8
0
        public void SaveBrowserImage(string sFileName, 
            System.Drawing.Imaging.PixelFormat pixFormat,
            System.Drawing.Imaging.ImageFormat format)
        {
            if (m_WBWebBrowser2 == null)
                return;
            Bitmap bmp = null;
            try
            {
                //Get doc2, doc3, and viewobject
                IHTMLDocument2 pDoc2 = m_WBWebBrowser2.Document as IHTMLDocument2;
                if (pDoc2 == null) return;
                IHTMLDocument3 pDoc3 = m_WBWebBrowser2.Document as IHTMLDocument3;
                if (pDoc3 == null) return;
                IViewObject pViewObject = pDoc2 as IViewObject;
                if (pViewObject == null) return;

                IHTMLBodyElement pBody = null;
                IHTMLElement pElem = null;
                IHTMLElement2 pBodyElem = null;
                IHTMLStyle pStyle = null;
                string strStyle;
                int bodyHeight = 0;
                int bodyWidth = 0;
                int rootHeight = 0;
                int rootWidth = 0;
                int height = 0;
                int width = 0;

                //get the IHtmlelement
                pElem = pDoc2.body;

                //Get the IHTMLStyle
                if(pElem != null)
                    pStyle = pElem.style;

                //Get the borderstyle so we can reset it
                strStyle = pStyle.borderStyle;
                //Hide 3D border
                pStyle.borderStyle = "none";
                pBody = pElem as IHTMLBodyElement;
                //No scrollbars
                if(pBody != null)
                    pBody.scroll = "no";

                //Get root scroll h + w
                //QI for IHTMLElement2
                pBodyElem = pElem as IHTMLElement2;
                if (pBodyElem != null)
                {
                    bodyWidth = pBodyElem.scrollWidth;
                    bodyHeight = pBodyElem.scrollHeight;
                }

                //release
                pElem = null;
                pBodyElem = null;
                //Get docelem
                pElem = pDoc3.documentElement;
                //QI for IHTMLElement2
                if (pElem != null)
                {
                    pBodyElem = pElem as IHTMLElement2;
                    //Get scroll H + W
                    if (pBodyElem != null)
                    {
                        rootWidth = pBodyElem.scrollWidth;
                        rootHeight = pBodyElem.scrollHeight;
                    }
                    //calc actual W + H
                    width = rootWidth > bodyWidth ? rootWidth : bodyWidth;
                    height = rootHeight > bodyHeight ? rootHeight : bodyHeight;
                }
                //Set up a rect
                tagRECT rWPos = new tagRECT(0, 0, width, height);

                //Size browser
                if (m_WBOleInPlaceObject != null)
                    m_WBOleInPlaceObject.SetObjectRects(ref rWPos, ref rWPos);

                //Create bmp
                bmp = new Bitmap(width, height, pixFormat);

                //draw
                int hr = Hresults.S_FALSE;
                using (Graphics gr = Graphics.FromImage(bmp))
                {
                    //get hdc
                    IntPtr hdc = gr.GetHdc();
                    hr = pViewObject.Draw(
                        (uint)DVASPECT.DVASPECT_CONTENT,
                        (int)-1, m_NullPointer, m_NullPointer,
                        m_NullPointer, hdc, ref rWPos, ref rWPos,
                        m_NullPointer, (uint)0);
                    gr.ReleaseHdc(hdc);
                }

                //reset
                this.SetLocation();
                if (!string.IsNullOrEmpty(strStyle))
                    pStyle.borderStyle = strStyle;
                if(pBody != null)
                    pBody.scroll = "auto";

                if (hr == Hresults.S_OK)
                {
                    //save
                    bmp.Save(sFileName, format);
                }
                bmp.Dispose();
                bmp = null;
            }
            finally
            {
                if (bmp != null)
                    bmp.Dispose();
            }
        }
예제 #9
0
        /// <summary>
        /// Create Webbrowser control and set up it's events
        /// called from OnHandleCreated
        /// Webbrowser control hosting requires an HWND
        /// </summary>
        /// <returns></returns>
        private void InternalCreateWB()
        {
            //Create a new WB, throws exception if fails
            Type webbrowsertype = Type.GetTypeFromCLSID(Iid_Clsids.CLSID_WebBrowser, true);
            //Using Activator inplace of CoCreateInstance, returns IUnknown
            m_WBUnknown = System.Activator.CreateInstance(webbrowsertype);

            //Get the IOleObject
            m_WBOleObject = (IOleObject)m_WBUnknown;
            //Set client site
            int iret = m_WBOleObject.SetClientSite(this);
            //Set hostnames
            iret = m_WBOleObject.SetHostNames("csEXWB", string.Empty);

            //Get client rect
            bool brect = WinApis.GetClientRect(this.Handle, out m_WBRect);
            //Setup H+W
            m_WBRect.Right = m_WBRect.Right - m_WBRect.Left; //W
            m_WBRect.Bottom = m_WBRect.Bottom - m_WBRect.Top; //H
            m_WBRect.Left = 0;
            m_WBRect.Top = 0;

            //Get the IOleInPlaceObject
            m_WBOleInPlaceObject = (IOleInPlaceObject)m_WBUnknown;
            tagRECT trect = new tagRECT();
            WinApis.CopyRect(ref trect, ref m_WBRect);
            //Set WB rects
            iret = m_WBOleInPlaceObject.SetObjectRects(ref m_WBRect, ref trect);

            //INPLACEACTIVATE the WB
            iret = m_WBOleObject.DoVerb((int)OLEDOVERB.OLEIVERB_INPLACEACTIVATE, ref m_NullMsg, this, 0, this.Handle, ref m_WBRect);

            //Get the IWebBrowser2
            m_WBWebBrowser2 = (IWebBrowser2)m_WBUnknown;

            //By default, we handle dragdrops
            m_WBWebBrowser2.RegisterAsDropTarget = false;
            if (!DesignMode)
            {
                //Get connectionpointcontainer
                IConnectionPointContainer cpCont = (IConnectionPointContainer)m_WBUnknown;
                //Find connection point
                Guid guid = typeof(DWebBrowserEvents2).GUID;
                IConnectionPoint m_WBConnectionPoint = null;
                cpCont.FindConnectionPoint(ref guid, out m_WBConnectionPoint);
                //Advice
                m_WBConnectionPoint.Advise(this, out m_dwCookie);

                //Get the IOleComandTarget
                m_WBOleCommandTarget = (IOleCommandTarget)m_WBUnknown;

                //Reguster clipborad format for internal drag drop
                //RegisterClipboardFormatsForDragDrop();
            }

            if (!string.IsNullOrEmpty(m_sUrl))
                this.Navigate(m_sUrl);
            else
                this.Navigate("about:blank");

            //Get the shell embedding, ...
            WBIEServerHandle();
        }
예제 #10
0
 public static extern bool GetClientRect(IntPtr hWnd, out tagRECT lpRect);
예제 #11
0
 public static extern void SendMessage(HandleRef hWnd, uint msg,
     IntPtr wParam, ref tagRECT lParam);
예제 #12
0
 int IHTMLEditHost.SnapRect(IHTMLElement pIElement, ref tagRECT prcNew, int eHandle)
 {
     if (HTMLEditHostSnapRect != null)
     {
         HTMLEditHostSnapRectEvent.SetParameters(pIElement, prcNew, eHandle);
         HTMLEditHostSnapRect(this, HTMLEditHostSnapRectEvent);
         //if things changed
         prcNew = HTMLEditHostSnapRectEvent.ElemRect;
     }
     return Hresults.S_OK;
 }