CString str=_T("要复制的文本");

//复制到剪贴板

    if (OpenClipboard())

    {

        HGLOBAL clipBuffer;  

        EmptyClipboard();

  

#ifdef _UNICODE         //复制Unicode字符串到剪贴板

        wchar_t * buffer;

        clipBuffer = GlobalAlloc(GMEM_DDESHARE, 2 * lstrlen(str) + sizeof(wchar_t));

        buffer = (wchar_t*)GlobalLock(clipBuffer);

        wcscpy(buffer,strSel);

        GlobalUnlock(clipBuffer);

        SetClipboardData(CF_UNICODETEXT,clipBuffer);

#else                         //复制ANSI字符串到剪贴板

        char *pbuff;

        clipBuffer = GlobalAlloc(GMEM_DDESHARE,str.GetLength()+1);

        pbuff = (char*)GlobalLock(clipBuffer);

        strcpy(pbuff,LPCSTR(strSel));

        GlobalUnlock(clipBuffer);

        SetClipboardData(CF_TEXT,clipBuffer);

#endif

        CloseClipboard();

    }