Posted By

jimfred on 04/09/11


Tagged


Versions (?)

MFC, Text to clipboard


 / Published in: C++
 

URL: stackoverflow.com/questions/2253476/does-mfc-provide-a-quick-way-to-throw-text-on-the-clipboard

  1. void SetClipboardText( LPCSTR pText )
  2. {
  3. HGLOBAL h;
  4. LPTSTR arr;
  5.  
  6. int size = strlen(pText)+1;
  7.  
  8. h=GlobalAlloc(GMEM_MOVEABLE, size);
  9. arr=(LPTSTR)GlobalLock(h);
  10. strcpy_s((char*)arr, size, pText);
  11. GlobalUnlock(h);
  12.  
  13. ::OpenClipboard (NULL);
  14. EmptyClipboard();
  15. SetClipboardData(CF_TEXT, h);
  16. CloseClipboard();
  17. }

Report this snippet  

You need to login to post a comment.