windows复制粘贴的代码
复制可以,粘贴还没测试。有没有什么问题?程序代码:
void gui_gdiplus_copy(wchar_t* str, int len) { if(!str || len<1 || !OpenClipboard(NULL))return; HGLOBAL mem = (HGLOBAL)GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(wchar_t)); if(!mem) { CloseClipboard(); return; } wchar_t* wstr = (wchar_t*)GlobalLock(mem); if(!wstr) { GlobalFree(mem); CloseClipboard(); return; } wcsncpy(wstr, str, len); wstr[len] = 0; GlobalUnlock(mem); if (!SetClipboardData(CF_UNICODETEXT, mem)) GlobalFree(mem); CloseClipboard(); } void gui_gdiplus_paste(wchar_t* str, int len) { if(len<1)return; if(!IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL)) return; HGLOBAL mem; size_t size; wchar_t* wstr; mem = (HGLOBAL)GetClipboardData(CF_UNICODETEXT); if (!mem) { CloseClipboard(); return; } size = GlobalSize(mem) - 1; if (!size) { CloseClipboard(); return; } wstr = (wchar_t*)GlobalLock(mem); if (!wstr) { CloseClipboard(); return; } wcsncpy(str, wstr, len<size?len:size); GlobalUnlock(mem); CloseClipboard(); }