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); }