home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HomeWare 14
/
HOMEWARE14.bin
/
os2
/
cenv2_19.arj
/
CLIPBRD.LIB
< prev
next >
Wrap
Text File
|
1994-03-08
|
5KB
|
130 lines
// ClibBrd.lib - Functions for reading from and writing to the Windows
// ver.1 clipboard.
//
// This library provides the following routines:
// 1) GetClipboardData(ClipboardDataFormat[,ClipboardDataSize])
// Copy data from the clipnoard, where:
// ClipboardDataFormat - one of the following data types
#define CF_TEXT 1
#define CF_BITMAP 2
#define CF_DSPTEXT 3
#define CF_DSPBITMAP 4
#define CF_METAFILE 5
#define CF_DSPMETAFILE 6
#define CF_PALETTE 9
// ClipboardDataSize - sets to the size of data returned; optional
// Returns: NULL if no data in clipboard or not of correct type, else
// returns data in buffer or BLOb of size ClipboardDataSize
//
// 2) PutClipboardData(ClipboardData,ClipboardDataSize,ClipboardDataFormat)
// Copy data to the clipboard, where:
// ClipboardData - buffer or BLOb of data to copy to the clipboard.
// If this is NULL then clipboard is emptied.
// ClipboardDataSize - size of data in ClipboardData, if this is zero
// then the clipboard is emptied
// ClipboardDataFormat - one of the data types #define'ed above
// Returns: True if data successfully copied, else False
GetClipboardData(ClipboardDataFormat,ClipboardDataSize)
{
_data = NULL; // assume failure
if ( OpenClipboard() ) {
#define ORD_WIN32QUERYCLIPBRDDATA 806
_CPDataPtr = PMDynamicLink("PMWIN",ORD_WIN32QUERYCLIPBRDDATA,BIT32,CDECL,
PMInfo().hab,ClipboardDataFormat);
if ( NULL != _CPDataPtr ) {
// query memory for how big _CPDataPtr is
BLObPut(lenBLOb,16384,UWORD32);
#define ORD_DOS32QUERYMEM 306
if ( 0 == PMDynamicLink("DOSCALLS",ORD_DOS32QUERYMEM,BIT32,CDECL,
_CPDataTextPtr,lenBLOb,flags) ) {
if ( 0 != (_len = BLObGet(lenBLOb,0,UWORD32)) ) {
_data = PMpeek(_CPDataPtr,_len);
if ( 1 < va_arg() )
ClipboardDataSize = _len;
}
}
}
CloseClipboard();
}
return(_data);
}
PutClipboardData(ClipboardData,ClipboardDataSize,ClipboardDataFormat)
{
bool PutClipSuccess = FALSE; // assume failure
if ( OpenClipboard() ) {
// empty clipboard of its current contents
#define ORD_WIN32EMPTYCLIPBRD 733
PMDynamicLink("PMWIN",ORD_WIN32EMPTYCLIPBRD,BIT32,CDECL,PMInfo().hab);
if ( NULL == ClipboardData || 0 == ClipboardDataSize ) {
// no data to put, so only needed to empty clipboard
PutClipSuccess = TRUE;
} else {
// allocate giveable shared memory, and copy this data to there
#define ORD_DOS32ALLOCSHAREDMEM 300
#define PAG_COMMIT 0x10
#define OBJ_GIVEABLE 0x200
#define PAG_WRITE 0x2
if ( 0 == PMDynamicLink("DOSCALLS",ORD_DOS32ALLOCSHAREDMEM,BIT32,CDECL,
_GiveMem,NULL,ClipboardDataSize,
PAG_COMMIT|OBJ_GIVEABLE|PAG_WRITE) ) {
PMpoke(_GiveMem,ClipboardData,ClipboardDataSize);
// finally, give this to the clipboard
#define ORD_WIN32SETCLIPBRDDATA 854
#define CFI_POINTER 0x0400
if ( PMDynamicLink("PMWIN",ORD_WIN32SETCLIPBRDDATA,BIT32,CDECL,
PMInfo().hab,_GiveMem,ClipboardDataFormat,CFI_POINTER) ) {
PutClipSuccess = True;
} else {
// error giving data to clipboad, and so must free it here
#define ORD_DOS32FREEMEM 304
PMDynamicLink("DOSCALLS",ORD_DOS32FREEMEM,BIT32,CDECL,_GiveMem);
}
}
}
CloseClipboard();
}
return PutClipSuccess;
}
/******* ROUTINES USED BY THE ABOVE FUNCTIONS *******/
// make sure clipboard gets closed before we exit
ClipboardIsOpen = FALSE;
atexit("CloseClipboardIfOpen");
CloseClipboardIfOpen()
{
if ( ClipboardIsOpen )
CloseClipboard();
}
OpenClipboard() // Return TRUE if open, else FALSE if cannot open
{
assert( !ClipboardIsOpen );
#define ORD_WIN32OPENCLIPBRD 793
if ( PMDynamicLink("PMWIN",ORD_WIN32OPENCLIPBRD,BIT32,CDECL,PMInfo().hab) )
ClipboardIsOpen = TRUE;
return( ClipboardIsOpen );
}
CloseClipboard() // close clipboard if we have it open
{
if ( ClipboardIsOpen ) {
#define ORD_WIN32CLOSECLIPBRD 707
assert( PMDynamicLink("PMWIN",ORD_WIN32CLOSECLIPBRD,BIT32,CDECL,PMInfo().hab) );
ClipboardIsOpen = FALSE;
}
}