Tools.h++ Class Reference

Table Of Contents
ostr << "Some text to be exchanged through the clipboard.\n";
ostr << "Might as well add a double: " << d << endl;
ostr.put('\0'); // Include the terminating null
// Lock the streambuf, get its handle:
HANDLE hMem = buf->str();
OpenClipboard(owner);
EmptyClipboard();
SetClipboardData(CF_TEXT, hMem);
CloseClipboard();
// Don't delete the buffer!. Windows is now responsible for it.
}
The owner of the clipboard is passed in as parameter "owner". A conventional ostream is created,
except that it uses an RWCLIPstreambuf as its associated streambuf. It can be used much like any
other ostream, such as cout, except that characters will be inserted into Windows global memory.
Some text and a double is inserted into the ostream. Finally, member function str() is called which
returns a Windows HANDLE. The clipboard is then opened, emptied, and the new data put into it
with format CF_TEXT which, in this case, is appropriate because a simple ostream was used to
format the output. If a specializing virtual streams class such as RWbostream or RWpostream had
been used instead, the format is not so simple. In this case, the user might want to register his or her
own format, using the Windows function RegisterClipboardFormat().
Public Constructors
RWCLIPstreambuf();
Constructs an empty RWCLIPstreambuf in dynamic mode. The results can be used anywhere
any other streambuf can be used. Memory to accomodate new characters will be allocated as
needed.
RWCLIPstreambuf(HANDLE hMem);
Constructs an RWCLIPstreambuf in static mode, using the memory block with global handle
hMem. The effect of gets and puts beyond the size of this memory block is unspecified.
Public Destructor
~RWCLIPstreambuf();
If member function str() has not been called, the destructor unlocks the handle and, if in
dynamic mode, also frees it.