您的位置:首页 > 其它

VS2013进程通讯-剪贴板

2015-12-02 13:41 330 查看

《VC++深入详解》17.1进程通信

I caught a problem when I want to copy something form program A to program B.

This is program A.

This is program B.

After I clicked The SEND button in program A.We can copy it in program B.But...

there is only one letter.
Here is the code in program A.
void CCaptionDlg::OnBnClickedBtnSend()
{
// TODO:  在此添加控件通知处理程序代码
if (OpenClipboard())//打开剪贴板
{

CString str;	//保存发送编辑框上的数据
HANDLE	hClip;	//保存调用GlobalAlloc函数后分配的内存对象的句柄
WCHAR*	pBuf;	//保存调用GlobalLock函数后返回的内存地址
CString buf;
EmptyClipboard();	//清空剪贴板上的数据
GetDlgItemText(IDC_EDIT_SEND, str);
hClip = GlobalAlloc(GMEM_MOVEABLE, str.GetLength() + 1);
pBuf = (WCHAR*)GlobalLock(hClip);
//http://www.cppblog.com/shongbee2/archive/2009/04/28/81349.html
//http://zhidao.baidu.com/link?url=1mAaN6rI_LYx2Cm9DHNBxXGpSq86OOianuDqQisjaZAtVko1Hjj55kSUv327GBww5lmlFDU2DJ2arKMz0rtg4_
int a=str.GetLength()+1;
wcscpy_s(pBuf,a , str);
GlobalUnlock(hClip);
SetClipboardData(CF_TEXT, hClip);
CloseClipboard();	//关闭剪贴板
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: