home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2BAS.ZIP / WINATOM.BAS < prev    next >
BASIC Source File  |  1989-08-27  |  6KB  |  173 lines

  1. '************************************************************************
  2. '* 
  3. '* Program Name: WinAtom.BAS
  4. '*
  5. '* Include File: WinMisc.BI
  6. '*
  7. '* Functions   :
  8. '*               WinCreateAtomTable
  9. '*               WinDestroyAtomTable
  10. '*               WinAddAtom
  11. '*               WinFindAtom
  12. '*               WinDeleteAtom
  13. '*               WinQueryAtomLenght
  14. '*               WinQueryAtomName
  15. '*               WinQuerySystemAtomTable
  16. '*
  17. '* Description : This program demonstrates how to use an atom table
  18. '*               Since these functions have no visible effect, the
  19. '*               information is written to a data file ("WinAtom.OUT").
  20. '*               Atom tables can be useful in reducing your string space
  21. '*               usage by storing strings as two-byte atoms.
  22. '************************************************************************
  23.  
  24. '*********         Initialization section        ***********
  25.  
  26. REM $INCLUDE: 'PMBase.BI'
  27. REM $INCLUDE: 'WinMisc.BI'
  28.  
  29. CONST KByte = 1024
  30.  
  31. DIM aqmsg AS QMSG
  32.  
  33. flFrameFlags& =  FCFTITLEBAR      OR FCFSYSMENU OR _
  34.                  FCFSIZEBORDER    OR FCFMINMAX  OR _
  35.                  FCFSHELLPOSITION OR FCFTASKLIST
  36.  
  37. szClientClass$ = "ClassName" + CHR$(0)
  38.  
  39. hab&  = WinInitialize    (0)
  40. hmq&  = WinCreateMsgQueue(hab&, 0)
  41.  
  42. bool% = WinRegisterClass(_
  43.         hab&,_
  44.         MakeLong(VARSEG(szClientClass$), SADD(szClientClass$)),_
  45.         RegBas,_
  46.         0,_
  47.         0)
  48.  
  49. hwndFrame& = WinCreateStdWindow (_
  50.              HWNDDESKTOP,_
  51.              WSVISIBLE,_
  52.              MakeLong (VARSEG(flFrameFlags&),  VARPTR(flFrameFlags&)),_
  53.              MakeLong (VARSEG(szClientClass$), SADD(szClientClass$)),_
  54.              0,_
  55.              0,_
  56.              0,_
  57.              0,_            'Optional: Specify Resource ID here
  58.              MakeLong (VARSEG(hwndClient&), VARPTR(hwndClient&)))
  59.  
  60. '**************       WinAtom        **************
  61.  
  62. OPEN "WinAtom.OUT" FOR OUTPUT AS #1
  63.  
  64. FirstAtom$  = "This is a very long first atom which will be stored as 2 bytes" + CHR$(0)
  65. SecondAtom$ = "This is a second atom which will also be stored as 2 bytes" + CHR$(0)
  66.  
  67. ' Creating 32K Atom table:
  68.       HAtom&  =  WinCreateAtomTable (32 * KByte, 0)
  69.       PRINT #1, "WinCreateAtomTable:", HEX$(HAtom&)
  70.  
  71. ' Adding Atoms to Atom table:
  72.       Atom1% = WinAddAtom (HAtom&,_
  73.            MakeLong(VARSEG(FirstAtom$), SADD(FirstAtom$)))
  74.       PRINT #1, "WinAddAtom:", HEX$(Atom1%)
  75.       PRINT #1, FirstAtom$
  76.  
  77.       Atom2% = WinAddAtom (HAtom&,_
  78.            MakeLong(VARSEG(SecondAtom$), SADD(SecondAtom$)))
  79.       PRINT #1, "WinAddAtom is ", HEX$(Atom2%)
  80.       PRINT #1, SecondAtom$
  81.  
  82. ' Checking Find values
  83.       ShouldBe1st% = WinFindAtom (HAtom&,_
  84.                      MakeLong(VARSEG(FirstAtom$),  SADD(FirstAtom$)))
  85.       ShouldBe2nd% = WinFindAtom (HAtom&,_
  86.              MakeLong(VARSEG(SecondAtom$), SADD(SecondAtom$)))
  87.       PRINT #1, "WinFindAtom:"
  88.       PRINT #1, "First atom:  "; HEX$(Atom1%); " ?= ";HEX$(ShouldBe1st%)
  89.       PRINT #1, "Second atom: "; HEX$(Atom2%); " ?= ";HEX$(ShouldBe2nd%)
  90.  
  91. ' Add first Atom to the Atom table to increase usage count:
  92.       Atom%  = WinAddAtom (HAtom&,_
  93.            MakeLong(VARSEG(FirstAtom$), SADD(FirstAtom$)))
  94.       Usage% = WinQueryAtomUsage (HAtom&, Atom%)
  95.       PRINT #1, "WinQueryAtomUsage:", Usage%
  96.  
  97. ' Delete Atom from Atom table:
  98.       Deleted% = WinDeleteAtom (HAtom&, Atom1%)
  99.       Usage%   = WinQueryAtomUsage (HAtom&, Atom1%)
  100.       PRINT #1, "WinDeleteAtom:",     deleted%
  101.       PRINT #1, "WinQueryAtomUsage:", Usage%
  102.  
  103. ' Query Atom length:
  104.       Length1% = WinQueryAtomLength (HAtom&, Atom1%)
  105.       PRINT #1,"1st WinQueryAtomLength:", Length1%
  106.       Buffer1$ = SPACE$(Length1%) + chr$(0)
  107.  
  108.       Length2% = WinQueryAtomLength (HAtom&, Atom2%)
  109.       PRINT #1,"2nd WinQueryAtomLength:", Length2%
  110.       Buffer2$ = SPACE$(Length2%) + chr$(0)
  111.  
  112. ' Query Atom Name:
  113.       NL% = WinQueryAtomName (HAtom&,_
  114.         Atom1%,_
  115.         MakeLong(VARSEG(Buffer1$), SADD(Buffer1$)),_
  116.         Length1% + 1)
  117.       PRINT #1, "1st WinQueryAtomName:", NL%
  118.       PRINT #1, Buffer1$
  119.  
  120.       NL% = WinQueryAtomName(HAtom&,_
  121.         Atom2%,_
  122.         MakeLong(VARSEG(Buffer2$), SADD(Buffer2$)),_
  123.         Length2% + 1)
  124.       PRINT #1, "2nd WinQueryAtomName:", NL%
  125.       PRINT #1, Buffer2$
  126.  
  127. ' Query System Atom table:
  128.       SysHAtom& = WinQuerySystemAtomTable&
  129.       PRINT #1,  "WinQuerySystemAtomTable:", HEX$(SysHAtom&)
  130.  
  131. ' Destroy Atom table (works):
  132.       HAtom&  =  WinDestroyAtomTable (HAtom&)
  133.       PRINT #1, "WinDestroyAtomTable:", HEX$(HAtom&)
  134.  
  135. ' Show string space difference
  136.       PRINT #1, "String space with strings allocated:    ";HEX$(FRE(""))
  137.       FirstAtom$  = ""
  138.       SecondAtom$ = ""
  139.       PRINT #1, "String space without strings allocated: ";HEX$(FRE(""))
  140.  
  141. CLOSE #1
  142.  
  143. '**************         Message loop         ***************
  144.  
  145. WHILE WinGetMsg(hab&, MakeLong(VARSEG(aqmsg), VARPTR(aqmsg)), 0, 0, 0)
  146.   bool% = WinDispatchMsg(hab&, MakeLong(VARSEG(aqmsg), VARPTR(aqmsg)))
  147. WEND
  148.  
  149. '***********         Finalize section        ***************
  150.  
  151. bool% = WinDestroyWindow   (hwndFrame&)
  152. bool% = WinDestroyMsgQueue (hmq&)
  153. bool% = WinTerminate       (hab&)
  154.  
  155. END
  156.  
  157. '***********         Window procedure        ***************
  158.  
  159. FUNCTION ClientWndProc& (hwnd&, msg%, mp1&, mp2&) STATIC
  160.      DIM ClientRect AS RECTL
  161.      ClientWndProc& = 0
  162.      SELECT CASE msg%
  163.      CASE WMPAINT     'Paint the window with background color
  164.         hps&  = WinBeginPaint(hwnd&, 0,_
  165.                 MakeLong(VARSEG(ClientRect), VARPTR(ClientRect)))
  166.         bool% = WinFillRect(hps&,_
  167.                 MakeLong(VARSEG(ClientRect), VARPTR(ClientRect)),0)
  168.         bool% = WinEndPaint(hps&)
  169.      CASE ELSE          'Pass control to system for other messages
  170.         ClientWndProc& = WinDefWindowProc(hwnd&, msg%, mp1&, mp2&)
  171.      END SELECT
  172. END FUNCTION
  173.