Пример #1
0
        private void Initialize()
        {
            if (Handle != null)
            {
                // Already initialized.
                return;
            }

            // When loaded for the first time, build the top-level redirected
            // window to host the child window.
            WindowParameters windowParams = new WindowParameters();

            windowParams.Name          = "RedirectedHwndHost";
            windowParams.Style         = WS.OVERLAPPED | WS.CLIPCHILDREN | WS.CAPTION;
            windowParams.ExtendedStyle = WS_EX.LAYERED | WS_EX.NOACTIVATE | WS_EX.TOOLWINDOW | WS_EX.TRANSPARENT;
            windowParams.WindowRect    = new Int32Rect(0, 0, 500, 500);

            _redirectedWindow = _redirectionWindowFactory.CreateWindow(windowParams);
            UpdateRedirectedWindowSettings(RedirectionVisibility, false);

            // Then create the child window to host.
            Handle = BuildWindowCore(_redirectedWindow.Handle);
            if (Handle == null || Handle.IsInvalid)
            {
                throw new InvalidOperationException("BuildWindowCore did not return a valid handle.");
            }

            _redirectedWindow.Show(WindowShowState.Normal, false);
        }
Пример #2
0
        public TWindow CreateWindow(WindowParameters windowParams)
        {
            GCHandle gcHandle      = new GCHandle();
            IntPtr   lpCreateParam = IntPtr.Zero;

            if (windowParams.Tag != null)
            {
                gcHandle      = GCHandle.Alloc(windowParams.Tag);
                lpCreateParam = GCHandle.ToIntPtr(gcHandle);
            }

            StrongHWND hwnd = StrongHWND.CreateWindowEx(
                windowParams.ExtendedStyle,
                Name,
                windowParams.Name,
                windowParams.Style,
                windowParams.WindowRect.X,
                windowParams.WindowRect.Y,
                windowParams.WindowRect.Width,
                windowParams.WindowRect.Height,
                windowParams.Parent,
                IntPtr.Zero,
                Marshal.GetHINSTANCE(typeof(TWindow).Module),
                lpCreateParam);

            TWindow createdWindow = null;

            if (!hwnd.IsInvalid)
            {
                Debug.Assert(_createdWindow != null);
                _createdWindow.TransferHandleOwnership(hwnd);

                createdWindow = _createdWindow;
            }

            _createdWindow = null;
            return(createdWindow);
        }
        private void Initialize()
        {
            if (Handle != null) {
                // Already initialized.
                return;
            }

            // When loaded for the first time, build the top-level redirected
            // window to host the child window.
            WindowParameters windowParams = new WindowParameters();
            windowParams.Name = "RedirectedHwndHost";
            windowParams.Style = WS.OVERLAPPED | WS.CLIPCHILDREN | WS.CAPTION;
            windowParams.ExtendedStyle = WS_EX.LAYERED | WS_EX.NOACTIVATE | WS_EX.TOOLWINDOW | WS_EX.TRANSPARENT;
            windowParams.WindowRect = new Int32Rect(0, 0, 500, 500);

            _redirectedWindow = _redirectionWindowFactory.CreateWindow(windowParams);
            UpdateRedirectedWindowSettings(RedirectionVisibility, false);

            // Then create the child window to host.
            Handle = BuildWindowCore(_redirectedWindow.Handle);
            if (Handle == null || Handle.IsInvalid) {
                throw new InvalidOperationException("BuildWindowCore did not return a valid handle.");
            }

            _redirectedWindow.Show(WindowShowState.Normal, false);
        }