I'am using the below code to copy paste..but it doesnt copy the whole context it just copies couple of letters and leave the rest of all as junk value..if I use char* to get the data buffer and change the project settings to Multi byte support...it will work..but t开发者_JS百科hen i loose to support the unicode formats and I also tried using CF_UNICODETEXT,it is not working either.. Please help me with this
void CCopyPAsteDlg::OnBnClickedPaste()
{
// TODO: Add your control notification handler code here
if (OpenClipboard())
{
if (::IsClipboardFormatAvailable(CF_TEXT)
|| ::IsClipboardFormatAvailable(CF_OEMTEXT))
{
HANDLE hClipboardData = GetClipboardData(CF_TEXT);
LPCTSTR pchData = new TCHAR[256];
pchData = (LPCTSTR)GlobalLock(hClipboardData);
CString strFromClipboard = pchData;
m_SetText.SetWindowText(strFromClipboard);
GlobalUnlock(hClipboardData);
}
else
{
//AfxMessageBox(L"There is no text (ANSI) data on the Clipboard.");
}
CloseClipboard();
}
}
void CCopyPAsteDlg::OnBnClickedCopy()
{
// TODO: Add your control notification handler code here
UpdateData();
CString strData;
m_GetText.GetWindowText(strData);
if (OpenClipboard())
{
EmptyClipboard();
HGLOBAL hClipboardData;
hClipboardData = GlobalAlloc(GMEM_DDESHARE,
strData.GetLength()+1);
LPCTSTR pchData = new TCHAR[256];
pchData = (LPCTSTR)GlobalLock(hClipboardData);
wcscpy((wchar_t*)pchData,strData);
GlobalUnlock(hClipboardData);
SetClipboardData(CF_TEXT,hClipboardData);
CloseClipboard();
}
}
Copy:
HGLOBAL hClipboardData = GlobalAlloc(GMEM_DDESHARE,
(strData.GetLength()+1)*sizeof(TCHAR));
LPCTSTR pchData = (LPCTSTR)GlobalLock(hClipboardData);
...
SetClipboardData(CF_UNICODETEXT,hClipboardData);
Paste:
HANDLE hClipboardData = GetClipboardData(CF_UNICODETEXT);
LPCTSTR pchData = (LPCTSTR)GlobalLock(hClipboardData);
精彩评论