Clipboard

Is there anyway to access the clipboard with c++?
Operating System?
Windows Xp, Professional, SP 2

And thanks for help in advance :)
Last edited on
Here's a list of clipboard-related functions:
http://msdn2.microsoft.com/en-us/library/ms674556(VS.85).aspx
SetClipboardData() looks like it might be useful...
disclaimer: I got this off of a Google search. I have no idea how it works.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//clipboardwriter.cpp - writes "hello" to your clipboard
#include <windows>

int main(){
	HGLOBAL hText;
	char *pText;
	hText = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE, 100);
	pText = (char*)GlobalLock(hText);
	strcpy(pText, "hello");
	GlobalUnlock(hText);

	OpenClipboard(NULL);
	EmptyClipboard();
	SetClipboardData(CF_TEXT, hText);
	CloseClipboard();
}


This one, I do understand. Except for GlobalLock().
1
2
3
4
5
6
7
8
9
10
11
//clipboardreader.cpp- reads text from your clipboard
#include <windows>
#include <iostream>

int main(){
	OpenClipboard(NULL);
	HANDLE foo = GetClipboardData(CF_TEXT);
	CloseClipboard();
	LPVOID lptstr = GlobalLock(foo);
	std::cout << (char *)lptstr;
}
Topic archived. No new replies allowed.