当前位置: 首页>>代码示例>>C#>>正文


C# WindowInteropHelper.EnsureHandle方法代码示例

本文整理汇总了C#中System.Windows.Interop.WindowInteropHelper.EnsureHandle方法的典型用法代码示例。如果您正苦于以下问题:C# WindowInteropHelper.EnsureHandle方法的具体用法?C# WindowInteropHelper.EnsureHandle怎么用?C# WindowInteropHelper.EnsureHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Interop.WindowInteropHelper的用法示例。


在下文中一共展示了WindowInteropHelper.EnsureHandle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Connect

        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;
                }
            }
        }
开发者ID:DreadBoy,项目名称:Shapeshifter,代码行数:33,代码来源:ClipboardHookService.cs

示例2: SwitchPreviewPanel

        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;
            }
        }
开发者ID:shareefalis,项目名称:ace-windows-old,代码行数:30,代码来源:SelfView.xaml.cs

示例3: MainWindow

        public MainWindow()
        {
            InitializeComponent();

            var interopHelper = new WindowInteropHelper(this);
            interopHelper.EnsureHandle();
            handle = interopHelper.Handle;
        }
开发者ID:Artentus,项目名称:GameUtils,代码行数:8,代码来源:MainWindow.xaml.cs

示例4: EnableCustomWindowPreview

        public static void EnableCustomWindowPreview(Window window, bool enable = true)
        {
            var interopHelper = new WindowInteropHelper(window);

            var hwnd = interopHelper.EnsureHandle();

            EnableCustomWindowPreview(hwnd, enable);
        }
开发者ID:squaredinfinity,项目名称:Foundation,代码行数:8,代码来源:dwmapi.cs

示例5: AddWindowStyle

 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);
 }
开发者ID:magnumvalente,项目名称:BrasilDidaticos,代码行数:8,代码来源:ExtraWindowStyles.cs

示例6: BindRawInputKeyboard

        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;
        }
开发者ID:joewan,项目名称:xenko,代码行数:9,代码来源:InputManager.Windows.RawInput.Keyboard.cs

示例7: MainWindow

        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);
        }
开发者ID:williamwilson,项目名称:BeatBox,代码行数:10,代码来源:MainWindow.xaml.cs

示例8: ClipboardMonitor

        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);
        }
开发者ID:Usagination,项目名称:Decchi,代码行数:10,代码来源:ClipboardMonitor.cs

示例9: MainWindowWnc

            public MainWindowWnc(MainWindow window)
            {
                this.m_window = window;

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

                this.AssignHandle(helper.Handle);
            }
开发者ID:Usagination,项目名称:Decchi,代码行数:10,代码来源:MainWindow.xaml.cs

示例10: Setup

 /// <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);
 }
开发者ID:jameshy,项目名称:else,代码行数:14,代码来源:Win32MessagePump.cs

示例11: GlobalHotkeyService

 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);
 }
开发者ID:Melamew,项目名称:iLynx.Common,代码行数:15,代码来源:GlobalHotkeyService.cs

示例12: MainWindow

        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;
        }
开发者ID:RyuaNerin,项目名称:ffchat,代码行数:18,代码来源:MainWindow.xaml.cs

示例13: OnPropertyChanged

		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;
				}
			}
		}
开发者ID:lisiynos,项目名称:pascalabcnet,代码行数:42,代码来源:FullScreenEnabledWindow.cs

示例14: ReenableWPFTabletSupport

        /// <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);
        }
开发者ID:ux-hs-mannheim,项目名称:lgRuntime,代码行数:45,代码来源:SurfaceTouchHelper.cs

示例15: OnSourceInitialized

 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);
 }
开发者ID:DeCarabas,项目名称:EBrake,代码行数:7,代码来源:MainWindow.xaml.cs


注:本文中的System.Windows.Interop.WindowInteropHelper.EnsureHandle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。