void CClipBoradTestDlg::OnBnClickedButton1(){ // TODO: 在此添加控件通知处理程序代码 HANDLE hClip; HGLOBAL hmem; if(!OpenClipboard()) { MessageBox(_T("open clipboard error!")); return; } if(!EmptyClipboard()) { MessageBox(_T("clear clipboard error!")); return; } CString str; GetDlgItemText(IDC_EDIT1,str); size_t cbStr = (str.GetLength() + 1) * sizeof(TCHAR); hmem = GlobalAlloc(GMEM_MOVEABLE,cbStr);//申请内存 memcpy(GlobalLock(hmem),str.GetBuffer(0),cbStr);//将数据拷贝到申请的内存中。 str.ReleaseBuffer(); GlobalUnlock(hmem); hClip = SetClipboardData(CF_UNICODETEXT,hmem);}void CClipBoradTestDlg::OnBnClickedButton2(){ // TODO: 在此添加控件通知处理程序代码 if(!OpenClipboard()) { MessageBox(_T("open clipboard error!")); return; } CString str; HANDLE hdata = GetClipboardData(CF_UNICODETEXT); if(hdata == NULL) { MessageBox(_T("hdata null!")); return; } str.Format(_T("%s"),GlobalLock(hdata)); GlobalUnlock(hdata); SetDlgItemText(IDC_EDIT2,str); CloseClipboard();}