Knowledge Base Nr: 00323 clipboard2.cpp - http://www.swe-kaiser.de

Downloads:

Win32/MFC: (unicode-)text in clipboard ablegen

  
CString sClipboardText(L"Alles klar?");

if (::OpenClipboard(AfxGetMainWnd()->GetSafeHwnd()))
{
HGLOBAL hText;
wchar_t* pText;

hText = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, 1000);
pText = (wchar_t*)GlobalLock(hText);

wcscpy(pText, sClipboardText.GetBuffer(1000));

GlobalUnlock(hText);

::EmptyClipboard();
::SetClipboardData(CF_UNICODETEXT, hText);
::CloseClipboard();
}