生活随笔
收集整理的這篇文章主要介紹了
进程间通信之剪切板
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
剪切板實現(xiàn)進程間兩個關(guān)鍵步驟
- 【1】寫數(shù)據(jù)到剪切板(進程1)
- 【2】從剪切板讀取數(shù)據(jù)(進程2)
進程1程序
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
int main()
{
if(OpenClipboard(NULL)){
string str =
"hello world";
cout<<
"要寫入剪切板上的數(shù)據(jù)為:"<<str<<endl;HANDLE hClip;
char *pBuf;EmptyClipboard();hClip=GlobalAlloc(GMEM_MOVEABLE,str.length()+
1);pBuf=(
char*)GlobalLock(hClip);
strcpy(pBuf,str.c_str());GlobalUnlock(hClip);SetClipboardData(CF_TEXT,hClip);CloseClipboard();}system(
"pause");
return 0;
}
進程2程序
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
int main()
{
if(OpenClipboard(NULL)){
if(IsClipboardFormatAvailable(CF_TEXT)){HANDLE hClip;
char *pBuf;hClip=GetClipboardData(CF_TEXT);pBuf=(
char*)GlobalLock(hClip);GlobalUnlock(hClip);CloseClipboard();
cout<<
"從剪切板上得到的數(shù)據(jù)是:"<<pBuf<<endl;}}system(
"pause");
return 0;
}
結(jié)果展示
總結(jié)
以上是生活随笔為你收集整理的进程间通信之剪切板的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。