Created
January 11, 2012 12:19
-
-
Save t-mat/1594419 to your computer and use it in GitHub Desktop.
Windows SDK : クリップボードにTCHARテキストをコピーする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <windows.h> | |
| #include <tchar.h> | |
| void setStringToClipboard(const TCHAR* str) { | |
| if(OpenClipboard(0)) { | |
| EmptyClipboard(); | |
| size_t l = _tcslen(str); | |
| if(l) { | |
| HGLOBAL h = GlobalAlloc(GMEM_MOVEABLE, (l+1) * sizeof(*str)); | |
| if(h) { | |
| _tcscpy_s((TCHAR*)GlobalLock(h), l+1, str); | |
| GlobalUnlock(h); | |
| switch(sizeof(*str)) { | |
| default: | |
| case 1: | |
| SetClipboardData(CF_TEXT, h); | |
| break; | |
| case 2: | |
| SetClipboardData(CF_UNICODETEXT, h); | |
| break; | |
| } | |
| } | |
| } | |
| CloseClipboard(); | |
| } | |
| } | |
| #if defined(SELF_TEST) | |
| void main() { | |
| setStringToClipboard(_T("TEST STRING")); | |
| } | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment