Exemplo n.º 1
0
        int IVsWindowPane.CreatePaneWindow(IntPtr hwndParent, int x, int y, int cx, int cy, out IntPtr hwnd)
        {
            if (InitializationMode != PaneInitializationMode.Uninitialized)
                throw new InvalidOperationException("The WindowPane is already initialized");

            // Indicate to derived classes that IVsWindowPane.CreatePaneWindow was used, and not IVsUIElementPane.CreateUIElementPane
            InitializationMode = PaneInitializationMode.IVsWindowPane;

            // We should call OnCreate one time for derived classes to pre-initialize themselves.
            // This should be called before accessing the Content or Window properties.
            OnCreate();

            hwnd = IntPtr.Zero;
            if (Content == null && Window == null)
                throw new InvalidOperationException("A WindowPane derived type must provide either a content control or a HWND.   If the tool is WPF based IVsUIElementPane.CreteUIElement should be used.");

            int hresult = NativeMethods.S_OK;
            if (Content != null)
            {
                // This path is unusual in that the content of this frame is WPF but it is being requested as an HWND through this
                // obsolete API.   Create a HwndSource wrapper around the FrameworkElement using the provided parent
                if (Content is FrameworkElement || Content is IVsUIWpfElement)
                {
                    // Create a HwndSource for the the content
                    HwndSource contentSource = new HwndSource(/* classStyle */ 0,
                        NativeMethods.WS_CHILD | NativeMethods.WS_CLIPSIBLINGS | NativeMethods.WS_VISIBLE,
                        /* exStyle */ 0,
                        /* x, y */ 0, 0,
                        /* name */ "",  // no name for this item.
                        hwndParent);

                    contentSource.SizeToContent = SizeToContent.Manual;
                    if (Content is IVsUIWpfElement)
                    {
                        object element = null;
                        ((IVsUIWpfElement)Content).CreateFrameworkElement(out element);
                        contentSource.RootVisual = (FrameworkElement)element;
                    }
                    else
                    {
                        contentSource.RootVisual = (FrameworkElement)Content;
                    }

                    contentSource.Disposed += delegate(object sender, EventArgs e)
                    {
                        this.Dispose();
                    };

                    hwnd = contentSource.Handle;
                }
                // If the content is already win32 and impliments the IVsUIWin32Element, we have little to do
                else if (Content is IVsUIWin32Element)
                {
                    hresult = ((IVsUIWin32Element)Content).Create(hwndParent, out hwnd);
                }
            }
            else if (Window != null)
            {
                // If our derived class provided a Win32 control, create it with the provided parent
                win32Wrapper = new UIWin32ElementWrapper(this);
                hresult = win32Wrapper.Create(hwndParent, out hwnd);
            }

            return hresult;
        }
Exemplo n.º 2
0
        /// <include file='doc\WindowPane.uex' path='docs/doc[@for="WindowPane.IVsUIElementPane.CreateUIElementPane"]/*' />
        /// <internalonly/>
        /// <devdoc>
        /// IVsUIElementPane implementation.
        /// </devdoc>
        int IVsUIElementPane.CreateUIElementPane(out object uiElement)
        {
            uiElement = null;

            if (InitializationMode != PaneInitializationMode.Uninitialized)
                throw new InvalidOperationException("The WindowPane is already initialized");

            // Indicate to derived classes that IVsUIElementPane.CreateUIElementPane was used, and not IVsWindowPane.CreatePaneWindow
            InitializationMode = PaneInitializationMode.IVsUIElementPane;

            // We should call OnCreate one time for derived classes to pre-initialize themselves.
            // This should be called before accessing the Content or Window properties.
            OnCreate();

            if (Content != null)
                uiElement = Content;
            else if (Window != null) {
                win32Wrapper = new UIWin32ElementWrapper(this);
                uiElement = win32Wrapper;
            }
            else
                return VSConstants.E_UNEXPECTED;

            return VSConstants.S_OK;
        }