//============================================================================= /// <summary> /// Called when the pane is initialised. /// </summary> /// <param name="ParentWindow">The HWND of the parent window, that this pane will map on to.</param> /// <param name="Width">The starting width of the pane.</param> /// <param name="Height">The starting height of the pane.</param> public void initialise_pane(int ParentWindow, int Width, int Height) { // Build the parameters required for the HwndSource object HwndSourceParameters sourceParams = new HwndSourceParameters("PowerMILLPlugin"); sourceParams.PositionX = 0; sourceParams.PositionY = 0; sourceParams.Height = Height; sourceParams.Width = Width; sourceParams.ParentWindow = new IntPtr(ParentWindow); sourceParams.WindowStyle = 0x10000000 | 0x40000000; // WS_VISIBLE | WS_CHILD; // Create the HwndSource object m_hwnd_source = new HwndSource(sourceParams); // Set the root visual m_hwnd_source.RootVisual = m_root_element; // Set the size of the Hwnd m_hwnd_source.SizeToContent = SizeToContent.WidthAndHeight; // Set the size of the control m_root_element.Width = Width; m_root_element.Height = Height; // Add a message hook - this is a workaround so hear about WM_CHAR messages m_hwnd_source.AddHook(child_hwnd_source_hook); }
public NativeHandleAddInAdapter(FrameworkElement root, ContractHandle adapter, string name = null) { Debug.Assert(null != root); Debug.Assert(null != adapter); Debug.Assert(adapter.Contract is IObserverContract); root.VerifyAccess(); observer = adapter; var parameters = new HwndSourceParameters(name ?? "AddInWindow") { ParentWindow = new IntPtr(-3), WindowStyle = 0x40000000 }; hwndSource = new HwndSource(parameters) { RootVisual = root, SizeToContent = SizeToContent.Manual }; if (hwndSource.CompositionTarget != null) { hwndSource.CompositionTarget.BackgroundColor = Colors.White; } hwndSource.AddHook(HwndSourceHook); CommandManager.AddCanExecuteHandler(root, CanExecuteRoutedEventHandler); CommandManager.AddExecutedHandler(root, ExecuteRoutedEventHandler); // TODO: Refactoring Debug.WriteLine("--\t\t\t\t\t\t\t Handle: {0}\t--\tWindow: {1}", hwndSource.Handle.ToString("x8"), parameters.WindowName); }
private void InitHwndSource() { if (m_hwndSource != null) { return; } int classStyle = 0; int style = 0; int styleEx = Win32.WS_EX_NOACTIVATE; HwndSourceParameters parameters = new HwndSourceParameters() { UsesPerPixelOpacity = true, WindowClassStyle = classStyle, WindowStyle = style, ExtendedWindowStyle = styleEx, PositionX = (int)(m_parentBoundingBox.X + m_boundingBox.X), PositionY = (int)(m_parentBoundingBox.Y + m_boundingBox.Y), Width = (int)(m_boundingBox.Width), Height = (int)(m_boundingBox.Height) }; m_hwndSource = new HwndSource(parameters); m_hwndSource.RootVisual = m_hwndAdornmentRoot; m_hwndSource.AddHook(WndProc); m_shown = false; }
public override Task <WpfReply> GetUserControl1(WpfRequest request, ServerCallContext context) { try { var p = new HwndSourceParameters("UserControl1") { ParentWindow = new IntPtr(-3), WindowStyle = 1073741824 }; var hwndSource = App.Current.Dispatcher.Invoke(() => { var source = new HwndSource(p); source.RootVisual = new UserControl1() { Height = 300, Width = 500 }; source.CompositionTarget.BackgroundColor = Colors.White; source.SizeToContent = SizeToContent.Manual; return(source); }); return(Task.FromResult(new WpfReply { Handle = hwndSource.Handle.ToInt32() })); } catch (Exception e) { Debug.WriteLine(e); } return(Task.FromResult(new WpfReply())); }
public void ShowPreview(int previewHandle, string rootVisualPropertyName) { V preview = this.CreateWindow(System.Windows.Forms.Screen.PrimaryScreen, true); IntPtr previewPointer = new IntPtr(previewHandle); Interop.Rectangle clientRectange = new Interop.Rectangle(); bool result = Interop.Win32Api.GetClientRect(previewPointer, ref clientRectange); HwndSourceParameters sourceParams = new HwndSourceParameters("sourceParams"); sourceParams.PositionX = 0; sourceParams.PositionY = 0; sourceParams.Height = clientRectange.Bottom - clientRectange.Top; sourceParams.Width = clientRectange.Right - clientRectange.Left; sourceParams.ParentWindow = previewPointer; sourceParams.WindowStyle = (int)(Interop.WindowStyles.WindowStyleVisible | Interop.WindowStyles.WindowStyleChild | Interop.WindowStyles.WindowStyleClipChildren); try { // at this point a window with the specified handle may no longer exist, so we wrap this in a try-catch this.hostWindow = new HwndSource(sourceParams); } catch (Exception) { return; } this.hostWindow.Disposed += OnHostWindowDisposed; this.hostWindow.RootVisual = (Visual)preview.FindName(rootVisualPropertyName); }
/// <summary> /// Previews the screensaver in screen saver small window. /// For that the window handle is needed and set to this. /// </summary> /// <param name="e">StartupEventArgs</param> private void PreviewScreensaver(StartupEventArgs e) { // Gets windows' handle for screensaver preview window. Int32 previewInt32 = Convert.ToInt32(e.Args[1]); IntPtr previewHandle = new IntPtr(previewInt32); // Receives window size via RECT and Win32API. RECT lpRect = new RECT(); Win32API.GetClientRect(previewHandle, ref lpRect); previewClockWindow = new PreviewWindow(lpRect.Right, lpRect.Bottom, previewHandle); HwndSourceParameters sourceParams = new HwndSourceParameters("sourceParams") { // Defines source parameters. PositionX = 0, PositionY = 0, Height = lpRect.Bottom - lpRect.Top, Width = lpRect.Right - lpRect.Left, ParentWindow = previewHandle, WindowStyle = (int)(WindowStyles.WS_VISIBLE | WindowStyles.WS_CHILD | WindowStyles.WS_CLIPCHILDREN) }; // Transmits pictures to screensaver window of windows. winWPFContent = new HwndSource(sourceParams); winWPFContent.Disposed += new EventHandler(WinWPFContent_Disposed); winWPFContent.RootVisual = previewClockWindow.clockBorder; previewClockWindow.Show(); }
private static HwndSource CreateHwndSource(HwndSourceParameters?optCreationParameters, IntPtr hwndParent) { HwndSourceParameters creationParameters = new HwndSourceParameters(); if (optCreationParameters.HasValue) { creationParameters = optCreationParameters.Value; } // In all cases, the HwndSource parameters are adjusted so that: // 1) it is forced to be a child window // 2) it is forced to have our child window as its parent // 3) it is forced to clip children and siblings creationParameters.WindowStyle |= WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE; creationParameters.ParentWindow = hwndParent; HwndSource hwndSource = new HwndSource(creationParameters); // The size of the HwndSource window is enforced to be the // size of the parent window. hwndSource.SizeToContent = SizeToContent.Manual; //hwndSource.AddHook(new HwndSourceHook(HwndSourceWndProcHook)); return(hwndSource); }
protected override HandleRef BuildWindowCore(HandleRef hwndParent) { HwndSourceParameters hwndSourceParameter = new HwndSourceParameters() { ParentWindow = hwndParent.Handle, WindowStyle = 1442840576, Width = 1, Height = 1 }; this._wpfContentHost = new HwndSource(hwndSourceParameter); this._rootPresenter = new Border() { Child = new AdornerDecorator() { Child = this.Content }, Focusable = true }; this._rootPresenter.SetBinding(Border.BackgroundProperty, new Binding("Background") { Source = this._owner }); this._wpfContentHost.RootVisual = this._rootPresenter; this._wpfContentHost.SizeToContent = System.Windows.SizeToContent.Manual; this._manager = this._owner.Model.Root.Manager; this._manager.InternalAddLogicalChild(this._rootPresenter); return(new HandleRef(this, this._wpfContentHost.Handle)); }
/// <summary> /// Внедряет представление в докируемую панель /// </summary> /// <param name="view">Тип представления</param> /// <param name="caption">Заголовок окна</param> /// <param name="style">Стиль окна</param> /// <returns></returns> public IControlBar Create(FrameworkElement view, string caption, int style) { try { IControlBar controlBar = _controlBarHandler.Invoke(caption, style); HwndSourceParameters pars = new HwndSourceParameters { WindowStyle = WS_CHILD | WS_VISIBLE, PositionX = 0, PositionY = 0, ParentWindow = (IntPtr)controlBar.hWnd }; HwndSource source = new HwndSource(pars) { RootVisual = view, SizeToContent = SizeToContent.WidthAndHeight }; source.AddHook(ChildHwndSourceHook); controlBar.EmbedWindow(source.Handle.ToInt32()); return(controlBar); } catch (Exception) { throw; } }
public MainWindow(IntPtr previewWndHandle) : this() { Top = Left = -9999; try { RECT lpRect; GetClientRect(previewWndHandle, out lpRect); //dockPanel.Width = 228; // lpRect.right - lpRect.left; //dockPanel.Height = 168; // lpRect.bottom - lpRect.top; HwndSourceParameters sourceParams = new HwndSourceParameters("sourceParams") { PositionX = 0, PositionY = 0, Height = lpRect.bottom - lpRect.top, Width = lpRect.right - lpRect.left, ParentWindow = previewWndHandle, WindowStyle = (int)(WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN) }; _winWPFContent = new HwndSource(sourceParams); _winWPFContent.Disposed += new EventHandler(_winWPFContent_Disposed); _winWPFContent.RootVisual = dockPanel; } catch (Exception ex) { MessageBox.Show(ex.Message); } _previewMode = true; }
private static void LaunchPreviewWinodw(int previewHandle, AppConfiguration config) { var pPreviewHnd = new IntPtr(previewHandle); var lpRect = new NativeMethods.Rect(); if (NativeMethods.GetClientRect(pPreviewHnd, ref lpRect)) { var sourceParams = new HwndSourceParameters(name: "sourceParams") { PositionX = 0, PositionY = 0, Height = lpRect.Bottom - lpRect.Top, Width = lpRect.Right - lpRect.Left, ParentWindow = pPreviewHnd, WindowStyle = (int)( NativeMethods.WindowStyles.WS_VISIBLE | NativeMethods.WindowStyles.WS_CHILD | NativeMethods.WindowStyles.WS_CLIPCHILDREN) }; var previewWindowContainer = new HwndSource(sourceParams); var previewWindow = new MainWindow { IsPreviewMode = true }; previewWindow.InitializeConfig(config.Windows[0], config.SharedWindowConfig, config.SharedPanelConfig); previewWindowContainer.RootVisual = (Visual)previewWindow.Content; previewWindowContainer.Disposed += delegate { previewWindow.Close(); }; } }
private void CreateHwndSource(IntPtr handle) { var rect = GetContainerArea(handle); var hwndSourceParameters = new HwndSourceParameters() { ParentWindow = handle, AcquireHwndFocusInMenuMode = false, PositionX = rect.Left, PositionY = rect.Top, Width = rect.Width, Height = rect.Height, WindowStyle = -2113929216, ExtendedWindowStyle = 524292 | Win32NativeMethods.WS_EX_TRANSPARENT, UsesPerPixelOpacity = true, WindowName = FrameName, }; var hwndSource = new HwndSource(hwndSourceParameters) { RootVisual = this }; var tableAbove = Win32NativeMethods.GetWindow(handle, (uint)GetWindowConsts.GW_HWNDPREV); Win32NativeMethods.SetWindowPos(hwndSource.Handle, tableAbove, 0, 0, 0, 0, (uint)SetWindowPosConsts.SWP_SHOWWINDOW | (uint)SetWindowPosConsts.SWP_NOACTIVATE | (uint)SetWindowPosConsts.SWP_NOMOVE | (uint)SetWindowPosConsts.SWP_NOSIZE); _hwndSource = hwndSource; }
// Create HwndSource // Set SizeToContent to SizeToContent.Width, add RootVisual, and call SetWindowPos // Set SizeToContent to SizeToContent.Height, call SetWindowPos // Resize RootVisual, set SizeToContent to SizeToContent.WidthAndHeight, and call SetWindowPos private void RunTest() { _dispatcher = Dispatcher.CurrentDispatcher; Console.WriteLine("Testing HwndSource SizeToContent behavior"); HwndSourceParameters param = new HwndSourceParameters("DrtHwndSource", 100, 100); param.SetPosition(0, 0); if (!DRT.KeepAlive) { _source = new HwndSource(param); _source.ContentRendered += new EventHandler(OnContentRendered); _source.AddHook(new HwndSourceHook(ApplicationFilterMessage)); _dispatcher.BeginInvoke( DispatcherPriority.Background, new DispatcherOperationCallback(SetAutoWidth), null); } else // 'hold' was passed in on the command line - don't finish this suite { _source = new HwndSource(param); _source.AddHook(new HwndSourceHook(ApplicationFilterMessage)); } DRT.Suspend(); }
// This method handles the situation where the PresentationSource that // contains this OldSchoolMdiChild instance changes. This will happen // the first time, and possibly if someone programatically removes it // and inserts it somewhere else. private void OnPresentationSourceChanged(object sender, SourceChangedEventArgs e) { // Destroy our PresentationSource children when we are disconnected. if (e.OldSource != null) { if (_hwndSourceChild != null && !_hwndSourceChild.IsDisposed) { _hwndSourceChild.RootVisual = null; _hwndSourceChild.Dispose(); _hwndSourceChild = null; } } // Create our PresentationSource children when we are connected. HwndSource newSource = e.NewSource as HwndSource; if (newSource != null) { var p = new HwndSourceParameters("MiddleChild", 200, 100); p.WindowClassStyle = 0; p.WindowStyle = WS_OVERLAPPEDWINDOW | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; p.ExtendedWindowStyle = 0; p.ParentWindow = newSource.Handle; p.HwndSourceHook = ChildHook; _hwndSourceChild = new HwndSource(p); _hwndSourceChild.RootVisual = Child; // Show the window for the first time normally. ShowWindow(_hwndSourceChild.Handle, SW_SHOWNORMAL); // First time SetWindowPos(_hwndSourceChild.Handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); } }
private HwndSource CreateBackgroundWindow() { HwndSource presentationSource = PresentationSource.FromVisual(Application.Current.MainWindow) as HwndSource; IntPtr zero = IntPtr.Zero; if (presentationSource != null) { zero = presentationSource.Handle; } //WS_EX_TOPMOST = 0x00000008,WS_CHILDWINDOW = 0x40000000, WS_EX_NOACTIVATE = 0x08000000, //WS_EX_LAYERED = 0x00080000,WS_EX_TRANSPARENT = 0x00000020, int num = 0; int num2 = 0x4000000; int num3 = 0x80000 | 0x20 | 0x00000008 | 0x08000000; //0x8000080;WS_EX_TRANSPARENT | WS_EX_LAYERED HwndSourceParameters parameters = new HwndSourceParameters() { WindowClassStyle = num, WindowStyle = num2, ExtendedWindowStyle = num3 }; parameters.SetPosition(0, 0); parameters.UsesPerPixelOpacity = true; //transparent; if ((zero != IntPtr.Zero)) { //parameters.ParentWindow = zero; } HwndSource source2 = new HwndSource(parameters); source2.RootVisual = this; return(source2); }
private void ShowPreview(IntPtr previewHwnd) { var mediaElementController = new PrimayScreenOnlyController(_movieManager, 1); var window = new ScreenSaverWindow(mediaElementController, 0); mediaElementController.Start(); var lpRect = new RECT(); var bGetRect = Win32API.GetClientRect(previewHwnd, ref lpRect); Debug.Assert(bGetRect); var sourceParams = new HwndSourceParameters("sourceParams") { PositionX = 0, PositionY = 0, Height = lpRect.Bottom - lpRect.Top, Width = lpRect.Right - lpRect.Left, ParentWindow = previewHwnd, WindowStyle = (int)(WindowStyles.WS_VISIBLE | WindowStyles.WS_CHILD | WindowStyles.WS_CLIPCHILDREN) }; _winWpfContent = new HwndSource(sourceParams); _winWpfContent.Disposed += (_, __) => window.Close(); _winWpfContent.RootVisual = (Visual)window.Content; UpdateManager.Instance.CheckForUpdatesAsync(); }
void CreateHwnd() { if (hwnd != null) { return; } int classStyle = 0; int style = (int)Win32.WS_CLIPCHILDREN; int styleEx = Win32.WS_EX_NOACTIVATE; HwndSourceParameters parameters = new HwndSourceParameters() { UsesPerPixelOpacity = true, WindowClassStyle = classStyle, WindowStyle = style, ExtendedWindowStyle = styleEx, PositionX = (int)(parentBounds.X + bounds.X), PositionY = (int)(parentBounds.Y + bounds.Y), Width = (int)(bounds.Width), Height = (int)(bounds.Height) }; hwnd = new HwndSource(parameters); hwnd.RootVisual = visualRoot; hwnd.AddHook(WndProc); isShown = false; }
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)); }
/// <summary/> protected override object CreateWindow(object o) { // HwndSource windows do not automatically adjust for DPI. // Change the values parsed to reflect what the Avalon window class would do for us automatically. int w = (int)MathEx.ConvertToAbsolutePixelsX(WindowWidth); int h = (int)MathEx.ConvertToAbsolutePixelsY(WindowHeight); HwndSourceParameters parameters = new HwndSourceParameters("Rendering Window", w, h); parameters.WindowStyle = unchecked ((int)0x90000000); parameters.ExtendedWindowStyle = unchecked ((int)0x8); if (IsWindowPositionValid) { Point p = MathEx.ConvertToAbsolutePixels(WindowPosition); parameters.SetPosition((int)p.X, (int)p.Y); } windowSource = new TrustedHwndSource(parameters); rootVisual = new VisualWrapper(WindowSize); windowSource.RootVisual = rootVisual; windowHandle = windowSource.Handle; return(null); }
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)); }
public static HwndSource GetPreviewHandle() { var wnd = PreviewHandle; if (wnd == IntPtr.Zero) { return(null); } Int32Rect rect; if (!NativeMethods.GetClientRect(wnd, out rect)) { throw new ApplicationException("プレビューウィンドウの領域取得に失敗しました。"); } var param = new HwndSourceParameters("ScreenSaverPreview"); param.SetPosition(0, 0); param.SetSize(rect.Width, rect.Height); param.ParentWindow = wnd; param.WindowStyle = (int)(NativeWindowStyle.WS_VISIBLE | NativeWindowStyle.WS_CHILD | NativeWindowStyle.WS_CLIPCHILDREN); var prev = new HwndSource(param); prev.Disposed += (s, e) => Application.Current.Shutdown(); return(prev); }
protected override HandleRef BuildWindowCore(HandleRef parent) { HwndSourceParameters parameters = new HwndSourceParameters("HostedAvalon", 100, 100); parameters.ParentWindow = parent.Handle; parameters.WindowStyle = NativeConstants.WS_CHILD; source = new HwndSource(parameters); source.AddHook(new HwndSourceHook(Helper)); StackPanel panel = new StackPanel(); rootUIElement = (UIElement)panel; source.RootVisual = panel; Button b = new Button(); b.Click += new RoutedEventHandler(Click); b.Content = "akiaki"; panel.Children.Add(b); MainWindow = source.Handle; return(new HandleRef(null, MainWindow)); }
private async Task CreateNewTest() { Process process = await AppTest.StartAsync("notepad", 1000); while (true) { Console.WriteLine("MainWindow: " + process.MainWindowHandle); var top = User32.GetTopWindow(process.MainWindowHandle); Console.WriteLine("Top window: " + top); /*User32.EnumWindows((ptr,arg) => * { * int pId; * User32.GetWindowThreadProcessId(ptr, out pId); * if (pId == process.Id) * { * StringBuilder bld = new StringBuilder(200); * User32.GetWindowText(ptr, bld, 200); * Console.WriteLine($"{ptr} - {bld} - {User32.IsWindowEnabled(ptr)}"); * } * return true; * }, IntPtr.Zero);*/ foreach (var ptr in User32.EnumerateProcessWindowHandles(process.Id)) { StringBuilder bld = new StringBuilder(200); User32.GetWindowText(process.MainWindowHandle, bld, 200); if (User32.IsWindowVisible(ptr)) { Console.WriteLine($"{ptr} - {bld} - {User32.IsWindowEnabled(ptr)} - {User32.IsWindowVisible(ptr)} - {User32.GetWindowLongA(ptr, -16)& 0x00C00000}"); } } Console.WriteLine(); await Task.Delay(1000); } return; HwndSourceParameters parameters = new HwndSourceParameters(); parameters.WindowStyle = (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_VISIBLE); parameters.ParentWindow = process.MainWindowHandle; Overlay frameworkElement = new Overlay(); HwndSource hwndSource = new HwndSource(parameters) { SizeToContent = SizeToContent.WidthAndHeight, RootVisual = frameworkElement }; hwndSource.CompositionTarget.BackgroundColor = Colors.LightSteelBlue; // black background seems too dominant, use a different default frameworkElement.Width = 500; frameworkElement.Height = 500; }
//Callback will be triggered on app startup private void ApplicationStartup(object sender, StartupEventArgs e) { //Argument to start the screensaver if (e.Args.Length == 0 || e.Args[0].ToLower().StartsWith("/s")) { foreach (Screen s in Screen.AllScreens) { if (s != Screen.PrimaryScreen) { Blackout window = new Blackout(); window.Left = s.WorkingArea.Left; window.Top = s.WorkingArea.Top; window.Width = s.WorkingArea.Width; window.Height = s.WorkingArea.Height; window.Show(); } else { MainWindow window = new MainWindow(); window.Left = s.WorkingArea.Left; window.Top = s.WorkingArea.Top; window.Width = s.WorkingArea.Width; window.Height = s.WorkingArea.Height; window.Show(); } } } //Argument to preview the screen saver else if (e.Args[0].ToLower().StartsWith("/p")) { MainWindow window = new MainWindow(); Int32 previewHandle = Convert.ToInt32(e.Args[1]); IntPtr pPreviewHnd = new IntPtr(previewHandle); RECT lpRect = new RECT(); bool bGetRect = Win32API.GetClientRect(pPreviewHnd, ref lpRect); HwndSourceParameters sourceParams = new HwndSourceParameters("sourceParams"); sourceParams.PositionX = 0; sourceParams.PositionY = 0; sourceParams.Height = lpRect.Bottom - lpRect.Top; sourceParams.Width = lpRect.Right - lpRect.Left; sourceParams.ParentWindow = pPreviewHnd; sourceParams.WindowStyle = (int)(WindowStyles.WS_VISIBLE | WindowStyles.WS_CHILD | WindowStyles.WS_CLIPCHILDREN); winWPFContent = new HwndSource(sourceParams); winWPFContent.Disposed += (o, args) => window.Close(); winWPFContent.RootVisual = window.RootGrid; } //Argument to configure the screensaver else if (e.Args[0].ToLower().StartsWith("/c")) { SettingsWindow window = new SettingsWindow(); window.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; window.VerticalAlignment = System.Windows.VerticalAlignment.Center; window.Show(); } }
internal override HwndSourceParameters CreateHwndSourceParameters() { HwndSourceParameters result = base.CreateHwndSourceParameters(); result.TreatAsInputRoot = true; result.TreatAncestorsAsNonClientArea = true; return(result); }
private IntPtr CreateMessageOnlyWindow() { IntPtr HWND_MESSAGE = new IntPtr(-3); HwndSourceParameters sourceParam = new HwndSourceParameters() { ParentWindow = HWND_MESSAGE }; HwndSource source = new HwndSource(sourceParam); source.AddHook(WndProc); return source.Handle; }
internal override HwndSourceParameters CreateHwndSourceParameters() { HwndSourceParameters parameters = base.CreateHwndSourceParameters(); parameters.TreatAsInputRoot = true; parameters.TreatAncestorsAsNonClientArea = true; return(parameters); }
private void FullWindowFromMessages_Loaded(object sender, RoutedEventArgs e) { HwndSourceParameters parameters = new HwndSourceParameters(); HwndSource source = new HwndSource(parameters); source = HwndSource.FromHwnd(new WindowInteropHelper(sender as Window).Handle); source.AddHook(new HwndSourceHook(WndProc)); }
private IntPtr Create(HwndSourceParameters parameters) { DisposeHWndSource(); _hwndSource = new HwndSource(parameters); _hwndSource.RootVisual = _decorator; (_hwndSource as IKeyboardInputSink).KeyboardInputSite = (ElementContainerInternal as IKeyboardInputSite); return(_hwndSource.Handle); }
private void ApplicationStartup(object sender, StartupEventArgs e) { IConfigurationRoot configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true) .Build(); if (e.Args.Length == 0 || e.Args[0].ToLower().StartsWith("/s")) { //foreach (Screen s in Screen.AllScreens) //{ Screen s = Screen.PrimaryScreen; if (s != Screen.PrimaryScreen) { Blackout window = new Blackout { Left = s.WorkingArea.Left, Top = s.WorkingArea.Top, Width = s.WorkingArea.Width, Height = s.WorkingArea.Height }; window.Show(); } else { MainWindow window = new MainWindow(configuration) { Left = s.WorkingArea.Left, Top = s.WorkingArea.Top, Width = s.WorkingArea.Width, Height = s.WorkingArea.Height }; window.Show(); } //} } else if (e.Args[0].ToLower().StartsWith("/p")) { MainWindow window = new MainWindow(); Int32 previewHandle = Convert.ToInt32(e.Args[1]); IntPtr pPreviewHnd = new IntPtr(previewHandle); WaveSim.Rect lpRect = new WaveSim.Rect(); HwndSourceParameters sourceParams = new HwndSourceParameters("sourceParams") { PositionX = 0, PositionY = 0, Height = lpRect.Bottom - lpRect.Top, Width = lpRect.Right - lpRect.Left, ParentWindow = pPreviewHnd, WindowStyle = (int)(WindowStyles.WS_VISIBLE | WindowStyles.WS_CHILD | WindowStyles.WS_CLIPCHILDREN) }; winWPFContent = new HwndSource(sourceParams); winWPFContent.Disposed += (o, args) => window.Close(); winWPFContent.RootVisual = window.MainGrid; } }