home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / winclipb.c < prev    next >
C/C++ Source or Header  |  1993-10-14  |  6KB  |  184 lines

  1. /*
  2.  * File......: WINCLIPB.C
  3.  * Author....: Dave Pearson
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Dave Pearson
  7.  * Date......: 24/03/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Dave Pearson and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20. // NOTE: This code has been written for and compiled with Borland C++
  21. //       Version 3.1
  22. //
  23.  
  24. #include "gt_mem.h"
  25. #include <Extend.H>
  26.  
  27. Boolean _ClipboardIsHere(void);
  28. Boolean _OpenClipboard(void);
  29. void    _CloseClipboard(void);
  30.  
  31. /*  $DOC$
  32.  *  $FUNCNAME$
  33.  *      GT_CBPASTE()
  34.  *  $CATEGORY$
  35.  *      Windows
  36.  *  $ONELINER$
  37.  *      Place text into the MS Windows clipboard.
  38.  *  $SYNTAX$
  39.  *      GT_CBPaste(<cText>) --> lPasted
  40.  *  $ARGUMENTS$
  41.  *      <cText> is the text to place into the Windows clipboard.
  42.  *  $RETURNS$
  43.  *      A logical value, .T. if the text was pasted, .F. if not.
  44.  *  $DESCRIPTION$
  45.  *      GT_CBPaste() can be used to place text into the Windows clipboard
  46.  *      when your application is running in a DOS window.
  47.  *
  48.  *      If the text is pasted into the clipboard the function will return
  49.  *      true (.T.), if not, it will return false (.F.). For the function
  50.  *      to fail to paste one of the following has to happen:
  51.  *
  52.  *              a) The application is not running under MS Windows.
  53.  *              b) The DOS paste service is not available.
  54.  *              c) The clipboard could not be opened.
  55.  *
  56.  *      The information used to write this function was taken from ``Hands
  57.  *      On - Low Level'' in Personal Computer World - December 1992, Page
  58.  *      451. This article states that there is a problem using the
  59.  *      described method with Windows 3.1. I have tested this function with
  60.  *      Windows 3.1 and Windows For Workgroups and it appears to work
  61.  *      fine.
  62.  *
  63.  *  $EXAMPLES$
  64.  *
  65.  *      // Function to take a customers address details and paste them
  66.  *      // Into the Windows clipboard.
  67.  *
  68.  *      #define CR_LF   chr(13)+chr(10)
  69.  *
  70.  *      function AddresToClip()
  71.  *      if GT_CBPaste(alltrim(Customer->Address1)+CR_LF+;
  72.  *                    alltrim(Customer->Address2)+CR_LF+;
  73.  *                    alltrim(Customer->Address3)+CR_LF+;
  74.  *                    alltrim(Customer->Address4)+CR_LF+;
  75.  *                    alltrim(Customer->Address5)+CR_LF)
  76.  *
  77.  *         // Tell the user that it worked.
  78.  *
  79.  *      else
  80.  *
  81.  *        // Tell the user that it didn't work.
  82.  *
  83.  *      endif
  84.  *      return(NIL)
  85.  *
  86.  *  $END$
  87.  */
  88.  
  89. CLIPPER GT_CBPaste()
  90. {
  91.         char    *Text;
  92.         int     Size;
  93.         int     SegText;
  94.         int     OffText;
  95.         int     HiSize;
  96.         int     LoSize;
  97.         Boolean Ok = FALSE;
  98.  
  99.         if (PCOUNT >= 1 && ISCHAR(1))
  100.         {
  101.                 if (_ClipboardIsHere())
  102.                 {
  103.                         if (_OpenClipboard())
  104.                         {
  105.                                 Text    = _parc(1);
  106.                                 SegText = _GT_FP_SEG(Text);
  107.                                 OffText = _GT_FP_OFF(Text);
  108.                                 Size    = _parclen(1);
  109.                                 HiSize  = _GT_FP_SEG(Size);
  110.                                 LoSize  = _GT_FP_OFF(Size);
  111.  
  112.                                 asm     mov     DX,01h
  113.                                 asm     mov     ES,SegText
  114.                                 asm     mov     BX,OffText
  115.                                 asm     mov     SI,HiSize
  116.                                 asm     mov     CX,LoSize
  117.                                 asm     mov     AX,1703h
  118.                                 asm     int     2Fh
  119.                                 Ok = (_AX != 0);
  120.                                 _CloseClipboard();
  121.                         }
  122.                 }
  123.         }
  124.         _retl(Ok);
  125. }
  126.  
  127. /*****************************************************************************
  128. * Function: _ClipboardIsHere()                                               *
  129. * Syntax..: Boolean _ClipboardIsHere(void)                                   *
  130. * Usage...: Internal function to check if Windows is running and if we can   *
  131. * ........: talk to the Clipboard.                                           *
  132. * By......: David A Pearson                                                  *
  133. *****************************************************************************/
  134.  
  135. static Boolean _ClipboardIsHere(void)
  136. {
  137.         Boolean Ok = TRUE;
  138.  
  139.         asm     mov     AX,1600h
  140.         asm     int     2Fh
  141.         asm     test    AL,7Fh
  142.         asm     jnz     WinFound
  143.         asm     mov     AX,4680h
  144.         asm     int     2Fh
  145.         asm     or      ax,ax
  146.         asm     jz      WinFound
  147.         Ok = FALSE;
  148. WinFound:
  149.         if (Ok)
  150.         {
  151.                 asm     mov     AX,1700h
  152.                 asm     int     2Fh
  153.                 Ok = (_AX != 0x1700);
  154.         }
  155.         return(Ok);
  156. }
  157.  
  158. /*****************************************************************************
  159. * Function: _OpenClipboard()                                                 *
  160. * Syntax..: Boolean _OpenClipboard(void)                                     *
  161. * Usage...: Internal function to open the clipboard.                         *
  162. * By......: David A Pearson                                                  *
  163. *****************************************************************************/
  164.  
  165. static Boolean _OpenClipboard(void)
  166. {
  167.         asm     mov     AX,1701h
  168.         asm     int     2Fh
  169.         return(_AX != 0);
  170. }
  171.  
  172. /*****************************************************************************
  173. * Function: _CloseClipboard()                                                *
  174. * Syntax..: Boolean _CloseClipboard(void)                                    *
  175. * Usage...: Internal function to close the clipboard.                        *
  176. * By......: David A Pearson                                                  *
  177. *****************************************************************************/
  178.  
  179. static void _CloseClipboard(void)
  180. {
  181.         asm     mov     AX,1708h
  182.         asm     int     2Fh
  183. }
  184.