Example #1
0
        protected override void WndProc(ref Message m)
        {
            const int WM_DRAWCLIPBOARD = 0x308;
            const int WM_CHANGECBCHAIN = 0x030D;

            switch (m.Msg)
            {
            case WM_DRAWCLIPBOARD:
                if (intercept)
                {
                    newText();
                }
                Win32Wrapper.SendMessage(nextClipboardViewer, m.Msg, m.WParam, m.LParam);
                break;

            case WM_CHANGECBCHAIN:
                if (m.WParam == nextClipboardViewer)
                {
                    nextClipboardViewer = m.LParam;
                }
                else
                {
                    Win32Wrapper.SendMessage(nextClipboardViewer, m.Msg, m.WParam, m.LParam);
                }
                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
Example #2
0
        /// <summary>
        /// Gets the highlighted text from the active window, via the
        /// clipboard without damaging current clipboard contents.
        /// </summary>
        /// <remarks>
        /// Saves current clipboard and then sends Ctrl+C to active window.
        /// Picks text from clipboard, and restores original clipboard content.
        /// </remarks>
        public void GetHighlightedText()
        {
            intercept = true;
            saveCurrentContent();
            IntPtr handle = Win32Wrapper.GetForegroundWindow();

            Win32Wrapper.keybd_event(Win32Wrapper.VK_CONTROL, 0, 0, IntPtr.Zero);
            Win32Wrapper.keybd_event(Win32Wrapper.VK_C, 0, 0, IntPtr.Zero);
            Win32Wrapper.keybd_event(Win32Wrapper.VK_C, 0, Win32Wrapper.KEYEVENTF_KEYUP, IntPtr.Zero);
            Win32Wrapper.keybd_event(Win32Wrapper.VK_CONTROL, 0, Win32Wrapper.KEYEVENTF_KEYUP, IntPtr.Zero);
        }
Example #3
0
 private ClipboardManager()
 {
     nextClipboardViewer = Win32Wrapper.SetClipboardViewer(this.Handle);
 }