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

  1. REM $INCLUDE: 'os2def.bi'
  2. REM $INCLUDE: 'pmbase.bi'
  3. REM $INCLUDE: 'opendlg.bi'
  4. REM $INCLUDE: 'winmisc.bi'
  5. REM $INCLUDE: 'wintrack.bi'
  6. REM $INCLUDE: 'gpibit.bi'
  7.  
  8. REM $INCLUDE: 'CAPTURE.INC'
  9.  
  10.  
  11. '|***************************************************************************
  12. '|
  13. '| LOADMOD.BAS:  Support module of CAPTURE.BAS
  14. '|
  15. '|***************************************************************************
  16. '| Loads a bitmap from a disk file.  The filename of the bitmap to be loaded
  17. '| is obtained from the the routine "DlgFile" in OPENDLG.DLL.  If "Dlgfile"
  18. '| returns an appropriate value, the bitmap is loaded into memory.  If the
  19. '| is not a valid OS/2 bitmap format, it will not be loaded.
  20. '|
  21. '| Due to a limitation of the OPENDLG routines, if a file that does not exist
  22. '| is opened, the OPENDLG routine asks the user if it should be created.
  23. '| Since this program cannot load a bitmap that does ont exist, the file is
  24. '| not created if "yes" is selected.
  25. '|***************************************************************************
  26. SUB LoadBitmapFromFile(hwndFrame&, hwnd&, hbm&)
  27. DIM bfh AS BITMAPFILEHEADER, bi AS MyBITMAPINFO, vdlf AS DLF
  28. DIM filename AS STRING * 80, ptl AS POINTL
  29. '|
  30. '| Initialize values to be used in in the Dialog box
  31. '|
  32.   szExtension$ = "\*.BMP" + CHR$(0)
  33.   szHelp$ = "The default extension is .BMP, and is attached to the file "+_
  34.             "name if an extension is not given." + CHR$(13) + CHR$(10) +_
  35.             "If the file does not exist, you'll be asked if you wish to "+_
  36.             "create it.  Since the Bitmap must exist to be loaded, "+_
  37.             "selecting YES will not create the file.  The OPEN BITMAP "+_
  38.             "dialog box will disappear, and message box will appear "+_
  39.             "explaining that the file must exist to be loaded.  This is "+_
  40.             "due to a limit with OPENDLG.DLL" + CHR$(0)
  41.   szSaveTitle$ = "LOAD BITMAP FROM FILE" + CHR$(0)
  42. '|
  43. '| Initialize fields of "vdlf".  vdlf is of TYPE DLF, which is used
  44. '| by the Dialog box routine.
  45. '|
  46.   CALL SetupDLF(MakeLong(VARSEG(vdlf), VARPTR(vdlf)),_
  47.                 DLGOPENDLG,_
  48.                 MakeLong(VARSEG(filehandle%), VARPTR(filehandle%)),_
  49.                 MakeLong(VARSEG(szExtension$), SADD(szExtension$)),_
  50.                 0,_
  51.                 MakeLong(VARSEG(szSaveTitle$), SADD(szSaveTitle$)),_
  52.                 MakeLong(VARSEG(szHelp$), SADD(szHelp$)))
  53.                 vdlf.szOpenFile = filename
  54. '|
  55. '| Obtain file name of bitmap to loaded.  The routine "DlgFile" is contained
  56. '| within the DLL "OpenDlg.DLL".  It displays and manipulates the
  57. '| dialog box for saving files.  It returns only when a valid filename
  58. '| has been obtained, and the user selects "Open".  It returns one of
  59. '| three values:
  60. '|               TDFNEWOPEN  the file does not exist
  61. '|                           (since this program creates a file only
  62. '|                            during a SAVE operation, to OPEN a file,
  63. '|                            the file must exist.  Any messages from
  64. '|                            DLGFILE stating "File does not exist,
  65. '|                            do wish to create it?", you can ignore
  66. '|                            since the file will not be created.  If you
  67. '|                            select "YES", the DLGFILE will return
  68. '|                            TDFNEWOPEN and this routine will prompt
  69. '|                            the user that the file must exist to be loaded.
  70. '|               TDFOLDOPEN  file exists, open it
  71. '|               TDFNOOPEN   user selected "Cancel"
  72. '|
  73. '| Loop until DlgFile returns either TDFNOOPEN or TDFOLDOPEN
  74. '|
  75.   DO
  76.   '|
  77.   '| Get file name
  78.   '|
  79.     retn% = DlgFile(hwndFrame&, MakeLong(VARSEG(vdlf), VARPTR(vdlf)))
  80.   '|
  81.   '| Close file since DlgFile opens the file selected regardless if
  82.   '| DLGNOOPEN was included in the paramaters passed to DlgFile.  The
  83.   '| file handle returned from DlgFile cannot be used by standard BASIC
  84.   '| file functions, i.e. GET, PUT, INPUT,..., since it is a DOS file
  85.   '| handle.
  86.   '|
  87.     bool% = DosClose(filehandle%)
  88.     filename = vdlf.szFileName
  89.   '|
  90.   '| Stripe off unused portion of 80 byte fixed string containing file name
  91.   '|
  92.     bmpfile$ = LEFT$(filename, INSTR(filename, CHR$(0)) - 1)
  93.     IF retn% = TDFOLDOPEN THEN
  94.     '|
  95.     '| If file exists, OPEN file and load bitmap
  96.     '|
  97.       CALL SetSystemPointerToWaitPointer
  98.       OPEN bmpfile$ FOR BINARY AS #2
  99.     '|
  100.     '| Get bitmap file header information and copy information to
  101.     '| "bi" (bitmap info type), and read palette information
  102.     '|
  103.       GET #2,,bfh
  104.       GET #2,,bi.argbColor
  105.       bi.cbFix     = bfh.bmp.cbFix
  106.       bi.cx        = bfh.bmp.cx
  107.       bi.cy        = bfh.bmp.cy
  108.       bi.cPlanes   = bfh.bmp.cPlanes
  109.       bi.cBitCount = bfh.bmp.cBitCount
  110.     '|
  111.     '| Create a presentation space and device context for bitmap.
  112.     '| Delete current bitmap.
  113.     '| Create a new bitmap using above bitmap information
  114.     '| Set new bitmap to presentation space
  115.     '|
  116.       CALL CreateBitmapPSandDC(hpsBitmap&, hdc&)
  117.       bool% = GpiDeleteBitmap(hbm&)
  118.       hbm& = GpiCreateBitmap(hpsBitmap&,_
  119.                              MakeLong(VARSEG(bi), VARPTR(bi)),_
  120.                              0, 0, 0)
  121.       IF (hbm& <> 0) AND (bfh.usType = BFTBMAP) THEN
  122.       '|
  123.       '| If file is a valid bitmap file, load bitmap
  124.       '|
  125.         bool% = GpiSetBitmap(hpsBitmap&, hbm&)
  126.       '|
  127.       '| Determine buffer size needed for one scan line, rounded to next
  128.       '| 32 byte boundary. (required by OS/2)
  129.       '|
  130.         bits% = bi.cBitCount * bi.cx
  131.         ScanLineSize% = ((bits% \ 32) + SGN(bits% MOD 32)) * 4
  132.         inbuffer$ = SPACE$(ScanLineSize%)
  133.       '|
  134.       '| GET one scan at a time, convert to displable format and store in
  135.       '| in micro presentation space created above
  136.       '|
  137.         FOR scanline& = 0 TO bi.cy - 1
  138.           GET #2,,inbuffer$
  139.           bool% = GpiSetBitmapBits(hpsBitmap&,_
  140.                                    scanline&,_
  141.                                    1,_
  142.                                    MakeLong(VARSEG(inbuffer$), SADD(inbuffer$)),_
  143.                                    MakeLong(VARSEG(bi), VARPTR(bi)))
  144.         NEXT scanline&
  145.         CALL SetScrollBarStatus
  146.       ELSE
  147.       '|
  148.       '| If file is not a valid OS/2 bitmap file, prompt user
  149.       '|
  150.         caption$ = "INVALID FORMAT" + CHR$(0)
  151.         message$ = bmpfile$ + " is not a valid OS/2 Bitmap file" + CHR$(0)
  152.         bool% = DisplayMessageBox(message$, caption$, 2)
  153.         bool% = GpiDeleteBitmap(hbm&)
  154.         hbm& = 0
  155.       END IF
  156.     '|
  157.     '| CLOSE file, and release presentation space, device context used to
  158.     '| create bitmap.  Post a WMPAINT message to cause bitmap to be displayed.
  159.     '|
  160.       CLOSE #2
  161.       bool% = GpiDestroyPS(hpsBitmap&)
  162.       bool% = DevCloseDC(hdc&)
  163.       bool% = WinInvalidateRect(hwnd&, 0, 0)
  164.       CALL SetSystemPointerToStandardArrow
  165.     ELSEIF retn% = TDFNEWOPEN THEN
  166.     '|
  167.     '| If file is a new file delete the file, since it is create by DlgFile
  168.     '| if "Yes" is selected when asked if it is to be created.  Display
  169.     '| message to prompt user that the file must exist to be loaded.
  170.     '|
  171.       KILL bmpfile$
  172.       caption$ = bmpfile$ + "does not exist!" + CHR$(0)
  173.       message$ = "A Bitmap must exist to be loaded" + CHR$(0)
  174.       bool% = DisplayMessageBox(message$, caption$, 2)
  175.     END IF
  176.   LOOP UNTIL (retn% = TDFNOOPEN) OR (retn% = TDFOLDOPEN)
  177. END SUB
  178.  
  179.