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

  1. '│*****************************************************************
  2. '│
  3. '│ Module:       BitMod.bas
  4. '│
  5. '│ Subprograms:  Demo1PlaneBitmap
  6. '│               Demo4PlaneBitMap
  7. '│               DemoSystemBitmaps
  8. '│               DemoResizeBitmap
  9. '│               DemoCaptureAndMagnify
  10. '│               DemoFillWithBitmap
  11. '│
  12. '│ Description:  BitMod demonstrates most of the Bitmap routines available
  13. '│               with the Presentation Manager, and many others that do not
  14. '│               deal directly with bitmaps.  Due to the need for many of
  15. '│               the routines defined in a variaty of different Include
  16. '│               files, compiler work space was getting low, so several
  17. '│               FUNCTION and CONST declarations were cut and pasted into
  18. '│               BITMOD.INC.  Each SUBprogram in this module has its own
  19. '│               menuitem under the top level menuitem "Bitmaps".  Several
  20. '│               of these routines essentially use the same calls, but all
  21. '│               demonstrate several different ways of manipulating bitmaps.
  22. '│
  23. '│               Three different bitmaps are used throughout these routines
  24. '│               all of which are stored in the programs resouce.
  25. '│
  26. '│***************************************************************************
  27.  
  28. REM $INCLUDE: 'os2def.bi'
  29. REM $INCLUDE: 'pmbase.bi'
  30. REM $INCLUDE: 'winman1.bi'
  31. REM $INCLUDE: 'winsys.bi'
  32. REM $INCLUDE: 'winpoint.bi'
  33. REM $INCLUDE: 'wintrack.bi'
  34. REM $INCLUDE: 'gpibit.bi'
  35. REM $INCLUDE: 'gpicolor.bi'
  36. REM $INCLUDE: 'gpiarea.bi'
  37. REM $INCLUDE: 'gpiline.bi'
  38.  
  39. REM $INCLUDE: 'BITMOD.INC'
  40.  
  41. COMMON /Gdemo/ cxClient%, cyClient%
  42.  
  43. '│
  44. '│ Demo1PlaneBitmap loads bitmap #1, which is a 99 x 99 bitmap created
  45. '│ with Iconedit.EXE.  This is a signle plane bitmap with 1 bitcount,
  46. '│ meaning each pixel displayed is represented by only one bit, which
  47. '│ means only two colors can be displayed, one forground and one background.
  48. '│ The Client window is divided into 20 equal boxes, the bitmap is loaded
  49. '│ and then displayed stretched and displayed to fill each area on the
  50. '│ screen in a different color.
  51. '│
  52.  
  53. SUB Demo1PlaneBitmap(hps&)
  54. SHARED cxClient%, cyClient%
  55. DIM aptl(3) AS POINTL
  56.   '│
  57.   '│ Divide Client window in to 20 equal areas
  58.   '│
  59.   xdiv4% = cxClient% / 5
  60.   ydiv4% = cyClient% / 4
  61.   '│
  62.   '│ Load bitmap1 from progams resource and store handle in hbm&
  63.   '│
  64.   hbm& = GpiLoadBitmap(hps&, 0, IDBBITMAP1, 0, 0)
  65.   '│
  66.   '│ For the first and only the first bitmap drawn, set background color
  67.   '│ to black so a forground color of white can be used.  For every succeeding
  68.   '│ bitmap, a white background is used.
  69.   '│
  70.   bcolor% = CLRBLACK
  71.   '│
  72.   '│ aptl(0) contains lower left hand corner of target area on screen
  73.   '│ aptl(1) contains upper right hand corner of target area on screen
  74.   '│
  75.   FOR X% = 0 to 4
  76.     aptl(0).x = X% * xdiv4%
  77.     aptl(1).x = aptl(0).x + xdiv4%
  78.     FOR Y% = 0 to 3
  79.       aptl(0).y = Y% * ydiv4%
  80.       aptl(1).y = aptl(0).y + ydiv4%
  81.       bool% = WinDrawBitmap(hps&, hbm&, 0,_
  82.                             MakeLong(VARSEG(aptl(0)), VARPTR(aptl(0))),_
  83.                             fcolor%, bcolor%, DBMSTRETCH)
  84.       '│
  85.       '│ Incriment forground color.  Reset to 1 when at end of default
  86.       '│ color table.
  87.       '│
  88.       fcolor% = fcolor% + 1
  89.       if fcolor% = 16 then fcolor% = 1
  90.       bcolor% = CLRWHITE
  91.     NEXT Y%
  92.   NEXT X%
  93. END SUB
  94.  
  95.  
  96. '│*****************************************************************
  97. '│ Demo4PlaneBitMap is a very simple routine.  It first sets the system
  98. '│ pointer to an hourglass to signify the bitmap is being loaded, since it
  99. '│ takes a few seconds to load and display.  It the loads the bitmap from
  100. '│ the programs resource, and displays it to fill the Client window.
  101. '│
  102. SUB Demo4PlaneBitMap(hps&)
  103. SHARED cxClient%, cyClient%
  104. DIM ptl AS POINTL, aptl(3) AS POINTL, rect AS RECTL
  105. DIM bmpinfo AS BITMAPINFOHEADER 
  106.   '│
  107.   '│ Set system ponter to hourglass
  108.   '│
  109.   bool% = WinSetPointer(HWNDDESKTOP,_
  110.                         WinQuerySysPointer(HWNDDESKTOP, SPTRWAIT, 0))
  111.   '│
  112.   '│ Load bitmap2 from programs resource and store handle in hbm&
  113.   '│
  114.   hbm& = GpiLoadBitmap(hps&, 0, IDBBITMAP2, 0, 0)
  115.   bool% = GpiQueryBitmapParameters(hbm&,_
  116.                                    MakeLong(VARSEG(bmpinfo), VARPTR(bmpinfo)))
  117.  
  118.   '│
  119.   '│ aptl(0) contains lower left hand corner of target area
  120.   '│ aptl(1) contains upper right hand corne of target area
  121.   '│ aptl(2) contains lower right hand corner of source area
  122.   '│ aptl(3) contains upper right hand corner of source area
  123.   '│
  124.   '│ aptl(2) and aptl(3) are set so as to use the entire bitmap
  125.   '│ aptl(0) and aptl(1) are set so as to fill the entire Client window
  126.   '│
  127.   aptl(0).x = 0
  128.   aptl(0).y = 0
  129.   aptl(1).x = cxClient%
  130.   aptl(1).y = cyClient%
  131.   aptl(2).x = 0
  132.   aptl(2).y = 0
  133.   aptl(3).x = bmpinfo.cx
  134.   aptl(3).y = bmpinfo.cy
  135.   '│
  136.   '│ Display bitmap
  137.   '│
  138.   bool% = GpiWCBitBlt(hps&, hbm&, 4&,_
  139.                     MakeLong(VARSEG(aptl(0)), VARPTR(aptl(0))),_
  140.                     ROPSRCCOPY, BBOAND)
  141.   '│
  142.   '│ Release bitmap handle
  143.   '│
  144.   bool% = GpiDeleteBitmap(hbm&)
  145.  
  146. END SUB
  147.  
  148.  
  149. '│*****************************************************************
  150. '│ DemoSystemBitmaps, depending on the menuitem selected, will display all
  151. '│ the available system bitmaps at the same time, magnifying them to fill
  152. '│ the client window, or will display one at a time in its actual size, but
  153. '│ fills the client window with multiple copies of the bitmap
  154. '│
  155. SUB DemoSystemBitmaps(hps&, lastgpi%)
  156. SHARED cxClient%, cyClient%
  157. DIM aptl(1) AS POINTL, ptl AS POINTL, rect AS RECTL
  158. DIM bmpinfo AS BITMAPINFOHEADER
  159.  
  160. IF lastgpi% = ShowAllSysBitmaps THEN
  161. '│
  162. '│ Display all system bitmaps at once if lastgpi% = ShowAllSysBitmaps
  163. '│
  164. '│ Divide the Client window into 20 equal areas
  165. '│
  166.   xdiv5% = cxClient% / 5
  167.   ydiv4% = cyClient% / 4
  168.   '│
  169.   '│ Begin at first system bitmap
  170.   '│
  171.   bitmapnum% = 1
  172.   FOR X% = 0 TO 4
  173.   '│
  174.   '│ aptl(0) contains lower left hand corner of target area
  175.   '│ aptl(1) contains upper right hand corner of target area
  176.   '│
  177.     aptl(0).x = X% * xdiv5%
  178.     aptl(1).x = aptl(1).x + xdiv5%
  179.     FOR Y% = 0 TO 3
  180.       aptl(0).y = Y% * ydiv4%
  181.       aptl(1).y = aptl(0).y + ydiv4%
  182.       '│
  183.       '│ The ID numbers for the system bitmaps is not continuous.
  184.       '│ There is no corresponding bitmap for numbers 13,14,20, or 21
  185.       '│ so they are skipped.
  186.       '│
  187.       While (bitmapnum% = 13 OR bitmapnum% = 14 OR_
  188.              bitmapnum% = 20 OR bitmapnum% = 21)
  189.         bitmapnum% = bitmapnum% + 1
  190.       WEND
  191.       '│
  192.       '│ Retrieve bitmap corresponding to bitmapnum%
  193.       '│
  194.       hbm& = WinGetSysBitmap(HWNDDESKTOP, bitmapnum%)
  195.       bitmapnum% = bitmapnum% + 1
  196.       '│
  197.       '│ Display bitmap filling area defined by aplt(0) and aplt(1)
  198.       '│
  199.       bool% = WinDrawBitmap(hps&, hbm&, 0,_
  200.                             MakeLong(VARSEG(aptl(0)), VARPTR(aptl(0))),_
  201.                             CLRNEUTRAL, CLRBACKGROUND, DBMSTRETCH)
  202.     NEXT Y%
  203.   NEXT X%
  204. ELSE
  205. '│
  206. '│ The following fills the Client window the select bitmap, using its actual
  207. '│ size
  208. '│
  209. '│ The menu ID number is used to determine which bitmap to be displayed, and
  210. '│ the menu ID numbers were defined as 70 greater than the actual bitmap
  211. '│ ID, so 70 must be subtracted to obtain the actual ID.  See the GpiDemo.RC.
  212. '│
  213.   bitmap% = lastgpi% - 70
  214.   hbm& = WinGetSysBitmap(HWNDDESKTOP, bitmap%)
  215.   '│
  216.   '│ Determine actual size of bitmap
  217.   '│
  218.   bool% = GpiQueryBitmapParameters(hbm&,_
  219.                                    MakeLong(VARSEG(bmpinfo), VARPTR(bmpinfo)))
  220.   '│
  221.   '│ Fill the Client window with RED.  This will display a narrow RED line
  222.   '│ between each bitmap, since the bitmaps are draw a few pixels apart.
  223.   '│ This helps distinguish the actual size of the bitmap.
  224.   '│
  225.   rect.xleft = 0
  226.   rect.xright = cxClient%
  227.   rect.ytop = cyClient%
  228.   rect.ybottom = 0
  229.   bool% = WinFillRect(hps&, MakeLong(VARSEG(rect), VARPTR(rect)), CLRRED)
  230.   '│
  231.   '│ Fill the screen with the selected bitmap
  232.   '│
  233.   FOR X% = 0 TO cxClient% STEP bmpinfo.cx + 2
  234.     FOR Y% = 0 TO cyClient% STEP bmpinfo.cy + 2
  235.       ptl.x = X%
  236.       ptl.y = Y%
  237.       bool% = WinDrawBitmap(hps&, hbm&, 0,_
  238.                             MakeLong(VARSEG(ptl), VARPTR(ptl)),_
  239.                             CLRNEUTRAL, CLRBACKGROUND, DBMNORMAL)
  240.     NEXT Y%
  241.   NEXT X%
  242. END IF
  243. END SUB
  244.  
  245.  
  246. '│*****************************************************************
  247. '│ DemoResizeBitmap essentially does the same thing as the above routines,
  248. '│ stretches or compresses a bitmap, but with the aid of the WinTrackRect
  249. '│ routine, it does it in a way that is much more visible.  You see the
  250. '│ original bitmap, and the user then, using the mouse, selects the new
  251. '│ size of the bitmap.  The mouse is moved resize the window tracking
  252. '│ rectangle, and then clicks the left mouse button to display the bitmap
  253. '│ as it new size.
  254. '│
  255. SUB DemoResizeBitmap(hwnd&, hps&) STATIC
  256. SHARED cxClient%, cyClient%
  257. DIM ti AS TRACKINFO, aptl(1) AS POINTL
  258.   '│
  259.   '│ Load bitmap from programs resource and store handle in hbm&
  260.   '│
  261.   hbm& = GpiLoadBitmap(hps&, 0, IDBBITMAP1, 0, 0)
  262.   '│
  263.   '│ If this is the first call to this routine, set default values for
  264.   '│ bitmap size and tracking rectangle size, otherwize, use current values.
  265.   '│ Values are retained due to the STATIC following the SUB statment.
  266.   If Demoed% = 0 THEN
  267.     '│
  268.     '│ Tracking rectangle default values.  Slightly larger than the bitmap.
  269.     '│
  270.     ti.rclTrack.xleft = 0
  271.     ti.rclTrack.yBottom = 0
  272.     ti.rclTrack.xRight = 110
  273.     ti.rclTrack.ytop = 110
  274.     '│
  275.     '│ Default values for the bitmap.  Draws bitmap actual size.
  276.     '│
  277.     aptl(0).x = 0
  278.     aptl(0).y = 0
  279.     aptl(1).x = 98
  280.     aptl(1).y = 98
  281.     demoed% = 1
  282.   END IF
  283.   '│
  284.   '│ Display bitmap using current size
  285.   '│
  286.   bool% = WinDrawBitmap(hps&, hbm&, 0,_
  287.                         MakeLong(VARSEG(aptl(0)), VARPTR(aptl(0))),_
  288.                         CLRNEUTRAL, CLRBACKGROUND, DBMSTRETCH)
  289.   '│
  290.   '│ Initialize tracking rectangle information.  See QuickHELP or
  291.   '│ OS/2 Programmers reference VOL 2 for a detailed description of the
  292.   '│ fields of "ti" defined as TRACKINFO.
  293.   '│
  294.   ti.cxBorder = 1
  295.   ti.cyBorder = 1
  296.   ti.cxKeyboard = 4
  297.   ti.cyKeyboard = 4
  298.   ti.rclBoundary.xleft = 0
  299.   ti.rclBoundary.ybottom = 0
  300.   ti.rclBoundary.xright = cxClient%
  301.   ti.rclBoundary.ytop = cyClient%
  302.   ti.ptlMinTrackSize.x = 1
  303.   ti.ptlMinTrackSize.y = 1
  304.   ti.ptlMaxTrackSize.x = cxClient%
  305.   ti.ptlMaxTrackSize.y = cyClient%
  306.   ti.fs = TFTOP OR TFRIGHT OR TFSTANDARD OR TFSETPOINTERPOS
  307.   '│
  308.   '│ Set system pointer to a four point pointer to signify movement in
  309.   '│ all directions.
  310.   '│
  311.   bool% = WinSetPointer(HWNDDESKTOP,_
  312.                         WinQuerySysPointer(HWNDDESKTOP, SPTRMOVE, 0))
  313.   '│
  314.   '│ Resize tracking rectangle.  WinTrackRect does not return until
  315.   '│ the left mouse button is clicked.
  316.   '│
  317.   bool% = WinTrackRect(hwnd&, 0,_
  318.                        MakeLong(VARSEG(ti), VARPTR(ti)))
  319.   '│
  320.   '│ Obtain resulting rectangle size to be used as new bitmap size.
  321.   '│
  322.   aptl(1).x = ti.rclTrack.xRight
  323.   aptl(1).y = ti.rclTrack.ytop
  324.   '│
  325.   '│ Fill new rectangle with RED.  This is done only to let the user know
  326.   '│ that something is going on, since if the new rectangle is quite large,
  327.   '│ it can take a few seconds to display the bitmap.
  328.   '│
  329.   bool% = WinFillRect(hps&,_
  330.                       MakeLong(VARSEG(ti.rclTrack), VARPTR(ti.rclTrack)),_
  331.                       CLRRED)
  332.   '│
  333.   '│ Draw the bitmap using its new size
  334.   '│
  335.   bool% = WinDrawBitmap(hps&, hbm&, 0,_
  336.                         MakeLong(VARSEG(aptl(0)), VARPTR(aptl(0))),_
  337.                         CLRNEUTRAL, CLRBACKGROUND, DBMSTRETCH)
  338.   '│
  339.   '│ Release bitmap handle
  340.   '│
  341.   bool% = GpiDeleteBitmap(hbm&)
  342.  
  343. END SUB
  344.  
  345.  
  346. '│*****************************************************************
  347. '│ DemoCaptureAndMagnify use the WinTractRect to select an area of the screen
  348. '│ to capture and store as a bitmap.  Once the bitmap is stored, it is stretched
  349. '│ or compressed to fill the client window.  Three presentation spaces are needed
  350. '│ for this operation:
  351. '│
  352. '│   1. The Client window, where the bitmap will finally be displayed.
  353. '│   2. A Screen presentation space where the bitmap is captured from.  The
  354. '│      entire screen is available to be captured.  For a visual explanation
  355. '│      of this, click the restore icon prior to selecting capture bitmap from
  356. '│      the menu so this applications window does not take up the entire screen.
  357. '│   3. A memory presentation space where the bitmap is stored after being
  358. '│      captured, so it can be quickly redrawn when a WMPAINT message is
  359. '│      executed.
  360. '│
  361. SUB DemoCaptureAndMagnify(hab&, hwndFrame&, shwnd&, hps&) STATIC
  362. SHARED cxClient%, cyClient%
  363. DIM ti AS TRACKINFO, aptl(3) AS POINTL
  364. DIM sizl AS POINTL, bi AS BITMAPINFOHEADER
  365.  
  366.   hwnd& = ABS(shwnd&)
  367.   '│
  368.   '│ If shwnd& is negative, this routine was called due to a WMPAINT
  369.   '│ message, therefore a new bitmap is not to be captured. Everything
  370.   '│ in the SUBprogram is skipped except the previous bitmap captured is
  371.   '│ redrawn.
  372.   '│
  373.   IF shwnd& > 0 THEN
  374.   '│
  375.   '│ Instructions for using "Capture Bitmap"
  376.   '│
  377.     message$="Position pointer to upper-left corner of area "+_
  378.              "to be captured, then click left mouse button.  "+_
  379.              "Stretch box around area to be captured, then "+_
  380.              "click left mouse button again." + CHR$(0)
  381.     caption$ = ""+CHR$(0)
  382.   '│
  383.   '│ Display instructions and determine if user really wants to capture
  384.   '│ a bitmap.  If value returned from WinMessageBox is MBIDOK then
  385.   '│ capture a new bitmap, otherwise, display previous bitmap.
  386.   '│
  387.     IF  WinMessageBox(HWNDDESKTOP, HWNDDESKTOP,_
  388.                       MakeLong(VARSEG(message$), SADD(message$)),_
  389.                       MakeLong(VARSEG(caption$), SADD(caption$)),_
  390.                       0,_
  391.                       MBOKCANCEL OR_
  392.                       MBICONASTERISK) = MBIDOK THEN
  393.     '│
  394.     '│ Release previous bitmap handle, and the presentation space where the
  395.     '│ bitmap is stored, and the Device Context associated with the
  396.     '│ presentation space.
  397.     '│
  398.       bool% = GpiDeleteBitmap(hbm&)
  399.       bool% = GpiDestroyPS(hps3&)
  400.       bool% = DevCloseDC(hdc&)
  401.     '│
  402.     '│ Initialize tracking rectangle information.  See QuickHELP or
  403.     '│ OS/2 Programmers reference VOL 2 for a detailed description of the
  404.     '│ fields of "ti" defined as TRACKINFO.
  405.     '│
  406.       ti.cxBorder = 1
  407.       ti.cyBorder = 1
  408.       ti.cxGrid = 0
  409.       ti.cyGrid = 0
  410.       ti.cxKeyboard = 4
  411.       ti.cyKeyboard = 4
  412.       ti.rclBoundary.xleft = 0
  413.       ti.rclBoundary.ybottom = 0
  414.       ti.rclBoundary.xright = WinQuerySysValue(HWNDDESKTOP, SVCXSCREEN)
  415.       ti.rclBoundary.ytop = WinQuerySysValue(HWNDDESKTOP, SVCYSCREEN)
  416.       ti.ptlMinTrackSize.x = 1
  417.       ti.ptlMinTrackSize.y = 1
  418.       ti.ptlMaxTrackSize.x = ti.rclBoundary.xright
  419.       ti.ptlMaxTrackSize.y = ti.rclBoundary.ytop
  420.       ti.rclTrack.xleft = ti.rclBoundary.xright / 2
  421.       ti.rclTrack.yBottom = ti.rclBoundary.ytop / 2
  422.       ti.rclTrack.xRight = ti.rclBoundary.xright / 2
  423.       ti.rclTrack.ytop = ti.rclBoundary.ytop / 2
  424.       ti.fs = TFMOVE OR TFSTANDARD OR TFSETPOINTERPOS
  425.     '│
  426.     '│ Obtain a Screen Presentation Space
  427.     '│
  428.       hps2& = WinGetScreenPS(HWNDDESKTOP)
  429.     '│
  430.     '│ Set pointer to four point system pointer as in "Resize Bitmap"
  431.     '│
  432.       bool% = WinSetPointer(HWNDDESKTOP,_
  433.                             WinQuerySysPointer(HWNDDESKTOP, SPTRMOVE, 0))
  434.     '│
  435.     '│ Obtain upper left hand corner of area to be captured.  The tracking
  436.     '│ rectangle is simply a single pixel during this call to WinTrackRect
  437.     '│ so only the pointer is visible.  When the left mouse button is
  438.     '│ clicked, WinTractRect returns, new parameters are set which allow
  439.     '│ the rectangle to be resized down and to the right of the selected
  440.     '│ upper left hand corner of the the area to be captured.
  441.     '│
  442.       bool% = WinTrackRect(HWNDDESKTOP, 0,_
  443.                            MakeLong(VARSEG(ti), VARPTR(ti)))
  444.     '│
  445.     '│ Set new parameters for tracking rectangle.  Can only expand
  446.     '│ rectangle down or to the right.
  447.     '│
  448.       ti.fs = TFBOTTOM OR TFRIGHT OR TFSTANDARD OR TFSETPOINTERPOS
  449.     '│
  450.     '│ Obtain area to be captured
  451.     '│
  452.       bool% = WinTrackRect(HWNDDESKTOP, 0,_
  453.                            MakeLong(VARSEG(ti), VARPTR(ti)))
  454.     '│
  455.     '│ Initialize bitmap information
  456.     '│
  457.       bi.cbFix = LEN(bi)
  458.       bi.cx = ti.rclTrack.xright - ti.rclTrack.xleft
  459.       bi.cy = ti.rclTrack.ytop - ti.rclTrack.ybottom
  460.       bi.cPlanes = 1
  461.       bi.cBitCount = 4
  462.     '│
  463.     '│ Initialize information for Memory Device Context, then open
  464.     '│ a memory device context.
  465.     '│
  466.       token$ = "*" + CHR$(0)
  467.       sizl.x = bi.cx
  468.       sizl.y = bi.cy
  469.       hdc& = DevOpenDC(hab&, ODMEMORY,_
  470.                        MakeLong(VARSEG(token$), SADD(token$)), 0, 0, 0)
  471.     '│
  472.     '│ Create a micro presentation space and associate it with the memory
  473.     '│ device context opened above.
  474.     '│
  475.       hps3& = GpiCreatePS(hab&, hdc&,_
  476.                           MakeLong(VARSEG(sizl), VARPTR(sizl)),_
  477.                           PUPELS OR GPIFDEFAULT OR GPITMICRO OR GPIAASSOC)
  478.     '│
  479.     '│ Create bitmap using information set previously and associate bitmap
  480.     '│ with presentation space created above.
  481.     '│
  482.       hbm& = GpiCreateBitmap(hps3&,_
  483.                              MakeLong(VARSEG(bi), VARPTR(bi)),_
  484.                              0, 0, 0)
  485.       bool% = GpiSetBitmap(hps3&, hbm&)
  486.     '│
  487.     '│ Set aptl() to source and target rectangles
  488.     '│
  489.       aptl(0).x = 0
  490.       aptl(0).y = 0
  491.       aptl(1).x = bi.cx
  492.       aptl(1).y = bi.cy
  493.       aptl(2).x = ti.rclTrack.xleft
  494.       aptl(2).y = ti.rclTrack.ybottom
  495.       aptl(3).x = ti.rclTrack.xright
  496.       aptl(3).y = ti.rclTrack.ytop
  497.     '│
  498.     '│ Copy area defind by the rectangle returned by WinTractRect to the
  499.     '│ micro presentation space created above.
  500.     '│
  501.       bool% = GpiBitBlt(hps3&, hps2&, 4&,_
  502.                         MakeLong(VARSEG(aptl(0)), VARPTR(aptl(0))),_
  503.                         ROPSRCCOPY, BBOAND)
  504.     '│
  505.     '│ Release the Screen presentation space
  506.     '│
  507.       bool% = WinReleasePS(hps2&)
  508.     END IF
  509.   END IF
  510. '│
  511. '│ Initialize source and target rectanges.  Target is now the Client Window
  512. '│
  513.   aptl(0).x = 0
  514.   aptl(0).y = 0
  515.   aptl(1).x = cxClient%
  516.   aptl(1).y = cyClient%
  517.   aptl(2).x = 0
  518.   aptl(2).y = 0
  519.   aptl(3).x = bi.cx
  520.   aptl(3).y = bi.cy
  521. '│
  522. '│ Copy captured bitmap to the Client Window
  523. '│
  524.   bool% = GpiBitBlt(hps&, hps3&, 4&,_
  525.                     MakeLong(VARSEG(aptl(0)), VARPTR(aptl(0))),_
  526.                     ROPSRCCOPY, BBOAND)
  527. END SUB
  528.  
  529.  
  530. '│*****************************************************************
  531. '│ DemoFillWithBitmap demonstrates how to use an 8 x 8 bitmap created
  532. '│ with Iconedit.EXE as a fill pattern.  A crude picture is drawn, which
  533. '│ sort of resembles a castle, and then is filled with the bitmap.
  534. '│ the bitmap resembles bricks when used as a fill pattern.
  535. '│
  536. SUB DemoFillWithBitmap(hps&)
  537. SHARED cxClient%, cyClient%
  538. DIM pic(14) AS POINTL
  539.  
  540.   xdiv5% = cxClient% / 5
  541.   ydiv4% = cyClient% / 4
  542. '│
  543. '│ Initialize pic() with points used to draw the picture.  The points
  544. '│ are calculated to be proportional to the Client Window
  545. '│
  546.   pic(0).x = 0             : pic(0).y = 0
  547.   pic(1).x = 0             : pic(1).y = 2 * ydiv4%
  548.   pic(2).x = xdiv5%        : pic(2).y = 2 * ydiv4%
  549.   pic(3).x = xdiv5%        : pic(3).y = ydiv4%
  550.   pic(4).x = 2 * xdiv5%    : pic(4).y = ydiv4%
  551.   pic(5).x = 2 * xdiv5%    : pic(5).y = 3 * ydiv4%
  552.   pic(6).x = xdiv5%        : pic(6).y = 3 * ydiv4%
  553.   pic(7).x = cxClient% / 2 : pic(7).y = cyClient%
  554.   pic(8).x = 4 * xdiv5%    : pic(8).y = 3 * ydiv4%
  555.   pic(9).x = 3 * xdiv5%    : pic(9).y = 3 * ydiv4%
  556.   pic(10).x = 3 * xdiv5%   : pic(10).y = ydiv4%
  557.   pic(11).x = 4 * xdiv5%   : pic(11).y = ydiv4%
  558.   pic(12).x = 4 * xdiv5%   : pic(12).y = 2 * ydiv4%
  559.   pic(13).x = cxClient%    : pic(13).y = 2 * ydiv4%
  560.   pic(14).x = cxClient%    : pic(14).y = 0
  561. '│
  562. '│ Load Bitmap from programs resource.  Assigne the Bitmap an ID of 254.
  563. '│ Set the current pattern set to 254 which has been defined as the bitmap.
  564. '│ Select pattern set 254, the bitmap.  Set color to RED, to resemble bricks.
  565. '│ Mark the beginning of of the picture.  Move to first point of picture,
  566. '│ lower left corner of Client window.  Use GpiPolyLine to draw picture
  567. '│ in one call, using points stored in pic().  Mark end of area and fill
  568. '│ picture with current pattern and color, which is RED and the loaded
  569. '│ bitmap.  Finally release the bitmap handle.
  570. '│
  571.   hbm&  = GpiLoadBitmap(hps&, 0, IDBBITMAP3, 0, 0)
  572.   bool% = GpiSetBitmapId(hps&, hbm&, 254)
  573.   bool% = GpiSetPatternSet(hps&, 254)
  574.   bool% = GpiSetPattern(hps&, 254)
  575.   bool% = GpiSetColor(hps&, CLRRED)
  576.   bool% = GpiBeginArea(hps&, (BAALTERNATE OR BABOUNDARY))
  577.   bool% = GpiMove(hps&, MakeLong(VARSEG(pic(0)), VARPTR(pic(0))))
  578.   bool% = GpiPolyLine(hps&, 14&, MakeLong(VARSEG(pic(1)), VARPTR(pic(1))))
  579.   bool% = GpiEndArea(hps&)
  580.   bool% = GpiDeleteBitmap(hbm&)
  581.  
  582. END SUB
  583.  
  584.