public OpenFileDialogCreationListener( IWin32Window parent )
 {
     _subClasser = new WindowSubClasser(parent, new WndProcDelegate(WndProc));
     _subClasser.Install();
 }
Пример #2
0
        /// <summary>
        /// Initialize MSHTML by creating a new MSHTML instance, running it, and
        /// in-place activating it. The call to IOleObject.DoVerb will result in
        /// a call to our IOleDocumentSite.ActivateMe method where we will conclude
        /// the initialization sequence.
        ///
        /// This method is based on the CFramerDocument::CreateNewDocObject method
        /// from the FramerEx sample (referenced above in the class comment).
        /// Differences in our implementation include the fact that we don't use
        /// IPersistStorage or IPersistFile to load  the contents of the document,
        /// we don't call IOleObject.SetHostNames, and we don't call IOleObject.Advise
        /// to set up an IAdviseSink (not necessary since we don't need notifications
        /// of changes to the data or view).
        /// </summary>
        private void InitializeMSHTML()
        {
            // Create the html document
            htmlDocument = (IHTMLDocument2)new HTMLDocumentClass();

            // Query for its IOleObject interface (core OLE embedded object interface)
            oleObject = (IOleObject)htmlDocument;

            // Put the compound document object into the running state
            int result = Ole32.OleRun(oleObject);
            if (result != HRESULT.S_OK)
                Marshal.ThrowExceptionForHR(result);

            // Inform the embedded object of its "client-site" (i.e. container)
            oleObject.SetClientSite((IOleClientSite)(this));

            // Lock the OleObject into it's running state (we will unlock it during Dispose)
            result = Ole32.OleLockRunning(oleObject, true, false);
            if (result != HRESULT.S_OK)
                Marshal.ThrowExceptionForHR(result);

            // Get the boundaries of the container
            RECT containerRect;
            GetContainerRect(out containerRect);

            // In-Place Activate the MSHTML ActiveDocument (will result in a call to
            // IOleDocumentSite.ActivateMe where initialization will continue)
            result = oleObject.DoVerb(
                OLEIVERB.INPLACEACTIVATE,	// request in-place activation
                IntPtr.Zero,				// MSG for event that invoked the verb (none)
                (IOleClientSite)(this),		// client site for activation
                0,							// reserved (must be 0)
                this.Handle,				// parent-window for active object
                ref containerRect);		// bounding rectangle in parent window

            // check for DoVerb error
            if (result != HRESULT.S_OK)
                Marshal.ThrowExceptionForHR(result);

            // hookup to document events
            documentEventRepeater = new HtmlDocumentEventRepeater(htmlDocument);

            // If FindForm() is null, this editor is not hosted in a
            // managed window, thus, we must subclass the window to wait for
            // control key press to push through to PreProcessMessage
            // that would normally come through the managed message pump
            if (FindForm() == null)
            {
                NativeWindow nw = new NativeWindow();
                nw.AssignHandle(MshtmlWindowHandle);
                windowSubClasser = new WindowSubClasser(nw, new WndProcDelegate(WndProcDelegate));
                windowSubClasser.Install();
            }
        }