Changeset 968 for code/branches/core2
- Timestamp:
- Mar 31, 2008, 9:22:54 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/util/Clipboard.cc
r966 r968 24 24 * ... 25 25 * 26 * Windows version inspired by "Copy Text To Clipboard" by Laszlo Szathmary, 2007 27 * http://www.loria.fr/~szathmar/off/projects/C/CopyTextToClipboard/index.php 26 28 */ 27 29 … … 33 35 bool toClipboard(std::string text) 34 36 { 35 if (OpenClipboard(0))37 try 36 38 { 37 EmptyClipboard(); 38 HGLOBAL clipbuffer = GlobalAlloc(GMEM_DDESHARE, text.size() + 1); 39 char* buffer = (char*)GlobalLock(clipbuffer); 40 strcpy(buffer, text.c_str()); 41 GlobalUnlock(clipbuffer); 42 SetClipboardData(CF_TEXT, clipbuffer); 43 CloseClipboard(); 39 if (OpenClipboard(0)) 40 { 41 EmptyClipboard(); 42 HGLOBAL clipbuffer = GlobalAlloc(GMEM_DDESHARE, text.size() + 1); 43 char* buffer = (char*)GlobalLock(clipbuffer); 44 strcpy(buffer, text.c_str()); 45 GlobalUnlock(clipbuffer); 46 SetClipboardData(CF_TEXT, clipbuffer); 47 CloseClipboard(); 44 48 45 return true; 49 return true; 50 } 51 } 52 catch (...) 53 { 46 54 } 47 55 return false; … … 50 58 std::string fromClipboard() 51 59 { 52 if (OpenClipboard(0))60 try 53 61 { 54 HANDLE hData = GetClipboardData(CF_TEXT); 55 std::string output = (char*)GlobalLock(hData); 56 GlobalUnlock(hData); 57 CloseClipboard(); 62 if (OpenClipboard(0)) 63 { 64 HANDLE hData = GetClipboardData(CF_TEXT); 65 std::string output = (char*)GlobalLock(hData); 66 GlobalUnlock(hData); 67 CloseClipboard(); 58 68 59 return output; 69 return output; 70 } 71 } 72 catch (...) 73 { 60 74 } 61 75 return ""; 62 76 } 63 77 #else 78 std::string clipboard = ""; 79 64 80 bool toClipboard(std::string text) 65 81 { 66 return false; 82 clipboard = text; 83 return true; 67 84 } 85 68 86 std::string fromClipboard() 69 87 { 70 return "";88 return clipboard; 71 89 } 72 90 #endif
Note: See TracChangeset
for help on using the changeset viewer.