home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / cenvid / winclip.lib < prev    next >
Encoding:
Text File  |  1995-09-27  |  8.4 KB  |  279 lines

  1. // WinClip.lib - Functions for reading from and writing
  2. // ver.1         to the Windows clipboard from DOS.
  3. //
  4. //**** GetClipboardText() Read text string from Windows clipboard
  5. // SYNTAX: string GetClipboardText()
  6. // RETURN: NULL if cannot find or retrieve clipboard text, else return
  7. //         null-terminated string of clipboard data
  8. //
  9. //
  10. //**** PutClipboardText() Write text string to the Windows clipboard
  11. // SYNTAX: bool PutClipboardText(string Text)
  12. // WHERE: Text: null-terminated string to write to clipboard; or NULL
  13. //        to delete the contents of the clipboard
  14. //
  15.  
  16. if !defined(_DOS_)
  17.    printf("\n\a\aWinClip must execute from CEnviD for DOS.\n"),
  18.    exit(EXIT_FAILURE);
  19.  
  20. ClipboardAvailable() // return True if functions available, else False
  21. {
  22.    RegIn.ax = 0x1700;
  23.    interrupt(0x2f,RegIn,RegOut);
  24.    if ( RegOut.ax == 0x1700 ) {
  25.       printf("\nClipboard functions not available\n");
  26.       return False;
  27.    }
  28.    return True;
  29. }
  30.  
  31. OpenClipboard() // return True for success, else False
  32. {
  33.    RegIn.ax = 0x1701;
  34.    interrupt(0x2F,RegIn,RegOut);
  35.    if ( RegOut.ax == 0 ) {
  36.       printf("\nUnable to open clipboard.\n");
  37.       return False;
  38.    }
  39.    return True;
  40. }
  41.  
  42. CloseClipboard() // return True for success, else False
  43. {
  44.    RegIn.ax = 0x1708;
  45.    interrupt(0x2F,RegIn,RegOut);
  46.    if ( RegOut.ax == 0 ) {
  47.       printf("\nUnable to open clipboard.\n");
  48.       return False;
  49.    }
  50.    return True;
  51. }
  52.  
  53. GetClipboardDataSize(pType) // return size of data in clipboard; 0 if none
  54. {
  55.    RegIn.ax = 0x1704;
  56.    RegIn.dx = pType;
  57.    interrupt(0x2F,RegIn,RegOut);
  58.    return ( RegOut.ax | (RegOut.dx << 16) );
  59. }
  60.  
  61. GetClipboardData(pBuf,pType)  // assume that pBuf is big enough
  62. {
  63.    RegIn.ax = 0x1705;
  64.    RegIn.dx = pType;
  65.    if !defined(_DOS32_)
  66.       RegIn.es = segment(pBuf), RegIn.bx = offset(pBuf);
  67.    else
  68.       RegIn.bx = pointer(pBuf);
  69.    interrupt(0x2F,RegIn,RegOut);
  70.    if ( 0 == RegOut.ax ) {
  71.       printf("\nError on GetClipboardData\n");
  72.       return False;
  73.    }
  74.    return True;
  75. }
  76.  
  77. GetClipboardText()
  78. {
  79.    lText = NULL; // assume failure
  80.    if ( ClipboardAvailable() && OpenClipboard() ) {
  81.       if ( lClipboardSize = GetClipboardDataSize(1) ) {
  82.          undefine(lText);
  83.          lText[lClipboardSize] = '\0';
  84.          if ( !GetClipboardData(lText,1) )
  85.             lText = NULL;
  86.          else
  87.             SetArraySpan(lText,strlen(lText));
  88.       }
  89.       CloseClipboard();
  90.    }
  91.    return lText;
  92. }
  93.  
  94. EmptyClipboard()
  95. {
  96.    RegIn.ax = 0x1702;
  97.    interrupt(0x2F,RegIn,RegOut);
  98.    if ( RegOut.ax == 0 ) {
  99.       printf("\Error on EmptyClipboard()\n");
  100.       return False;
  101.    }
  102.    return True;
  103. }
  104.  
  105. ClipboardCompact(pSize)
  106. {
  107.    RegIn.ax = 0x1702;
  108.    RegIn.si = (pSize >> 16 & 0xFFFF); RegIn.cx = pSize & 0xFFFF;
  109.    interrupt(0x2F,RegIn,RegOut);
  110.    return ( RegOut.ax | (RegOut.dx << 16) );
  111. }
  112.  
  113. SetClipboardData(pBuf,pBufSize,pType)
  114. {
  115.    RegIn.ax = 0x1703;
  116.    RegIn.dx = pType;
  117.    if !defined(_DOS32_)
  118.       RegIn.es = segment(pBuf), RegIn.bx = offset(pBuf);
  119.    else
  120.       RegIn.bx = pointer(pBuf);
  121.    RegIn.si = (pBufSize >> 16 & 0xFFFF); RegIn.cx = pBufSize & 0xFFFF;
  122.    interrupt(0x2F,RegIn,RegOut);
  123.    if ( RegOut.ax == 0 ) {
  124.       printf("\Error on SetClipboardData()\n");
  125.       return False;
  126.    }
  127.    return True;
  128. }
  129.  
  130. PutClipboardText(pText)
  131. {
  132.    lSuccess = False; // assume failure
  133.    if ( ClipboardAvailable() && OpenClipboard() ) {
  134.       if ( EmptyClipboard() ) {
  135.          if ( !pText ) {
  136.             lSuccess = True;
  137.          } else {
  138.             lTextLen = strlen(pText);
  139.             if ( ClipboardCompact(lTextLen+1)
  140.               && SetClipboardData(pText,lTextLen+1,1) ) {
  141.                lSuccess = True;
  142. }
  143.          }
  144.       }
  145.       CloseClipboard();
  146.    }
  147.    return lSuccess;
  148. }
  149.  
  150. //Parameters      AX = 1704H
  151. //                DX = WinOldAp-Supported Clipboard format
  152. //Return Values   DX:AX == Size of the data in bytes, including any
  153. //                         headers.
  154. //                      == 0 If data in this format is not in the clipboard.
  155. //
  156. //Name            IdentifyWinOldApVersion()
  157. //Parameters      AX = 1700H
  158. //Return Values   AX == 1700H: Clipboard functions not available
  159. //                   <> 1700H: AL = Major version number
  160. //                             AH = Minor version number
  161. //
  162. //Name            OpenClipboard()
  163. //Parameters      AX = 1701H
  164. //Return Values   AX == 0: Clipboard already open
  165. //                   <> 0: Clipboard opened
  166. //
  167. //Name            EmptyClipboard()
  168. //Parameters      AX = 1702H
  169. //Return Values   AX == 0: Error occurred
  170. //                   <> 0: OK, Clipboard emptied
  171. //
  172. //Name            SetClipboardData()
  173. //Parameters      AX = 1703H
  174. //                DX = WinOldAp-Supported Clipboard format
  175. //                ES:BX = Pointer to data
  176. //                SI:CX = Size of data in bytes
  177. //Return Values   AX == 0: Error occurred
  178. //                   <> 0: OK.  Data copied into allocated memory.
  179. //Note            The MS-DOS application should call the
  180. //                ClipboardCompact() function prior to this to determine
  181. //                if the data can be accommodated in memory.
  182. //
  183. //Name            GetClipboardDataSize()
  184. //Parameters      AX = 1704H
  185. //                DX = WinOldAp-Supported Clipboard format
  186. //Return Values   DX:AX == Size of the data in bytes, including any
  187. //                         headers.
  188. //                      == 0 If data in this format is not in the clipboard.
  189. //
  190. //Name            GetClipboardData()
  191. //Parameters      AX = 1705H
  192. //                DX = WinOldAp-Supported Clipboard format
  193. //                ES:BX = Pointer to data buffer to hold data
  194. //Return Values   AX == 0: Error occurred (or data in this format is not
  195. //                         in the clipboard)
  196. //                   <> 0: OK
  197. //Note           This call should be preceded by a
  198. //               GetClipBoardDataSize() call to find out how much memory
  199. //               is required for the buffer. No checking is performed, the
  200. //
  201. //               caller must ensure that the buffer is big enough;
  202. //               otherwise, some of the callers code or data may be
  203. //               overwritten.
  204. //
  205. //Name            CloseClipboard()
  206. //Parameters      AX = 1708H
  207. //Return Values   AX == 0: Error occurred
  208. //                   <> 0: OK
  209. //
  210. //
  211. //Name            ClipboardCompact()
  212. //Parameters      AX = 1709H
  213. //                SI:CX = Desired memory size in bytes.
  214. //Return Values   DX:AX == Number of bytes of largest block of free memory.
  215. //                      == 0 if error or no memory
  216. //Notes           The MS-DOS application is responsible for including the
  217. //                size of any headers in the desired memory size.
  218. //
  219. //
  220. //
  221. //Name            GetDeviceCaps()
  222. //Parameters      AX = 170AH
  223. //                DX = GDI information index
  224. //Return Values   AX == integer value of desired item
  225. //                   == 0 if error
  226. //Notes           The implied hDC for this call will be for the display.
  227. //
  228. //
  229. //
  230. //Supported Clipboard Formats
  231. //---------------------------
  232. //
  233. //
  234. //
  235. //The following Windows clipboard formats are supported:
  236. //
  237. //
  238. //
  239. //   CF_TEXT         = 1
  240. //   CF_BITMAP       = 2         ; See structures section
  241. //   CF_OEMTEXT      = 7
  242. //   CF_DSPTEXT      = 81h
  243. //   CF_DSPBITMAP    = 82h
  244. //Note: Since the RegisterClipboardFormat() and EnumClipboardFormats()
  245. //      functions are not available at this time, the use of private
  246. //      clipboard formats is not supported.
  247. //Structures
  248. //----------
  249. //
  250. //
  251. //
  252. //These structures mimic the actual Windows structures with one major
  253. //difference: instead of including a handle or pointer to other memory
  254. //containing the actual data, the data follows the structure. The
  255. //structure information now behaves like a header prefacing the data.
  256. //
  257. //
  258. //
  259. //Bitmap structure:
  260. //
  261. //
  262. //
  263. //   bmType          DW      ?   ; Always 0
  264. //   bmWidth         DW      ?   ; Width of bitmap in pixels
  265. //   bmHeight        DW      ?   ; Height of bitmap in raster lines
  266. //   bmWidthBytes    DW      ?   ; Bytes/raster line
  267. //   bmPlanes        DB      ?   ; Number of color planes in the bitmap
  268. //   bmBitsPixel     DB      ?   ; Number of adj color bits to def pixel
  269. //   bmBits          DQ      ?   ; Points to byte following bmHigDim
  270. //   bmWidDim        DW      ?   ; Width of bitmap in 0.1 mm units
  271. //
  272. //   bmHigDim        DW      ?   ; Height of bitmap in 0.1 mm units
  273. //   BitmapData      nBytes      ; The actual data
  274. //
  275. //
  276. //
  277. //#:x218a
  278. //
  279.