void CClipeDlg::OnButton1() //发送数据
{
// TODO: Add your control notification handler code here
if(OpenClipboard())
{
EmptyClipboard();
HANDLE handle;
char* buf;
CString str;
GetDlgItemText(IDC_EDIT_CUT,str);
handle=GlobalAlloc(GMEM_MOVEABLE,str.GetLength()+1);
buf=(char*)GlobalLock(handle);
strcpy(buf,str);
GlobalUnlock(handle);
SetClipboardData(CF_TEXT,handle);
CloseClipboard();
}
}void CClipeDlg::OnButton2() //接收数据
{
// TODO: Add your control notification handler code here
if(IsClipboardFormatAvailable(CF_TEXT))
{
HANDLE handle;
char* pbuf;
handle=GetClipboardData(CF_TEXT);
pbuf=(char*)GlobalLock(handle);
GlobalUnlock(handle);
SetDlgItemText(IDC_EDIT_RD,pbuf);
CloseClipboard();
}
}
为什么最后接收数据的时候,pbuf是空啊?
{
// TODO: Add your control notification handler code here
if(OpenClipboard())
{
EmptyClipboard();
HANDLE handle;
char* buf;
CString str;
GetDlgItemText(IDC_EDIT_CUT,str);
handle=GlobalAlloc(GMEM_MOVEABLE,str.GetLength()+1);
buf=(char*)GlobalLock(handle);
strcpy(buf,str);
GlobalUnlock(handle);
SetClipboardData(CF_TEXT,handle);
CloseClipboard();
}
}void CClipeDlg::OnButton2() //接收数据
{
// TODO: Add your control notification handler code here
if(IsClipboardFormatAvailable(CF_TEXT))
{
HANDLE handle;
char* pbuf;
handle=GetClipboardData(CF_TEXT);
pbuf=(char*)GlobalLock(handle);
GlobalUnlock(handle);
SetDlgItemText(IDC_EDIT_RD,pbuf);
CloseClipboard();
}
}
为什么最后接收数据的时候,pbuf是空啊?
剪贴板都还没打开:
OpenClipboard();
{
EmptyClipboard();
HANDLE handle;
char* buf;
CString str;
GetDlgItemText(IDC_EDIT_CUT,str);
handle=GlobalAlloc(GMEM_MOVEABLE,str.GetLength()+1);
buf=(char*)GlobalLock(handle);
strcpy(buf,str);
GlobalUnlock(handle);
SetClipboardData(CF_TEXT,handle);
CloseClipboard();//把这句话去掉就可以了~~~
}
你自己试试看,应该可以了~~~
OpenClipboard()你在那里调用了,自杀