将列表框复制到剪贴板,返回未保存的载体 在使用MFC的C++应用程序中,我希望能够将整个CclitBox内容复制到剪贴板。 sContents +="\n";
我发现了一个复制内容的函数,但返回载体是不保守的。 我用HexEditor查看,似乎是$0A而不是$0D&$0A 这是我的代码:将列表框复制到剪贴板,返回未保存的载体 在使用MFC的C++应用程序中,我希望能够将整个CclitBox内容复制到剪贴板。 sContents +="\n";,c++,visual-studio-2010,visual-studio,mfc,clipboard,C++,Visual Studio 2010,Visual Studio,Mfc,Clipboard,我发现了一个复制内容的函数,但返回载体是不保守的。 我用HexEditor查看,似乎是$0A而不是$0D&$0A 这是我的代码: CListBox * myListBox = (CListBox *)GetDlgItem(IDC_LIST_RESULT); CString sContents = _T(""); CString temp = _T(""); int NumberOfSelections = 0; NumberOfSelections = myListBox->GetCou
CListBox * myListBox = (CListBox *)GetDlgItem(IDC_LIST_RESULT);
CString sContents = _T("");
CString temp = _T("");
int NumberOfSelections = 0;
NumberOfSelections = myListBox->GetCount();
for(int Selection = 0; Selection <= NumberOfSelections-1; Selection++)
{
myListBox->GetText(Selection, temp);
sContents += temp;
sContents +="\n";
}
if (OpenClipboard())
{
HGLOBAL clipbuffer;
char * buffer;
if (EmptyClipboard())
{
clipbuffer = GlobalAlloc(GMEM_DDESHARE, sContents.GetLength() + 1);
buffer = (char*)GlobalLock(clipbuffer);
CStringA ansiString(sContents);
size_t cbString = strlen(ansiString) + 1;
strcpy_s(buffer, cbString, ansiString);
GlobalUnlock(clipbuffer);
if (SetClipboardData(CF_TEXT, clipbuffer) == NULL)
{
CString msg;
msg.Format(_T("Unable to set Clipboard data, error: %d"), GetLastError());
AfxMessageBox(msg);
}
else
AfxMessageBox(_T("Successfully copied selected laps to clipboard"));
}
else
AfxMessageBox(_T("Unable to empty Clipboard"));
CloseClipboard();
}
else
AfxMessageBox(_T("Unable to open Clipboard"));
// TODO: ajoutez ici le code de votre gestionnaire de notification de contrôle
CListBox*myListBox=(CListBox*)GetDlgItem(IDC\u列表\u结果);
CString scocontents=\u T(“”);
CString temp=_T(“”);
int NumberOfSelections=0;
NumberOfSelections=myListBox->GetCount();
for(int Selection=0;Selection GetText(Selection,temp);
sContents+=temp;
sContents+=“\n”;
}
if(OpenClipboard())
{
HGLOBAL clipbuffer;
字符*缓冲区;
if(EmptyClipboard())
{
clipbuffer=GlobalAlloc(GMEM_DDESHARE,scocontents.GetLength()+1);
buffer=(char*)GlobalLock(clipbuffer);
CStringA ansiString(内容);
大小=strlen(ansiString)+1;
strcpy_s(缓冲区、cbString、ansiString);
GlobalUnlock(clipbuffer);
if(SetClipboardData(CF_TEXT,clipbuffer)==NULL)
{
CString味精;
msg.Format(_T(“无法设置剪贴板数据,错误:%d”)、GetLastError();
AfxMessageBox(msg);
}
其他的
AfxMessageBox(_T(“成功地将选定的圈复制到剪贴板”);
}
其他的
AfxMessageBox(_T(“无法清空剪贴板”);
CloseClipboard();
}
其他的
AfxMessageBox(_T(“无法打开剪贴板”);
//待办事项:控制通知代码
我在Visual Studio 2013中使用unicode配置
有人有什么想法吗
非常感谢
致以最良好的祝愿
尼克斯只有一个
\n
,因为这是你放在剪贴板上的东西
sContents +="\n";
应该是
sContents +="\r\n";