本文整理汇总了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;
}
}
}
示例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;
}
}
示例3: MainWindow
public MainWindow()
{
InitializeComponent();
var interopHelper = new WindowInteropHelper(this);
interopHelper.EnsureHandle();
handle = interopHelper.Handle;
}
示例4: EnableCustomWindowPreview
public static void EnableCustomWindowPreview(Window window, bool enable = true)
{
var interopHelper = new WindowInteropHelper(window);
var hwnd = interopHelper.EnsureHandle();
EnableCustomWindowPreview(hwnd, enable);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
}
示例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);
}
示例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);
}