VC gets Clipboard text content

Source: Internet
Author: User

Objective:

This article is limited to obtaining and setting the text content of the Clipboard, but it does not involve resources such as pictures;


Example:

One: Set Clipboard text content (support general symbols, special symbols not tested)

BOOL Setclipboardtext (LPCSTR Text,hwnd hwnd)  {  ASSERT (HWND);  Open Clipboard  if (!::openclipboard (hWnd))  return false;  If the Clipboard has content, close the Clipboard if (! EmptyClipboard ())  {  closeclipboard ();  return false;  }  Gets the length of the text that needs to be set  int len=strlen (text);  Request Clipboard space handle Hclip=globalalloc (gmem_moveable| Gmem_ddeshare, (len+1) *sizeof (char*));  if (hclip==null)  {  closeclipboard ();  return false;  }  Space to apply lock char* pbuf= (char*) GlobalLock (hclip);  if (pbuf==null)  {  globalfree (hclip);    CloseClipboard ();  return false;  }  Copy the text content to the Clipboard memcpy ((char *) pbuf,text,len*sizeof (char*));  Pbuf[len]=null;  Operation complete, Release lock GlobalUnlock (hclip);  if (Null==setclipboarddata (cf_text,hclip))  {  globalfree (hclip);    CloseClipboard ();  return false;  }  CloseClipboard ();  return true;  }  

Two: Get the Clipboard text content (the std_string here is wrapped in string, overloading the "=" number)

Gets the Clipboard text content std_string Getclipboardtext (HWND hwnd)  {       ASSERT (HWND);  Std_string Clipboardtext;  Determines whether the data format of the Clipboard can be processed.  if (! Isclipboardformatavailable (cf_text))   return clipboardtext;   Open the Clipboard.          if (!::openclipboard (hWnd))  return clipboardtext;   Get Data  HANDLE Hmem = GetClipboardData (cf_text);   if (hmem! = NULL)           {   //Gets a string.  LPSTR LPSTR = (LPSTR) globallock (HMEM);   if (lpStr! = NULL)        {   clipboardtext=lpstr;  Release lock Memory  GlobalUnlock (HMEM);       }            }    Close clipboard        closeclipboard ();    return clipboardtext;  }  

Cond......


VC gets Clipboard text content

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.