剪切板上文本数据的传送

发表于:2007-05-25来源:作者:点击数: 标签:剪切板放置传送文本数据
把文本放置到剪接板上: CString source; //put your text in source if(OpenClipboard()) { HGLOBAL clipbuffer; char * buffer; EmptyClipboard(); clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.GetLength()+1); buffer = (char*)GlobalLock(clipbuffe

把文本放置到剪接板上:
CString source;
//put your text in source
if(OpenClipboard())
{
    HGLOBAL clipbuffer;
    char * buffer;
    EmptyClipboard();
    clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.GetLength()+1);
    buffer = (char*)GlobalLock(clipbuffer);
    strcpy(buffer, LPCSTR(source));
    GlobalUnlock(clipbuffer);
    SetClipboardData(CF_TEXT,clipbuffer);
    CloseClipboard();
}

从剪接板上获取文本:
char * buffer;
if(OpenClipboard())
{
    buffer = (char*)GetClipboardData(CF_TEXT);
    //do something with buffer here
    //before it goes out of scope
}
CloseClipboard();

原文转自:http://www.ltesting.net