1、剪切板模式、

在MFC里新建两个文本框和两个按钮,点击发送按钮相当于复制文本框1的内容,点击接收按钮相当于粘贴到文本框2内;

C++进程间通讯方式-LMLPHP

发送和接收按钮处功能实现如下:

void CClipboard2Dlg::OnBnClickedBtSend()
{ if (OpenClipboard()) //发送复制
{
CString str;
HANDLE hClip;
char *pbuf;
EmptyClipboard();
GetDlgItemText(IDC_EDIT_Send,str);
hClip = GlobalAlloc(GMEM_MOVEABLE,str.GetLength()+1);
pbuf = (char*)GlobalLock(hClip);
strcpy(pbuf,str);
GlobalUnlock(hClip);
SetClipboardData(CF_TEXT, hClip);
CloseClipboard();
}
} void CClipboard2Dlg::OnBnClickedBtRecv()
{ if (OpenClipboard()) //接收粘贴
{
if (IsClipboardFormatAvailable(CF_TEXT))
{
HANDLE hClip;
char *pbuf;
hClip = GetClipboardData(CF_TEXT);
pbuf = (char*)GlobalLock(hClip);
GlobalUnlock(hClip);
SetDlgItemText(IDC_EDIT_Recv, pbuf);
CloseClipboard();
} }
}

  

05-26 16:15