public void Connect()
        {
            if (!IsConnected)
            {
                lock (this)
                {
                    var mainWindow = App.Current.MainWindow;
                    if (mainWindow == null)
                    {
                        throw new InvalidOperationException("Can't install a clipboard hook when there is no window open.");
                    }

                    var interopHelper = new WindowInteropHelper(mainWindow);
                    var windowHandle = interopHelper.EnsureHandle();

                    var hooker = PresentationSource.FromVisual(mainWindow) as HwndSource;
                    if (hooker == null)
                    {
                        throw new InvalidOperationException("Could not fetch the handle of the main window.");
                    }

                    //now try installing a clipboard hook.
                    if (!ClipboardApi.AddClipboardFormatListener(windowHandle))
                    {
                        throw new NotImplementedException("Could not install a clipboard hook for the main window.");
                    }

                    hooker.AddHook(WindowHookCallback);

                    IsConnected = true;
                }
            }
        }
        private void SwitchPreviewPanel(bool bOn)
        {
            var _linphone = ServiceManager.Instance.LinphoneService;
            if (_linphone == null)
                return;
            if (!bOn)
            {
                if (ResetNativePreviewHandle)
                    _linphone.SetVideoPreviewWindowHandle(IntPtr.Zero, true);
            }
            else
            {
                _linphone.SetPreviewVideoSizeByName("cif");
                var source = GetWindow(this);
                if (source != null)
                {
                    var wih = new WindowInteropHelper(source);
                    if (wih.Handle != IntPtr.Zero)
                    {
                        IntPtr hWnd = wih.EnsureHandle();

                        if (hWnd != IntPtr.Zero)
                        {
                            _linphone.SetVideoPreviewWindowHandle(hWnd);
                        }
                    }
                }
                ResetNativePreviewHandle = true;
            }
        }
Beispiel #3
0
        public MainWindow()
        {
            InitializeComponent();

            var interopHelper = new WindowInteropHelper(this);
            interopHelper.EnsureHandle();
            handle = interopHelper.Handle;
        }
Beispiel #4
0
        public static void EnableCustomWindowPreview(Window window, bool enable = true)
        {
            var interopHelper = new WindowInteropHelper(window);

            var hwnd = interopHelper.EnsureHandle();

            EnableCustomWindowPreview(hwnd, enable);
        }
 private static void AddWindowStyle(Window window, WindowStyles styleToAdd)
 {
     WindowInteropHelper wih = new WindowInteropHelper(window);
     WindowStyles style = (WindowStyles)GetWindowLongPtr(wih.EnsureHandle(), GWL_STYLE);
     style |= styleToAdd;
     SetWindowLongPtr(wih.Handle, GWL_STYLE, (IntPtr)style);
     SetWindowPos(wih.Handle, IntPtr.Zero, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
 }
        private void BindRawInputKeyboard(System.Windows.Window winformControl)
        {
            EnsureMapKeys();

            var interopHelper = new WindowInteropHelper(winformControl);
            interopHelper.EnsureHandle();
            SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericKeyboard, DeviceFlags.None, interopHelper.Handle);
            SharpDX.RawInput.Device.KeyboardInput += DeviceOnKeyboardInput;
        }
        public MainWindow()
        {
            InitializeComponent();

            WindowInteropHelper interopHelper = new WindowInteropHelper(this);
            /* note: the window has not loaded yet, so has no handle, force the handle
             * creation now */
            interopHelper.EnsureHandle();
            DataContext = new BeatBoxViewModel(interopHelper.Handle);
        }
Beispiel #8
0
        public ClipboardMonitor(Window window)
        {
            var helper = new WindowInteropHelper(window);
            if (helper.Handle == IntPtr.Zero) helper.EnsureHandle();

            this.m_handle = helper.Handle;

            this.AssignHandle(this.m_handle);
            NativeMethods.AddClipboardFormatListener(this.m_handle);
        }
Beispiel #9
0
            public MainWindowWnc(MainWindow window)
            {
                this.m_window = window;

                var helper = new WindowInteropHelper(window);
                if (helper.Handle == IntPtr.Zero)
                    helper.EnsureHandle();

                this.AssignHandle(helper.Handle);
            }
Beispiel #10
0
 /// <summary>
 /// Setup wndproc handling so we can receive window messages (Win32 stuff)
 /// </summary>
 /// <exception cref="Exception">Failed to acquire window handle</exception>
 public void Setup(Window window)
 {
     var windowHelper = new WindowInteropHelper(window);
     windowHelper.EnsureHandle();
     _hwndSource = HwndSource.FromHwnd(windowHelper.Handle);
     if (_hwndSource == null) {
         throw new Exception("Failed to acquire window handle");
     }
     _hwndSource.AddHook(HandleMessages);
 }
 public GlobalHotkeyService()
 {
     // Static stuff is meh...
     Application.Current.Guard("Application.Current");
     Application.Current.MainWindow.Guard("Application.Current.MainWindow");
     var interopHelper = new WindowInteropHelper(Application.Current.MainWindow);
     interopHelper.EnsureHandle();
     source = HwndSource.FromHwnd(interopHelper.Handle);
     if (null == source)
     {
         Trace.WriteLine("Could not get HwndSource for the Shell");
         return;
     }
     source.AddHook(WndProc);
 }
Beispiel #12
0
        public MainWindow()
        {
            Instance = this;

            InitializeComponent();

            var helper = new WindowInteropHelper(this);
            helper.EnsureHandle();
            this.m_handle = helper.Handle;
            
            this.m_hookProc = new NativeMethods.WinEventDelegate(this.WinEventProc);

            this.ctlFilter.ItemsSource = ChatType.Types.Values;
            
            this.m_chat = CollectionViewSource.GetDefaultView(Worker.ChatLog);
            this.m_chat.Filter = (e) => ((Chat)e).ChatType.Visible;
            this.ctlList.ItemsSource = m_chat;
        }
		protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
		{
			base.OnPropertyChanged(e);
			if (e.Property == FullScreenProperty) {
				if ((bool)e.NewValue) {
					// enable fullscreen mode
					// remember previous window state
					if (this.WindowState == WindowState.Normal || this.WindowState == WindowState.Maximized)
						previousWindowState = this.WindowState;
					oldLeft = this.Left;
					oldTop = this.Top;
					oldWidth = this.Width;
					oldHeight = this.Height;
					
					WindowInteropHelper interop = new WindowInteropHelper(this);
					interop.EnsureHandle();
					Screen screen = Screen.FromHandle(interop.Handle);
					
					Rect bounds = screen.Bounds.ToWpf().TransformFromDevice(this);
					
					this.ResizeMode = ResizeMode.NoResize;
					this.Left = bounds.Left;
					this.Top = bounds.Top;
					this.Width = bounds.Width;
					this.Height = bounds.Height;
					this.WindowState = WindowState.Normal;
					this.WindowStyle = WindowStyle.None;
					
				} else {
					ClearValue(WindowStyleProperty);
					ClearValue(ResizeModeProperty);
					ClearValue(MaxWidthProperty);
					ClearValue(MaxHeightProperty);
					this.WindowState = previousWindowState;
					
					this.Left = oldLeft;
					this.Top = oldTop;
					this.Width = oldWidth;
					this.Height = oldHeight;
				}
			}
		}
        /// <summary>
        /// Code partially from http://msdn.microsoft.com/en-us/library/vstudio/dd901337(v=vs.90).aspx
        /// </summary>
        /// <param name="window"></param>
        public static void ReenableWPFTabletSupport(Window window)
        {
            //getting window handle
            WindowInteropHelper helper = new WindowInteropHelper(window);
            helper.EnsureHandle();
            IntPtr source = helper.Handle;

            // Get a collection of the tablet devices for this window.
            TabletDeviceCollection devices = Tablet.TabletDevices;
            Console.WriteLine("Tablet Devices before workaround: " + devices.Count);

            //if there are none -> create a new one
            if (devices.Count == 0)
            {
                // Get the Type of InputManager.
                Type inputManagerType = typeof(System.Windows.Input.InputManager);

                // Call the StylusLogic method on the InputManager.Current instance.
                object stylusLogic = inputManagerType.InvokeMember("StylusLogic",
                            BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                            null, InputManager.Current, null);

                if (stylusLogic != null)
                {
                    //  Get the type of the stylusLogic returned from the call to StylusLogic.
                    Type stylusLogicType = stylusLogic.GetType();

                    // Loop until there are no more devices to remove.
                    if (devices.Count == 0)
                    {
                        // Remove the first tablet device in the devices collection.

                        stylusLogicType.InvokeMember("OnTabletAdded",
                                BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,
                                null, stylusLogic, new object[] { (uint)source });
                    }
                }

            }
            Console.WriteLine("Tablet Devices after workaround: " + devices.Count);
        }
Beispiel #15
0
 void OnSourceInitialized(object sender, EventArgs e)
 {
     // Hook the window proc so that we can get the disc-change notifications.
     var interopHelper = new WindowInteropHelper(this);
     this.interopSource = HwndSource.FromHwnd(interopHelper.EnsureHandle());
     this.interopSource.AddHook(MessageHook);
 }
        private void ShowSettings(IntPtr hWnd)
        {
            string hWndToString = "null";
            bool fAbortShowSettings = false;

            if (hWnd == IntPtr.Zero)
            {
                hWndToString = "IntPtr.Zero!";
                fAbortShowSettings = true;
            }
            else if (hWnd == null)
            {
                fAbortShowSettings = true;
            }
            else
            {
                hWndToString = hWnd.ToString();
                fAbortShowSettings = false;
            }

            Log("ShowSettings(" + hWndToString + ") entered.");

            if (fAbortShowSettings)
            {
                Application.Current.Shutdown();
            }

            if (NativeMethods.IsWindow(hWnd))
            {
                Window settings = new SettingsWindow(hWnd);

                // use Win32 API's to get the window handles we need for ShowModal

                // Get the root owner window of the passed hWnd
                int error = 0;
                Log("  ShowSettings(): Getting Root Ancestor of passed hWnd: calling GetAncestor(hWnd, GetRoot)...");
                NativeMethods.SetLastErrorEx(0, 0);
                IntPtr passedWndRoot = NativeMethods.GetAncestor(hWnd, NativeMethods.GetAncestorFlags.GetRoot);
                error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                Log("  ShowSettings(): GetAncestor() returned IntPtr: " + passedWndRoot.ToString());
                Log("      GetLastError() returned: " + error.ToString());
                Log(" ");

                // and then show ourselves modal to that window
                Log("  ShowSettings(): Building a Windows.Interop.WindowsInteropHelper for SettingsWindow...");
                System.Windows.Interop.WindowInteropHelper wih = new System.Windows.Interop.WindowInteropHelper(settings);
                Log("  ShowSettings(): Calling wih.EnsureHandle() to force SettingsWindow to have a Handle...");
                wih.EnsureHandle();
                Log("  ShowSettings(): Setting wih.Owner to Root Ancestor of passed in hWnd...");
                wih.Owner = passedWndRoot;
                Log("  ShowSettings(): Calling ShowDialog()");
                settings.ShowDialog();
            }
            else
            {
                Log("  ShowSettings(): Invalid hWnd passed: " + hWnd.ToString());
                throw new ArgumentException("Invalid hWnd passed to ShowMiniPreview(): " + hWnd.ToString());
            }

            Log("ShowSettings(" + hWnd.ToString() + ") exiting.");
        }
Beispiel #17
0
        void DisableEdgeGestures() {
            var ih = new WindowInteropHelper(this);
            var hwnd = ih.EnsureHandle();

            var success = SetTouchDisableProperty(hwnd, true);
            if (!success) {
                Console.Error.WriteLine("Failed to set touch disable property");
            }
        }
 public void FlashWindow(Window wnd)
 {
     try
     {
         Window window = Window.GetWindow(wnd);
         if (window == null)
             return;
         var wih = new WindowInteropHelper(wnd);
         theWindowPtr = wih.EnsureHandle();
         if (theWindowPtr != IntPtr.Zero)
             Flash(theWindowPtr, 100);
     }
     catch (Exception ex)
     {
         ServiceManager.LogError("FlashWindow", ex);
     }
 }
 // Helper
 private static IntPtr GetWindowHwnd(Window window)
 {
     var tmp = new WindowInteropHelper(window);
     tmp.EnsureHandle();
     return new WindowInteropHelper(window).Handle;
 }
Beispiel #20
0
 /// <summary>
 /// Adds the window message hook.
 /// </summary>
 private void AddWindowMessageHook()
 {
     var interopHelper = new WindowInteropHelper(Window);
     var source = HwndSource.FromHwnd(interopHelper.EnsureHandle());
     if (source != null) source.AddHook(WndProc);
 }
        private void SwitchVideoPanel(bool bOn)
        {
            var _linphone = ServiceManager.Instance.LinphoneService;
            if (_linphone != null)
            {
                if (!bOn)
                {
                    _linphone.SetVideoCallWindowHandle(IntPtr.Zero, true);
                }
                else
                {
                    var source = GetWindow(this);
                    if (source != null)
                    {
                        var wih = new WindowInteropHelper(source);
                        IntPtr hWnd = wih.EnsureHandle();
                        if (hWnd != IntPtr.Zero)
                        {
                            _linphone.SetVideoCallWindowHandle(hWnd);
                        }

                    }
                }
            }
        }
        private static void ResetWindowStyle(Window window, WindowStyles styles, bool set)
        {
            const int Flags = SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREPOSITION
                | SWP_NOSIZE | SWP_NOZORDER;

            var wih = new WindowInteropHelper(window);
            var style = (WindowStyles)GetWindowLongPtr(wih.EnsureHandle(), GWL_STYLE);

            if (set)
            {
                style |= styles;
            }
            else
            {
                style &= ~styles;
            }

            SetWindowLongPtr(wih.Handle, GWL_STYLE, (IntPtr)style);
            SetWindowPos(wih.Handle, IntPtr.Zero, 0, 0, 0, 0, Flags);
        }
Beispiel #23
0
		static WindowInteropHelper GetHelper(DependencyObject o) {
			if (o == null)
				return null;
			var win = Window.GetWindow(o);
			if (win == null)
				return null;
			var helper = new WindowInteropHelper(win);
			if (helper.Handle == IntPtr.Zero)
				helper.EnsureHandle();
			if (helper.Handle == IntPtr.Zero)
				return null;
			return helper;
		}
Beispiel #24
0
        private void ShowEditor(string regex, string test, Action<RegexEditor> replacer)
        {
            var editor = new RegexEditor
                {
                    Replacer = replacer
                };
            if (regex != null)
            {
                editor.RegularExpression = regex;
            }
            if (test != null)
            {
                editor.TestingText = test;
            }

            var helper = new WindowInteropHelper(editor);
            helper.EnsureHandle();
            helper.Owner = Handle;

            editor.ShowDialog();
        }