Example #1
0
        /// <summary>
        ///     WNDs the proc.
        /// </summary>
        /// <param name="hwnd">The HWND.</param>
        /// <param name="msg">The MSG.</param>
        /// <param name="wParam">The w parameter.</param>
        /// <param name="lParam">The l parameter.</param>
        /// <param name="handled">if set to <c>true</c> [handled].</param>
        /// <returns>IntPtr.</returns>
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            // defined in winuser.h
            const int WM_DRAWCLIPBOARD = 0x308;
            const int WM_CHANGECBCHAIN = 0x030D;

            switch (msg)
            {
            case WM_DRAWCLIPBOARD:
                NativeMethods.SendMessage(_nextClipboardViewer, msg, wParam,
                                          lParam);
                var newItem = new TextClipboardItem
                {
                    ClippedDate = DateTime.Now,
                    Content     = Clipboard.GetText()
                };
                _textClipboardItems.Add(newItem);
                _clipboardItemSubject.OnNext(newItem);
                break;

            case WM_CHANGECBCHAIN:
                if (wParam == _nextClipboardViewer)
                {
                    _nextClipboardViewer = lParam;
                }
                else
                {
                    NativeMethods.SendMessage(_nextClipboardViewer, msg, wParam,
                                              lParam);
                }
                break;
            }
            return(IntPtr.Zero);
        }
Example #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ClipboardItemViewModel" /> class.
 /// </summary>
 /// <param name="textClipboardItem">The text clipboard item.</param>
 public ClipboardItemViewModel(TextClipboardItem textClipboardItem)
 {
     Instance = textClipboardItem;
     Preview  = new string(textClipboardItem.Content.Take(250).ToArray());
 }