private static void RemoveWndProcUsage(HwndHost hwndHost) { int refCount = (int)hwndHost.GetValue(WindowHookRefCountProperty); refCount--; hwndHost.SetValue(WindowHookRefCountProperty, refCount); if (refCount == 0) { HwndHostExtensionsWindowHook hook = (HwndHostExtensionsWindowHook)hwndHost.GetValue(WindowHookProperty); hook.Dispose(); hwndHost.ClearValue(WindowHookProperty); } }
private static void AddWndProcUsage(HwndHost hwndHost) { int refCount = (int)hwndHost.GetValue(WindowHookRefCountProperty); refCount++; hwndHost.SetValue(WindowHookRefCountProperty, refCount); if (refCount == 1) { if (!TryHookWndProc(hwndHost)) { // Try again later, when the HwndHost is loaded. hwndHost.Loaded += (s, e) => TryHookWndProc((HwndHost)s); } } }
private static bool TryHookWndProc(HwndHost hwndHost) { if (hwndHost.Handle != IntPtr.Zero) { // Hook the window messages so we can intercept the // various messages. HwndHostExtensionsWindowHook hook = new HwndHostExtensionsWindowHook(hwndHost); // Keep our hook alive. hwndHost.SetValue(WindowHookProperty, hook); return(true); } return(false); }
/// <summary> /// Attached property setter for the CopyBitsBehavior property. /// </summary> public static void SetCopyBitsBehavior(this HwndHost @this, CopyBitsBehavior value) { @this.SetValue(CopyBitsBehaviorProperty, value); }
/// <summary> /// Attached property setter for the RaiseMouseActivateCommand property. /// </summary> public static void SetRaiseMouseActivateCommand(this HwndHost @this, bool value) { @this.SetValue(RaiseMouseActivateCommandProperty, value); }