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 ..