home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
CLPPASTE.ZIP
/
CLP2FILE.C
< prev
next >
Wrap
Text File
|
1991-02-06
|
2KB
|
66 lines
/*
* CLP2FILE take text from clipboard and put into a file
*/
#define INCL_WIN
#define INCL_GPI
#define INCL_DOS
#define INCL_DOSSESMGR
#define NUL '\0'
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
cdecl main( VOID )
{
HAB hab; /* handle to anchor block */
HMQ hmq; /* handle to message queue */
SEL selClipText;
CHAR *pchText;
PCHAR pchClipText=NULL;
USHORT usLen,usIndex,usfmtInfo;
SHORT exitcode;
FILE *fp;
/* initialize thread & create message queue */
hab = WinInitialize( 0 );
hmq = WinCreateMsgQueue( hab, 0 );
if (WinOpenClipbrd(hab))
{
WinQueryClipbrdFmtInfo(hab,CF_TEXT,(PUSHORT)&usfmtInfo);
selClipText = (SEL)WinQueryClipbrdData(hab,CF_TEXT);
if (selClipText)
{
pchClipText = MAKEP(selClipText,0);
// usLen = strlen(pchClipText);
for(usLen = 0;pchClipText[usLen];usLen++);
pchText = malloc (usLen +1);
for(usIndex = 0;usIndex < usLen +1;usIndex++)
{
pchText[usIndex] = pchClipText[usIndex];
}
fp=fopen("clip.out","w+");
fputs(pchText,fp);
fclose(fp);
free(pchText);
exitcode=0;
// exit with a 0 if all ok
}
else
// exit with a 2 if clipboard contains other than text data
exitcode=2;
}
else
// exit with a 3 if cannot open clipboard
exitcode=3;
WinCloseClipbrd(hab);
WinDestroyMsgQueue(hmq);
return(exitcode);
}