home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / WINFRN.ZIP / OPWINFRN.PAS
Encoding:
Pascal/Delphi Source File  |  1992-08-29  |  5.4 KB  |  229 lines

  1. {$IFDEF Windows}
  2.   !! This unit is intended for DOS apps !!
  3. {$ENDIF}
  4.  
  5. {$IFDEF Ver55}
  6.   !! This unit requires TP version 6 or later !!
  7. {$ENDIF}
  8.  
  9. {*************************************************}
  10. {*               OPWINFRN.PAS 1.00               *}
  11. {*      Copyright TurboPower Software 1992       *}
  12. {*************************************************}
  13.  
  14. unit OpWinFrn;   {"Windows-friendly" support tools for DOS programs}
  15.  
  16. interface
  17.  
  18. type
  19.   {Windows 3.x types: not installed, running Real/Std mode, running Enhanced}
  20.   Win3ModeType = (NoWin, RealStd, Enhanced);
  21.  
  22. type
  23.   {record for DPMI version number}
  24.   DPMIVersRec =
  25.     record
  26.       Major, Minor : Word;
  27.     end;
  28.  
  29. const
  30.   {format codes for clipboard data types}
  31.   wcb_Text     = 1;
  32.   wcb_Bitmap   = 2;
  33.   wcb_MetaFile = 3;
  34.   wcb_SYLK     = 4;
  35.   wcb_DIF      = 5;
  36.   wcb_TIFF     = 6;
  37.  
  38. var
  39.   DPMIVers : DPMIVersRec;
  40.   WindowsMode : Win3ModeType;
  41.  
  42.   {Windows detection and sharing services...}
  43.  
  44. function CheckWin3 : Win3ModeType;
  45.   {-Determines whether Windows is running and, if so, what version}
  46. function CheckWinOldApp : Boolean;
  47.   {-Determines whether the WINOLDAPP services are available}
  48. procedure GetDPMIVers;
  49.   {-Get the version info for the current DPMI server}
  50. procedure ReleaseTimeSlice;
  51.   {-Give up the current time slice; typically called in keybrd wait loops.  If
  52.     your program has sections that sit in loops performing complex processing,
  53.     calling this service periodically will improve Windows' response to both
  54.     it and other running programs.  This is especially critical in comm program
  55.     terminal loops and other loops that check KeyPressed each time through the
  56.     loop.}
  57. procedure BeginCriticalSection;
  58.   {-Tell Windows that your process cannot be sliced out.  WARNING: Do *NOT*
  59.     use this service unless your section *really* is critical, and then only
  60.     for the shortest possible time!}
  61. procedure EndCriticalSection;
  62.   {-Tell Windows that you are finished with the critical code section}
  63.  
  64.  
  65.   {Windows clipboard data transfer tools...}
  66.  
  67. function OpenClipboard : Boolean;
  68.   {-Open clipboard; returns TRUE if clipboard available, FALSE otherwise}
  69. procedure CloseClipboard;
  70.   {-Release clipboard when finished with it.  Never leave the clipboard open
  71.     longer than absolutely nessessary.}
  72. function ClearClipboard : Boolean;
  73.   {-Clear the contents of the clipboard}
  74. function GetClipboardDataSize(Format : Word) : LongInt;
  75.   {-Returns the number of bytes needed to hold the contents of the clipboard}
  76. function GetClipboardData(Format : Word; var Buffer) : Boolean;
  77.   {-Gets the clipboard's contents.  Buffer must be large enough to hold
  78.     GetClipboardDataSize bytes.}
  79. function PutClipboardData(Format, BufLen : Word; var Buffer) : Boolean;
  80.   {-Put the contents of Buffer onto the clipboard.}
  81.  
  82. implementation
  83.  
  84.   function CheckWin3 : Win3ModeType;  Assembler;
  85.   asm
  86.     mov    ax,1600h
  87.     int    2Fh
  88.     cmp    al,1
  89.     jbe    @@CheckRealStd
  90.     cmp    al,80h
  91.     jae    @@CheckRealStd
  92.     mov    al,2
  93.     jmp    @@ExitPoint
  94. @@CheckRealStd:
  95.     mov    ax,4680h
  96.     int    2Fh
  97.     or     ax,ax
  98.     jnz    @@NotWin
  99.     mov    al,1
  100.     jmp    @@ExitPoint
  101. @@NotWin:
  102.     xor    al,al
  103. @@ExitPoint:
  104.   end;
  105.  
  106.   function CheckWinOldApp : Boolean; Assembler;
  107.   asm
  108.     mov    ax,1700h
  109.     int    2Fh
  110.     cmp    ax,1700h
  111.     jne    @@Yes
  112.     xor    al,al
  113.     jmp    @@Done
  114. @@Yes:
  115.     mov    al,1
  116. @@Done:
  117.   end;
  118.  
  119.   procedure ReleaseTimeSlice; Assembler;
  120.   asm
  121.     mov    ax,1680h
  122.     int    2Fh
  123.   end;
  124.  
  125.   procedure BeginCriticalSection; Assembler;
  126.   asm
  127.     mov    ax,1681h
  128.     int    2Fh
  129.   end;
  130.  
  131.   procedure EndCriticalSection; Assembler;
  132.   asm
  133.     mov    ax,1682h
  134.     int    2Fh
  135.   end;
  136.  
  137.   function OpenClipboard : Boolean; Assembler;
  138.   asm
  139.     mov    ax,1701h
  140.     int    2Fh
  141.     cmp    ax,0
  142.     je     @@Done
  143.     mov    ax,1
  144. @@Done:
  145.   end;
  146.  
  147.   procedure CloseClipboard; Assembler;
  148.   asm
  149.     mov    ax,1708h
  150.     int    2Fh
  151.     xor    ax,ax
  152.   end;
  153.  
  154.   function ClearClipboard : Boolean; Assembler;
  155.   asm
  156.     mov    ax,1702h
  157.     int    2Fh
  158.     cmp    ax,0
  159.     je     @@Done
  160.     mov    ax,1
  161. @@Done:
  162.   end;
  163.  
  164.   function GetClipboardDataSize(Format : Word) : LongInt; Assembler;
  165.   asm
  166.     mov    ax,1704h
  167.     mov    dx,Format
  168.     int    2Fh
  169.   end;
  170.  
  171.   function GetClipboardData(Format : Word; var Buffer) : Boolean; Assembler;
  172.   asm
  173.     mov    ax,1705h
  174.     les    di,Buffer
  175.     mov    bx,di
  176.     mov    dx,Format
  177.     int    2Fh
  178.     cmp    ax,0
  179.     je     @@Done
  180.     mov    ax,1
  181. @@Done:
  182.   end;
  183.  
  184.   function PutClipboardData(Format, BufLen : Word; var Buffer) : Boolean; Assembler;
  185.   asm
  186.     mov    ax,1703h
  187.     mov    dx,Format
  188.     les    di,Buffer
  189.     mov    bx,di
  190.     mov    cx,BufLen
  191.     xor    si,si
  192.     int    2Fh
  193.     cmp    ax,0
  194.     je     @@Done
  195.     mov    ax,1
  196. @@Done:
  197.   end;
  198.  
  199.   function DPMIPresent : Boolean; Assembler;
  200.   asm
  201.     mov    ax,1687h
  202.     int    2Fh
  203.     not    ax
  204.   end;
  205.  
  206.   procedure GetDPMIVers; Assembler;
  207.   asm
  208.     mov    ax,1686h
  209.     int    2Fh
  210.     cmp    ax,0
  211.     jne    @@Done
  212.     mov    ax,0400h
  213.     int    31h
  214.     mov    bx,ax
  215.     xchg   bh,bl
  216.     xor    bh,bh
  217.     xor    ah,ah
  218.     mov    DPMIVers.Major,bx
  219.     mov    DPMIVers.Minor,ax
  220. @@Done:
  221.   end;
  222.  
  223. begin
  224.   FillChar(DPMIVers, SizeOf(DPMIVers), 0);
  225.   WindowsMode := CheckWin3;
  226.   if DPMIPresent then
  227.     GetDPMIVers;
  228. end.
  229.