Clipboard monitoring-C ++ implementation

Source: Internet
Author: User

Let's have two messages: wm_changecbchain and wm_drawclipboard ..

Principle: The clipboard has a monitoring linked list, which is the program that monitors the clipboard. If a new monitoring program is added or removed, then a message wm_changecbchain will be sent to each program in the linked list. Of course, this is a chained message, and each program is responsible for transmitting the message to the next program. When the data in the clipboard changes, A wm_drawclipboard message will be sent to our window.

Message Processing functions:

Afx_msg void onchangecbchain (hwnd hwndremove, hwnd hwndafter );

Afx_msg void ondrawclipboard ();

Hwndremove: The Window handle deleted from the list of monitoring clipboard.

Hwndafter: the next window handle of the window removed from the List

HWND m_hNext;
M_hnext =: setclipboardviewer (this-> getsafehwnd (); // monitoring linked list

Void cdrayfilesdlg: onchangecbchain (hwnd hwndremove, hwnd hwndafter) {cdialogex: onchangecbchain (hwndremove, hwndafter); // todo: add the message processing program code if (m_hnext = hwndremove) m_hnext = hwndafter; else if (m_hnext): sendmessagew (m_hnext, wm_changecbchain, (wparam) hwndremove, (lparam) hwndafter);} void cdrayfilesdlg: callback () {cdialogex: ondrawclipboard (); // todo: add the message handler code here if (m_hnext): sendmessagew (m_hnext, wm_changecbchain, 0, 0);: openclipboard (getsafehwnd (); handle handledata = getclipboarddata (cf_text); cstring data (char *) handledata ); m_clipboarddata.addstring (Data + "\ r \ n");: closeclipboard ();}

The code is very simple and I will not explain it ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.