protected sealed override void DestroyWindowOverride(HWND hwnd) { Debug.Assert(hwnd.DangerousGetHandle() == _hwndSource.Handle); _hwndSource.Dispose(); _hwndSource = null; }
protected sealed override HWND BuildWindowOverride(HWND hwndParent) { HwndSourceParameters hwndSourceParameters = new HwndSourceParameters { WindowStyle = (int)(WS.VISIBLE | WS.CHILD | WS.CLIPSIBLINGS | WS.CLIPCHILDREN), ParentWindow = hwndParent.DangerousGetHandle() }; _hwndSource = new HwndSource(hwndSourceParameters) { SizeToContent = SizeToContent.Manual }; // Set the root visual of the HwndSource to an instance of // HwndSourceHostRoot. Hook it up as a logical child if // we are on the same thread. HwndSourceHostRoot root = new HwndSourceHostRoot(); _hwndSource.RootVisual = root; root.OnMeasure += OnRootMeasured; AddLogicalChild(_hwndSource.RootVisual); SetRootVisual(Child); return(new HWND(_hwndSource.Handle)); }
protected sealed override HWND BuildWindowCore(HWND hwndParent) { HwndSourceParameters hwndSourceParameters = new HwndSourceParameters(); hwndSourceParameters.WindowStyle = (int)(WS.VISIBLE | WS.CHILD | WS.CLIPSIBLINGS | WS.CLIPCHILDREN); //hwndSourceParameters.ExtendedWindowStyle = (int)(WS_EX.NOACTIVATE); hwndSourceParameters.ParentWindow = hwndParent.DangerousGetHandle(); _hwndSource = new HwndSource(hwndSourceParameters); _hwndSource.SizeToContent = SizeToContent.Manual; // TODO: make this an option // On Vista, or when Win7 uses vista-blit, DX content is not // available via BitBlit or PrintWindow? If WPF is using hardware // acceleration, anything it renders won't be available either. // One workaround is to force WPF to use software rendering. Of // course, this is only a partial workaround since other content // like XNA or D2D won't work either. //_hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly; // Set the root visual of the HwndSource to an instance of // HwndSourceHostRoot. Hook it up as a logical child if // we are on the same thread. HwndSourceHostRoot root = new HwndSourceHostRoot(); _hwndSource.RootVisual = root; root.OnMeasure += OnRootMeasured; AddLogicalChild(_hwndSource.RootVisual); SetRootVisual(Child); return(new HWND(_hwndSource.Handle)); }
protected virtual void OnCurrentHwndSourceChanged(DependencyPropertyChangedEventArgs e) { Initialize(); // Unregister the old keyboard input site. IKeyboardInputSite keyboardInputSite = ((IKeyboardInputSink)this).KeyboardInputSite; if (keyboardInputSite != null) { ((IKeyboardInputSink)this).KeyboardInputSite = null; keyboardInputSite.Unregister(); } // Register the new keyboard input site with the containing // HwndSource. IKeyboardInputSink sink = CurrentHwndSource; if (sink != null) { ((IKeyboardInputSink)this).KeyboardInputSite = sink.RegisterKeyboardInputSink(this); } // Set the owner of the RedirectedWindow to our CurrentHwndSource. // This keeps the RedirectedWindow on top of the HwndSource. if (CurrentHwndSource != null) { HWND hwndSource = new HWND(CurrentHwndSource.Handle); HWND hwndRoot = hwndSource; // User32NativeMethods.GetAncestor(hwndSource, GA.ROOT); // need to get the top-level window? NativeMethods.SetWindowLongPtr( _redirectedWindow.Handle, GWL.HWNDPARENT, hwndRoot.DangerousGetHandle()); } }
public static StrongHWND CreateWindowEx(WS_EX dwExStyle, string lpClassName, string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam) { HWND hwnd = NativeMethods.CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); return(new StrongHWND(hwnd.DangerousGetHandle())); }
private static IntPtr GetIEWindow(WebBrowser webBrowser) { HWND hwndIeWindow = HWND.NULL; HWND hwndShellEmbeddingWindow = new HWND(webBrowser.Handle); if (hwndShellEmbeddingWindow != HWND.NULL) { HWND hwndShellDocObjectView = NativeMethods.GetWindow(hwndShellEmbeddingWindow, GW.CHILD); if (hwndShellDocObjectView != HWND.NULL) { hwndIeWindow = NativeMethods.GetWindow(hwndShellDocObjectView, GW.CHILD); } } return(hwndIeWindow.DangerousGetHandle()); }
private IntPtr SendData(Process sourceProcess, HWND destinationHandle, IEnumerable <string> data, char separator = '\t') { var lpData = data.Any() ? string.Join(separator, data) : string.Empty; var structure = new COPYDATASTRUCT { dwData = IntPtr.Zero, cbData = Encoding.UTF8.GetByteCount(lpData) + 1, lpData = lpData, }; var lParam = Marshal.AllocHGlobal(Marshal.SizeOf(structure)); Marshal.StructureToPtr(structure, lParam, false); var msg = User32.WindowMessage.WM_COPYDATA; this.Logger.Debug($"ウィンドウメッセージを送信します。: hWnd=0x{destinationHandle.DangerousGetHandle():X}, msg={msg}, data=[{string.Join(", ", data)}]"); return(User32.SendMessage(destinationHandle, (uint)msg, sourceProcess.Handle, lParam)); }
internal IntPtr WndProc(IntPtr hwnd, int message, IntPtr wParam, IntPtr lParam) { Debug.Assert(hwnd == _hwnd.DangerousGetHandle()); return(OnMessage((WM)message, wParam, lParam)); }