Case idm_edit_paste: openclipboard (hwnd); // open the clipboard if (hglobal = getclipboarddata (cf_tchar) // obtain the clipboard memory handle {pglobal = globallock (hglobal); // lock the handle, obtain the memory pointer if (ptext) {free (ptext); ptext = NULL;} ptext = malloc (globalsize (hglobal); // copy the memory data lstrcpy (ptext, pglobal ); invalidaterect (hwnd, null, true);} closeclipboard (); // close the clipboard return 0; Case idm_edit_cut: Case idm_edit_copy: If (! Ptext) return 0; hglobal = globalalloc (ghnd | gmem_share, (lstrlen (ptext) + 1) * sizeof (tchar); pglobal = globallock (hglobal); lstrcpy (pglobal, ptext); globalunlock (hglobal); openclipboard (hwnd); // open the clipboard emptyclipboard (); // clear the clipboard setclipboarddata (cf_tchar, hglobal ); // set the memory handle closeclipboard (); // close the clipboard if (loword (wparam) = idm_edit_copy) return 0; // fall through for idm_edit_cut
I. Clipboard principle:
* Only one data item can be retained for the same type of data in the clipboard.
* The Clipboard contains a handle pointing to the copy and cut memory.
Copy & cut:
Obtain the handle pointing to the memory that stores the copy and cut data.
Open clipboard
Clear clipboard
Set memory handle
Close clipboard
Paste:
Open clipboard
Obtains the handle pointing to the memory that stores the copied and cut data.
Lock the handle to obtain the memory pointer
Copy memory data for corresponding processing
Close clipboard
Ii. Other functions:
Isclipboardformatavailable () determines whether the content in the clipboard is determined by the content.
Enumclipboardformats // returns a value for each format in the clipboard
Countclipboardformats // number of different formats
Getclipboardowner // get the clipboard owner