1. 程式人生 > >使用WindowsAPI置剪貼簿文字

使用WindowsAPI置剪貼簿文字

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
	HGLOBAL hGlobal;
	wchar_t* pString = L"中華人民共和國萬歲萬萬歲!";
	wchar_t* pGlobal;

	hGlobal = GlobalAlloc(GHND | GMEM_SHARE, (lstrlen(pString) + 1) * sizeof(wchar_t));

	pGlobal = (wchar_t*)GlobalLock(hGlobal);

	lstrcpy(pGlobal, pString);

	GlobalUnlock(hGlobal);

	OpenClipboard(GetDesktopWindow());
	EmptyClipboard();

	SetClipboardData(CF_UNICODETEXT, hGlobal);
	CloseClipboard();
	return 0;
}