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

  1. '***********************************************************
  2. '*
  3. '* Program Name: GpiAttr.BAS
  4. '*
  5. '* Include File: GpiAttr.BI
  6. '*
  7. '* Functions   : GpiSetAttrMode
  8. '*               GpiQueryAttrMode
  9. '*               GpiSetAttrs
  10. '*               GpiQueryAttrs
  11. '*               GpiPop
  12. '*
  13. '* Description : This program demonstrates how to set and query
  14. '*               attributes and attribute modes. This can be done
  15. '*               for a variety of elements, but this uses the
  16. '*               image element.
  17. '*
  18. '* NOTE:         To use an attribute mode of AMPRESERVE (necessary
  19. '*               for GpiPop), you must first create a presentation
  20. '*               space (with GpiCreatePS instead of the microPS
  21. '*               aquired with WinGetPS and WinBeginPaint).
  22. '***********************************************************
  23.  
  24. '*********         Initialization section        ***********
  25.  
  26. REM $INCLUDE: 'PMBase.BI'
  27. REM $INCLUDE: 'GpiCont.BI'      Needed for GpiCreatePS
  28. REM $INCLUDE: 'GpiLine.BI'      Needed for SIZEF type
  29. REM $INCLUDE: 'GpiAttr.BI'
  30.  
  31. COMMON SHARED /Handle/ hab&         'Global anchor block for GpiCreatePS
  32.  
  33. OPEN "GpiAttr.OUT" FOR OUTPUT AS #1
  34.  
  35. flFrameFlags& =  FCFTITLEBAR      OR FCFSYSMENU OR _
  36.                  FCFSIZEBORDER    OR FCFMINMAX  OR _
  37.                  FCFSHELLPOSITION OR FCFTASKLIST
  38.  
  39. szClientClass$ = "ClassName" + CHR$(0)
  40.  
  41. hab&  = WinInitialize    (0)
  42. hmq&  = WinCreateMsgQueue(hab&, 0)
  43.  
  44. bool% = WinRegisterClass(_
  45.         hab&,_
  46.         MakeLong(VARSEG(szClientClass$), SADD(szClientClass$)),_
  47.         RegBas,_
  48.         0,_
  49.         0)
  50.  
  51. hwndFrame& = WinCreateStdWindow (_
  52.              HWNDDESKTOP,_
  53.              WSVISIBLE,_
  54.              MakeLong (VARSEG(flFrameFlags&),  VARPTR(flFrameFlags&)),_
  55.              MakeLong (VARSEG(szClientClass$), SADD(szClientClass$)),_
  56.              0,_
  57.              0,_
  58.              0,_
  59.              0,_
  60.              MakeLong (VARSEG(hwndClient&), VARPTR(hwndClient&)))
  61.  
  62. '**************         Message loop         ***************
  63.  
  64. WHILE WinGetMsg(hab&, MakeLong(VARSEG(aqmsg), VARPTR(aqmsg)), 0, 0, 0)
  65.   bool% = WinDispatchMsg(hab&, MakeLong(VARSEG(aqmsg), VARPTR(aqmsg)))
  66. WEND
  67.  
  68. '***********         Finalize section        ***************
  69.  
  70. bool% = WinDestroyWindow  (hwndFrame&)
  71. bool% = WinDestroyMsgQueue(hmq&)
  72. bool% = WinTerminate      (hab&)
  73.  
  74. CLOSE #1
  75.  
  76. END
  77.  
  78. '***********         Window procedure        ***************
  79.  
  80. FUNCTION ClientWndProc& (hwnd&, msg%, mp1&, mp2&) STATIC
  81.      DIM ClientRect AS RECTL
  82.      ClientWndProc& = 0
  83.      SELECT CASE msg%
  84.        CASE WMCREATE
  85.          CALL DemonstrateGPIATTRroutines
  86.        CASE WMPAINT     'Paint the window with background color
  87.          hps&  = WinBeginPaint(hwnd&, 0,_
  88.                  MakeLong(VARSEG(ClientRect), VARPTR(ClientRect)))
  89.          bool% = WinFillRect(hps&,_
  90.                  MakeLong(VARSEG(ClientRect), VARPTR(ClientRect)),0)
  91.          bool% = WinEndPaint(hps&)
  92.      CASE ELSE        'Pass control to system for other messages
  93.        ClientWndProc& = WinDefWindowProc(hwnd&, msg%, mp1&, mp2&)
  94.    END SELECT
  95. END FUNCTION
  96.  
  97. SUB DemonstrateGPIATTRroutines
  98. DIM ibmd AS IMAGEBUNDLE
  99.    'Define size of presentation space for GpiCreatePS
  100.    DIM szl AS SIZEL
  101.    szl.cx = 640 : szl.cy = 480
  102.  
  103.    'Create a presentation space because AMPRESERVE mode can not be
  104.    'used with micro presentation spaces.
  105.    hps& = GpiCreatePS(hab&, 0,_
  106.           MakeLong(VARSEG(szl), VARPTR(szl)), PUPELS)
  107.  
  108. '*
  109. '* Set Attribute mode. AMPRESERVE cause current attributes to
  110. '* be pushed onto stack before changing the attribute values
  111. '*
  112.   bool% = GpiSetAttrMode  (hps&, AMPRESERVE)
  113.   PRINT #1, "GpiSetAttrMode:",  bool%
  114.   attr& = GpiQueryAttrMode(hps&)
  115.   PRINT #1,"GpiQueryAttrMode:", attr&
  116.  
  117. '*
  118. '* Get current IMAGE attributes for Foreground and Background colors
  119. '*
  120.   attrm& = GpiQueryAttrs(hps&,_
  121.            PRIMIMAGE, IBBCOLOR OR IBBBACKCOLOR,_
  122.            MakeLong(VARSEG(ibmd), VARPTR(ibmd)))
  123.   PRINT #1,"Initial values"
  124.   PRINT #1,"Image Attributes: IBBCOLOR =     ";ibmd.LColor
  125.   PRINT #1,"                  IBBBACKCOLOR = ";ibmd.LBackColor
  126.  
  127. '*
  128. '* Set Attributes for IMAGE primitive.  The same routine, GpiSetAttrs
  129. '* is used for all 5 Gpi primitives, the only difference is the
  130. '* second parameter which specifies the Gpi primitive, and the values
  131. '* allowed in the 3rd and 4th parameters which specify the values to
  132. '* be set.
  133. '*
  134.   ibmd.LColor     = 10
  135.   ibmd.LBackColor = 11
  136.   bool%  = GpiSetAttrs  (hps&, PRIMIMAGE,_
  137.            IBBCOLOR OR IBBBACKCOLOR, IBBMIXMODE OR IBBBACKMIXMODE,_
  138.            MakeLong(VARSEG(ibmd), VARPTR(ibmd)))
  139.   attrm& = GpiQueryAttrs(hps&, PRIMIMAGE,_
  140.            IBBCOLOR OR IBBBACKCOLOR,_
  141.            MakeLong(VARSEG(ibmd), VARPTR(ibmd)))
  142.   PRINT #1,"After GpiSetAttrs"
  143.   PRINT #1,"Image Attributes: IBBCOLOR =     ";ibmd.LColor
  144.   PRINT #1,"                  IBBBACKCOLOR = ";ibmd.LBackColor
  145.  
  146. '*
  147. '* Restore original IMAGE attributes
  148. '*
  149.   bool%  = GpiPop       (hps&, 2)
  150.   attrm& = GpiQueryAttrs(hps&, PRIMIMAGE,_
  151.            IBBCOLOR OR IBBBACKCOLOR,_
  152.            MakeLong(VARSEG(ibmd), VARPTR(ibmd)))
  153.   PRINT #1,"After GpiPop"
  154.   PRINT #1,"Image Attributes: IBBCOLOR =     ";ibmd.LColor
  155.   PRINT #1,"                  IBBBACKCOLOR = ";ibmd.LBackColor
  156.  
  157. END SUB
  158.