private IntPtr LowLevelClipboardProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { switch (msg) { case (int)InterceptClipboard.ClipboardEvent.WM_CHANGECBCHAIN: if (wParam == hWndNextViewer) { // clipboard viewer chain changed, need to fix it. hWndNextViewer = lParam; } else if (hWndNextViewer != IntPtr.Zero) { // pass the message to the next viewer. InterceptClipboard.SendMessage(hWndNextViewer, msg, wParam, lParam); } break; case (int)InterceptClipboard.ClipboardEvent.WM_DRAWCLIPBOARD: // clipboard content changed hookedClipboardCallbackAsync.BeginInvoke(true, null, null); // pass the message to the next viewer. InterceptClipboard.SendMessage(hWndNextViewer, msg, wParam, lParam); break; } return(IntPtr.Zero); }
public void Dispose() { // remove this window from the clipboard viewer chain InterceptClipboard.ChangeClipboardChain(hWndSource.Handle, hWndNextViewer); hWndNextViewer = IntPtr.Zero; hWndSource.RemoveHook(this.LowLevelClipboardProc); //pnlContent.Children.Clear(); }
public ClipboardListener(System.Windows.Window w) { hookedLowLevelClipboardProc = (InterceptClipboard.LowLevelClipboardProc)LowLevelClipboardProc; WindowInteropHelper wih = new WindowInteropHelper(w); hWndSource = HwndSource.FromHwnd(wih.Handle); hWndSource.AddHook(LowLevelClipboardProc); // start processing window messages hookedClipboardCallbackAsync = new ClipboardCallbackAsync(ClipboardListener_ClipboardCallbackAsync); hWndNextViewer = InterceptClipboard.SetClipboardViewer(hWndSource.Handle); // set this window as a viewer }