home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l391 / 4.ddi / CMNDLG.BA$ / CMNDLG.bin
Encoding:
Text File  |  1992-08-19  |  43.3 KB  |  1,123 lines

  1. ' ------------------------------------------------------------------------
  2. ' Visual Basic for MS-DOS Common Dialog Toolkit
  3. '
  4. ' The Common Dialog Toolkit (CMNDLG.BAS and CMNDLGF.FRM)
  5. ' provides support for the following dialogs:
  6. '       FileOpen
  7. '       FileSave
  8. '       FilePrint
  9. '       FindText
  10. '       ChangeText
  11. '       ColorPalette
  12. '       About
  13. '
  14. ' Support for each dialog is provided via procedures with
  15. ' these same names that create the corresponding dialog
  16. ' and return user input to your program.  These procedures
  17. ' only provide the user interface and return user input.
  18. ' They do not actually carry out the corresponding actions
  19. ' such as opening the file.  Detailed descriptions of
  20. ' these procedures are contained in the comment headers
  21. ' above each.
  22. '
  23. ' Special routines to preload (CmnDlgRegister) and unload
  24. ' (CmnDlgClose) the common dialog form for better
  25. ' performance (loaded forms display faster than unloaded
  26. ' forms) are also provided.  These routines are optional
  27. ' however as the common dialog form will automatically load
  28. ' and unload each time you invoke a common dialog.  Preloading
  29. ' the common dialog form will make common dialog access
  30. ' faster but will require more memory.
  31. '
  32. ' All common dialogs are created from the same form (CMNDLGF.FRM).
  33. ' The necessary controls for each dialog are children of
  34. ' a container picture box for the dialog.  Thus the
  35. ' form (CMNDLGF.FRM) contains a picture box with
  36. ' appropriate controls for common dialog listed above.
  37. ' When a particular common dialog is created and displayed,
  38. ' the container picture box for that dialog is made visible
  39. ' (thus all controls on that picture box become visible)
  40. ' and the form is centered and sized to match the
  41. ' container picture box.
  42. '
  43. ' To use these common dialogs in your programs, include
  44. ' CMNDLG.BAS and CMNDLGF.FRM in your program or use the
  45. ' supplied library (CMNDLG.LIB, CMNDLGA.LIB - AltMath version
  46. ' for Professional Edition only) and Quick library (CMNDLG.QLB)
  47. ' and call the appropriate procedure to invoke the dialog
  48. ' you need.
  49. '
  50. ' Copyright (C) 1982-1992 Microsoft Corporation
  51. '
  52. ' You have a royalty-free right to use, modify, reproduce
  53. ' and distribute the sample applications and toolkits provided with
  54. ' Visual Basic for MS-DOS (and/or any modified version)
  55. ' in any way you find useful, provided that you agree that
  56. ' Microsoft has no warranty, obligations or liability for
  57. ' any of the sample applications or toolkits.
  58. ' ------------------------------------------------------------------------
  59.  
  60. ' Include file containing declarations for called procedures.
  61. '$INCLUDE: 'CMNDLG.BI'
  62.  
  63. ' Common dialog form
  64. '$FORM frmCmnDlg
  65.  
  66. CONST FALSE = 0
  67. CONST TRUE = NOT FALSE
  68.  
  69. '--------------------------------------------------
  70. ' Sample usage of the common dialogs. This code is
  71. ' only executed if CMNDLG.BAS is the start-up file.
  72. ' Parameter information for each common dialog
  73. ' routine is contained in the header comments for
  74. ' the routine.
  75. '--------------------------------------------------
  76.  
  77. ' Set desktop attributes for demonstration.
  78. SCREEN.ControlPanel(16) = 5
  79. SCREEN.ControlPanel(5) = 1
  80.  
  81.  
  82.  
  83. ' Load and register common dialog form before using it
  84. ' to obtain better performance (loaded forms display faster
  85. ' than unloaded forms).  Form will remain loaded (but
  86. ' invisible) until this routine is called again to
  87. ' unload it.  Thus, all common dialog usage in your
  88. ' program will be faster.  Keeping the form loaded
  89. ' requires more memory, however, than loading and
  90. ' unloading it each time a common dialog is used.
  91. '
  92. CmnDlgRegister Success%
  93.  
  94. IF NOT Success% THEN END
  95.  
  96. ' Displays Open dialog.
  97. ' Returns filename and pathname for open operation.
  98. '
  99. FileOpen FileName$, PathName$, "", "", 0, 7, Flags%, Cancel%
  100.  
  101.  
  102. ' Displays Save dialog.
  103. ' Returns filename and pathname for save operation.
  104. '
  105. FileSave FileName$, PathName$, "*.TXT", "My Save Dialog", 0, 7, Flags%, Cancel%
  106.  
  107.  
  108. ' Displays Print dialog.
  109. ' Sets PRINTER.PrintTarget and returns number of copies to print.
  110. '
  111. FilePrint Copies%, 0, 7, Cancel%
  112.  
  113.  
  114. ' Displays Find dialog.
  115. ' Returns find text and user options.
  116. '
  117. FindText FText$, 0, 7, Options%, Flags%, Cancel%
  118.  
  119.  
  120. ' Displays Change dialog.
  121. ' Returns find text, change text, and user options.
  122. '
  123. ChangeText FText$, CText$, 0, 7, Options%, Flags%, Cancel%
  124.  
  125.  
  126. ' Displays Color Palette.
  127. ' Returns color number that user selects.
  128. '
  129. ColorPalette ColorNum%, 0, 7, Cancel%
  130.  
  131.  
  132. ' Displays supplied text in an About dialog.
  133. '
  134. About "Microsoft Visual Basic for MS-DOS" + CHR$(13) + "Sample Program" + CHR$(13) + "Copyright (C) 1982-1992 Microsoft Corporation", 15, 1, 1
  135.  
  136.  
  137. ' Unload common dialog form (if you have preloaded it for
  138. ' better performance) so program will terminate,
  139. ' otherwise common dialog form will remain loaded but
  140. ' invisible.
  141. '
  142. CmnDlgClose
  143.  
  144. ' About common dialog support routine.
  145. '
  146. ' Displays About dialog with custom picture and text.
  147. ' Dialog is centered and sized around the picture and
  148. ' text.  Text to be displayed is passed as an argument
  149. ' to procedure, picture must be created by the
  150. ' programmer in the DrawAboutPicture routine.
  151. '
  152. ' Parameters:
  153. '   AboutText - text to display in dialog.
  154. '   ForeColor - sets the dialog foreground color.  Does not affect
  155. '           SCREEN.ControlPanel color settings.
  156. '   BackColor - sets the dialog background color.  Does not affect
  157. '           SCREEN.ControlPanel color settings.
  158. '   Flags     - Determines if picture is displayed.
  159. '               Default is no picture.
  160. '
  161. SUB About (AboutText AS STRING, ForeColor AS INTEGER, BackColor AS INTEGER, Flags AS INTEGER)
  162.     ON LOCAL ERROR GOTO AboutError
  163.  
  164.     frmCmnDlg.Caption = "About"         ' Set form caption.
  165.  
  166.     ' Set dialog colors.
  167.     frmCmnDlg.ForeColor = ForeColor
  168.     frmCmnDlg.BackColor = BackColor
  169.     frmCmnDlg.pctAbout.ForeColor = ForeColor
  170.     frmCmnDlg.pctAbout.BackColor = BackColor
  171.     frmCmnDlg.pctAboutPict.ForeColor = ForeColor
  172.     frmCmnDlg.pctAboutPict.BackColor = BackColor
  173.     frmCmnDlg.lblAboutText.ForeColor = ForeColor
  174.     frmCmnDlg.lblAboutText.BackColor = BackColor
  175.     frmCmnDlg.cmdAboutOK.BackColor = BackColor
  176.  
  177.     ' Determine if picture should be displayed.
  178.     IF Flags = 1 THEN
  179.         CALL DrawAboutPicture           ' Routine that draws picture.
  180.         PictWidth% = frmCmnDlg.pctAboutPict.Width   ' Get Width and Height of picture for
  181.         PictHeight% = frmCmnDlg.pctAboutPict.Height ' determining size of dialog.
  182.     ELSE
  183.         frmCmnDlg.pctAboutPict.visible = FALSE      ' Make picture visible.
  184.         PictWidth% = 0
  185.         PictHeight% = 0
  186.     END IF
  187.  
  188.     ' Size and position label correctly for text display.
  189.     frmCmnDlg.lblAboutText.Caption = AboutText
  190.     frmCmnDlg.lblAboutText.MOVE frmCmnDlg.pctAboutPict.Left + PictWidth% + 3, frmCmnDlg.lblAboutText.Top, frmCmnDlg.TEXTWIDTH(frmCmnDlg.lblAboutText.Caption), frmCmnDlg.TEXTHEIGHT(frmCmnDlg.lblAboutText.Caption)
  191.     LabelWidth% = frmCmnDlg.lblAboutText.Width      ' Get Width and Height of text for
  192.     LabelHeight% = frmCmnDlg.lblAboutText.Height    ' determining size of dialog.
  193.  
  194.     ' Size and position About container.
  195.     frmCmnDlg.pctAbout.BorderStyle = 0
  196.     frmCmnDlg.pctAbout.visible = TRUE
  197.     frmCmnDlg.pctAbout.Width = PictWidth% + LabelWidth% + 8
  198.     IF LabelHeight% > PictHeight% THEN
  199.         frmCmnDlg.pctAbout.Height = LabelHeight% + 6
  200.     ELSE
  201.         frmCmnDlg.pctAbout.Height = PictHeight% + 5
  202.     END IF
  203.  
  204.     ' Center command button at the bottom of the dialog.
  205.     frmCmnDlg.cmdAboutOK.MOVE (frmCmnDlg.pctAbout.ScaleWidth - frmCmnDlg.cmdAboutOK.Width) \ 2, frmCmnDlg.pctAbout.ScaleHeight - 3
  206.     frmCmnDlg.cmdAboutOK.Default = TRUE
  207.     frmCmnDlg.cmdAboutOK.Cancel = TRUE
  208.  
  209.     ' Size and center dialog.
  210.     frmCmnDlg.MOVE frmCmnDlg.Left, frmCmnDlg.Top, frmCmnDlg.pctAbout.Width + 2, frmCmnDlg.pctAbout.Height + 2
  211.     frmCmnDlg.MOVE (SCREEN.Width - frmCmnDlg.Width) \ 2, ((SCREEN.Height - frmCmnDlg.Height) \ 2) - 2
  212.  
  213.     ' Display dialog modally.
  214.     frmCmnDlg.SHOW 1
  215.  
  216.     ' Hide or unload dialog and return control to user's program.
  217.     ' (Hide if user chose to preload form for performance.)
  218.     IF LEFT$(frmCmnDlg.Tag, 1) = "H" THEN
  219.         frmCmnDlg.pctAbout.visible = FALSE
  220.         frmCmnDlg.HIDE
  221.     ELSE
  222.         UNLOAD frmCmnDlg
  223.     END IF
  224.  
  225.     EXIT SUB
  226.  
  227. ' Error handling routine.
  228. AboutError:
  229.     SELECT CASE ERR
  230.     CASE 7:                                       ' Out of memory.
  231.           MSGBOX "Out of memory.  Can't load dialog.", 0, "About"
  232.           EXIT SUB
  233.     CASE ELSE
  234.           RESUME NEXT
  235.     END SELECT
  236. END SUB
  237.  
  238. ' ChangeText common dialog support routine.
  239. '
  240. ' Displays Change dialog which allows users to enter text
  241. ' to find and change.  Also allows user to specify options
  242. ' for Change operation. This procedure only provides
  243. ' the user interface and returns user input.  It does
  244. ' not actually carry out the corresponding action.
  245. '
  246. ' Parameters:
  247. '   FText - returns text the user wants to change.
  248. '           To supply default find text in dialog, assign
  249. '           default to FText then pass it to this procedure.
  250. '   CText - returns replacement text for FText.
  251. '           To supply default change text in dialog,
  252. '           assign default to CText then pass it to
  253. '           this procedure.
  254. '   ForeColor - sets the dialog foreground color.  Does not affect
  255. '           SCREEN.ControlPanel color settings.
  256. '   BackColor - sets the dialog background color.  Does not affect
  257. '           SCREEN.ControlPanel color settings.
  258. '   Options - Bit field that returns user's option
  259. '           selections as follows:
  260. '              1 - Match Case (default is no match case)
  261. '              2 - Whole Word (default is no whole word match)
  262. '              4 - Replace all occurances of FText with CText (default is Find and Verify)
  263. '           To supply default options, set appropriate
  264. '           bit position in Options then pass it to this
  265. '           procedure.  Note, "4 - Replace all occurances"
  266. '           is a return value only.
  267. '   Flags - Bit field that determines which dialog options
  268. '           are available to the user.  Field is defined as follows:
  269. '              1 - Don't display Match Case check box (default is display check box)
  270. '              2 - Don't display Whole Word check box (default is display check box)
  271. '              4 - Don't display Change All command button (default is display button)
  272. '           To change option availability, set appropriate
  273. '           bit position in Flags then pass it to this
  274. '           procedure.
  275. '   Cancel - returns whether or not user pressed the dialog's Cancel
  276. '           button.  True (-1) means the user canceled the dialog.
  277. '
  278. SUB ChangeText (FText AS STRING, CText AS STRING, ForeColor AS INTEGER, BackColor AS INTEGER, Options AS INTEGER, Flags AS INTEGER, Cancel AS INTEGER)
  279.     ON LOCAL ERROR GOTO ChangeTextError
  280.  
  281.     frmCmnDlg.Caption = "Change"        ' Set form caption.
  282.     
  283.     ' Determine if Match Case check box will be displayed to the user.
  284.     frmCmnDlg.chkSearchCase.visible = (Flags AND 1) <> 1
  285.     frmCmnDlg.chkSearchCase.Top = 8     ' Position check box correctly.
  286.     frmCmnDlg.chkSearchCase.value = (Options AND 1)
  287.  
  288.     ' Determine if Whole Word check box will be displayed to the user.
  289.     frmCmnDlg.chkSearchWord.visible = (Flags AND 2) <> 2
  290.     frmCmnDlg.chkSearchWord.Top = 9
  291.     frmCmnDlg.chkSearchWord.value = (Options AND 2) - .5 * (Options AND 2)
  292.  
  293.     ' Determine if Change All command button will be displayed to the user.
  294.     temp% = (Flags AND 4) <> 4
  295.     frmCmnDlg.cmdSearchChangeAll.visible = temp%
  296.     frmCmnDlg.cmdSearchCancel.Top = 4 - (3 * temp%)
  297.  
  298.     ' Turn off direction option (only available in FindText dialog).
  299.     frmCmnDlg.fraSearchDir.visible = FALSE
  300.  
  301.     ' Supply default find text if present.
  302.     frmCmnDlg.txtSearchFind.Text = FText
  303.  
  304.     ' Supply default change text if present.
  305.     frmCmnDlg.txtSearchChange.Text = CText
  306.  
  307.     ' Set default and cancel command buttons.
  308.     frmCmnDlg.cmdSearchFind.Default = TRUE
  309.     frmCmnDlg.cmdSearchCancel.Cancel = TRUE
  310.  
  311.     ' Turn on Change edit field and Change All command button
  312.     frmCmnDlg.txtSearchChange.visible = TRUE
  313.     frmCmnDlg.lblSearchChange.visible = TRUE
  314.     frmCmnDlg.cmdSearchFind.Caption = "Find and &Verify"
  315.  
  316.     ' Size and position Find/Change container.
  317.     frmCmnDlg.pctFindText.Height = 11
  318.     frmCmnDlg.pctFindText.BorderStyle = 0
  319.     frmCmnDlg.pctFindText.visible = TRUE
  320.  
  321.     ' Size and center dialog.
  322.     frmCmnDlg.MOVE frmCmnDlg.Left, frmCmnDlg.Top, frmCmnDlg.pctFindText.Width + 2, frmCmnDlg.pctFindText.Height + 2
  323.     frmCmnDlg.MOVE (SCREEN.Width - frmCmnDlg.Width) \ 2, ((SCREEN.Height - frmCmnDlg.Height) \ 2) - 2
  324.  
  325.     ' Set dialog colors.
  326.     frmCmnDlg.ForeColor = ForeColor
  327.     frmCmnDlg.BackColor = BackColor
  328.     frmCmnDlg.pctFindText.ForeColor = ForeColor
  329.     frmCmnDlg.pctFindText.BackColor = BackColor
  330.     frmCmnDlg.lblSearchFind.ForeColor = ForeColor
  331.     frmCmnDlg.lblSearchFind.BackColor = BackColor
  332.     frmCmnDlg.txtSearchFind.ForeColor = ForeColor
  333.     frmCmnDlg.txtSearchFind.BackColor = BackColor
  334.     frmCmnDlg.lblSearchChange.ForeColor = ForeColor
  335.     frmCmnDlg.lblSearchChange.BackColor = BackColor
  336.     frmCmnDlg.txtSearchChange.ForeColor = ForeColor
  337.     frmCmnDlg.txtSearchChange.BackColor = BackColor
  338.     frmCmnDlg.fraSearchDir.ForeColor = ForeColor
  339.     frmCmnDlg.fraSearchDir.BackColor = BackColor
  340.     FOR i% = 0 TO 1
  341.         frmCmnDlg.optSearchDir(i%).ForeColor = ForeColor
  342.         frmCmnDlg.optSearchDir(i%).BackColor = BackColor
  343.     NEXT i%
  344.     frmCmnDlg.chkSearchCase.ForeColor = ForeColor
  345.     frmCmnDlg.chkSearchCase.BackColor = BackColor
  346.     frmCmnDlg.chkSearchWord.ForeColor = ForeColor
  347.     frmCmnDlg.chkSearchWord.BackColor = BackColor
  348.     frmCmnDlg.cmdSearchFind.BackColor = BackColor
  349.     frmCmnDlg.cmdSearchCancel.BackColor = BackColor
  350.     frmCmnDlg.cmdSearchChangeAll.BackColor = BackColor
  351.  
  352.     ' Display dialog modally.
  353.     frmCmnDlg.SHOW 1
  354.  
  355.     ' Determine if user canceled dialog.
  356.     IF frmCmnDlg.cmdSearchCancel.Tag <> "FALSE" THEN
  357.         Cancel = TRUE
  358.     ' If not, return find text, change text, and user options.
  359.     ELSE
  360.         Cancel = FALSE
  361.         FText = frmCmnDlg.txtSearchFind.Text
  362.         CText = frmCmnDlg.txtSearchChange.Text
  363.         Options = frmCmnDlg.chkSearchCase.value OR 2 * frmCmnDlg.chkSearchWord.value OR 4 * VAL(frmCmnDlg.cmdSearchChangeAll.Tag)
  364.         frmCmnDlg.cmdSearchCancel.Tag = ""
  365.     END IF
  366.  
  367.     ' Hide or unload dialog and return control to user's program.
  368.     ' (Hide if user chose to preload form for performance.)
  369.     IF LEFT$(frmCmnDlg.Tag, 1) = "H" THEN
  370.         frmCmnDlg.pctFindText.visible = FALSE
  371.         frmCmnDlg.HIDE
  372.     ELSE
  373.         UNLOAD frmCmnDlg
  374.     END IF
  375.  
  376.     EXIT SUB
  377.  
  378. ' Error handling routine.
  379. ChangeTextError:
  380.     SELECT CASE ERR
  381.     CASE 7:                                       ' Out of memory.
  382.           MSGBOX "Out of memory.  Can't load dialog.", 0, "ChangeText"
  383.           Cancel = TRUE
  384.           EXIT SUB
  385.     CASE ELSE
  386.           RESUME NEXT
  387.     END SELECT
  388. END SUB
  389.  
  390. ' CmnDlgClose common dialog support routine
  391. '
  392. ' Unloads common dialog form (if you have preloaded it for
  393. ' better performance) so program will terminate,
  394. ' otherwise common dialog form will remain loaded but
  395. ' invisible.  This routine should be called if
  396. ' CmnDlgRegister was used to preload the form.  If
  397. ' CmnDlgRegister was not used, the form will be unloaded
  398. ' after each use.
  399. '
  400. SUB CmnDlgClose ()
  401.     UNLOAD frmCmnDlg            ' Unload form.
  402. END SUB
  403.  
  404. ' CmnDlgRegister common dialog support routine
  405. '
  406. ' Loads and registers common dialog form before using it
  407. ' to obtain better performance (loaded forms display faster
  408. ' than unloaded forms).  Form will remain loaded (but
  409. ' invisible) until this routine is called again to
  410. ' unload it.  Thus, all common dialog usage in your
  411. ' program will be faster (form is not loaded and unload
  412. ' each time a common dialog is invoked).  Keeping the
  413. ' form loaded requires more memory, however, than loading
  414. ' and unloading it each time a common dialog is used.
  415. '
  416. ' Use of this routine is optional since the common dialog
  417. ' form does not need to be loaded before it is used (each
  418. ' common dialog routine will load the form is it is not
  419. ' loaded).
  420. '
  421. ' Parameters:
  422. '   Success - returns TRUE (-1) if the load or unload
  423. '           attempt was successful, otherwise returns
  424. '           FALSE (0).
  425. '
  426. SUB CmnDlgRegister (Success AS INTEGER)
  427.     ' Set up error handling.
  428.     ON LOCAL ERROR GOTO RegisterError
  429.  
  430.     LOAD frmCmnDlg              ' Load form.
  431.     frmCmnDlg.Tag = "H"         ' Set flag for keeping form loaded after
  432.                                 ' each common dialog usage.
  433.  
  434.     Success = TRUE
  435.     EXIT SUB
  436.  
  437. ' Option error handling routine.
  438. ' Trap errors that occur when preloading dialog.
  439. RegisterError:
  440.     SELECT CASE ERR
  441.     CASE 7:                                       ' Out of memory.
  442.           MSGBOX "Out of memory.  Can't load Common Dialogs.", 0, "Common Dialog"
  443.           Success = FALSE
  444.           EXIT SUB
  445.     CASE ELSE
  446.           MSGBOX ERROR$ + ".  Can't load Common Dialogs.", 0, "Common Dialog"
  447.           Success = FALSE
  448.           EXIT SUB
  449.     END SELECT
  450. END SUB
  451.  
  452. ' ColorPalette common dialog support routine
  453. '
  454. ' Displays Color dialog which allows users to select a
  455. ' a color.  This procedure only provides the user
  456. ' interface and returns user input.  It does
  457. ' not actually carry out the corresponding action.
  458. '
  459. ' Parameters:
  460. '   ColorNum - returns the Basic color number (0-15) that
  461. '           the user selected.  To supply a default
  462. '           color choice in dialog, assign default to
  463. '           ColorNum then pass it to this procedure.
  464. '   ForeColor - sets the dialog foreground color.  Does not affect
  465. '           SCREEN.ControlPanel color settings.
  466. '   BackColor - sets the dialog background color.  Does not affect
  467. '           SCREEN.ControlPanel color settings.
  468. '   Cancel - returns whether or not user pressed the dialog's Cancel
  469. '           button.  True (-1) means the user cancelled the dialog.
  470. '
  471. SUB ColorPalette (ColorNum AS INTEGER, ForeColor AS INTEGER, BackColor AS INTEGER, Cancel AS INTEGER)
  472.     ON LOCAL ERROR GOTO ColorPaletteError
  473.  
  474.     frmCmnDlg.Caption = "Color Palette"     ' Set form caption.
  475.  
  476.     ' Determine default color choice and signal it
  477.     ' with a border.
  478.     frmCmnDlg.pctColors(0).Tag = STR$(ColorNum)     ' Mark selected color.
  479.     frmCmnDlg.pctColors(ColorNum).TabStop = TRUE    ' Set tabstop for this color.
  480.     frmCmnDlg.pctColors(ColorNum).PRINT "┌─────┐"    ' Display border around color.
  481.     frmCmnDlg.pctColors(ColorNum).PRINT "│     │"
  482.     frmCmnDlg.pctColors(ColorNum).PRINT "└─────┘"
  483.  
  484.     ' Set default and cancel command buttons.
  485.     frmCmnDlg.cmdColorOK.Default = TRUE
  486.     frmCmnDlg.cmdColorCancel.Cancel = TRUE
  487.  
  488.     ' Size and position ColorPalette container.
  489.     frmCmnDlg.pctColorPalette.BorderStyle = 0
  490.     frmCmnDlg.pctColorPalette.visible = TRUE
  491.  
  492.     ' Size and center dialog.
  493.     frmCmnDlg.MOVE frmCmnDlg.Left, frmCmnDlg.Top, frmCmnDlg.pctColorPalette.Width + 2, frmCmnDlg.pctColorPalette.Height + 2
  494.     frmCmnDlg.MOVE (SCREEN.Width - frmCmnDlg.Width) \ 2, ((SCREEN.Height - frmCmnDlg.Height) \ 2) - 2
  495.  
  496.     ' Set dialog colors.
  497.     frmCmnDlg.ForeColor = ForeColor
  498.     frmCmnDlg.BackColor = BackColor
  499.     frmCmnDlg.pctColorPalette.ForeColor = ForeColor
  500.     frmCmnDlg.pctColorPalette.BackColor = BackColor
  501.     frmCmnDlg.fraColors.ForeColor = ForeColor
  502.     frmCmnDlg.fraColors.BackColor = BackColor
  503.     frmCmnDlg.lblColors.ForeColor = ForeColor
  504.     frmCmnDlg.lblColors.BackColor = BackColor
  505.     frmCmnDlg.cmdColorOK.BackColor = BackColor
  506.     frmCmnDlg.cmdColorCancel.BackColor = BackColor
  507.  
  508.     ' Display dialog modally.
  509.     frmCmnDlg.SHOW 1
  510.  
  511.     ' Determine if user canceled dialog.
  512.     IF frmCmnDlg.cmdColorCancel.Tag <> "FALSE" THEN
  513.         Cancel = TRUE
  514.     ' If not, return ColorNum.
  515.     ELSE
  516.         Cancel = FALSE
  517.         ColorNum = VAL(frmCmnDlg.pctColors(0).Tag)
  518.         frmCmnDlg.cmdColorCancel.Tag = ""
  519.     END IF
  520.  
  521.     ' Hide or unload dialog and return control to user's program.
  522.     ' (Hide if user chose to preload form for performance.)
  523.     IF LEFT$(frmCmnDlg.Tag, 1) = "H" THEN
  524.         frmCmnDlg.pctColors(VAL(frmCmnDlg.pctColors(0).Tag)).TabStop = FALSE
  525.         frmCmnDlg.pctColors(VAL(frmCmnDlg.pctColors(0).Tag)).CLS
  526.         frmCmnDlg.pctColorPalette.visible = FALSE
  527.         frmCmnDlg.HIDE
  528.     ELSE
  529.         UNLOAD frmCmnDlg
  530.     END IF
  531.  
  532.     EXIT SUB
  533.  
  534. ' Error handling routine.
  535. ColorPaletteError:
  536.     SELECT CASE ERR
  537.     CASE 7:                                       ' Out of memory.
  538.           MSGBOX "Out of memory.  Can't load dialog.", 0, "ColorPalette"
  539.           Cancel = TRUE
  540.           EXIT SUB
  541.     CASE ELSE
  542.           RESUME NEXT
  543.     END SELECT
  544. END SUB
  545.  
  546. ' About Picture drawing routine for About common dialog.
  547. '
  548. ' Creates custom text-mode (ASCII) picture to be displayed
  549. ' in About dialog.  Add code here to create the picture
  550. ' you want to display in your About dialog.  Use PRINT
  551. ' method and ForeColor and BackColor properties to
  552. ' display characters and set picture Height and Width
  553. ' properties appropriately.
  554. '
  555. SUB DrawAboutPicture ()
  556.     frmCmnDlg.pctAboutPict.Height = 8           ' Set picture height.
  557.     frmCmnDlg.pctAboutPict.Width = 15           ' Set picture width.
  558.     frmCmnDlg.pctAboutPict.BorderStyle = 1      ' Set border style.
  559.     frmCmnDlg.pctAboutPict.visible = TRUE       ' Make picture visible.
  560.  
  561.     ' Display picture.
  562.     frmCmnDlg.pctAboutPict.PRINT "  Microsoft  "
  563.     frmCmnDlg.pctAboutPict.PRINT " Visual Basic"
  564.     frmCmnDlg.pctAboutPict.PRINT "             "
  565.     frmCmnDlg.pctAboutPict.PRINT " Programming "
  566.     frmCmnDlg.pctAboutPict.PRINT "  System for "
  567.     frmCmnDlg.pctAboutPict.PRINT "    MS-DOS   "
  568. END SUB
  569.  
  570. ' FileOpen common dialog support routine
  571. '
  572. ' Displays Open dialog which allows users to select a
  573. ' file from disk.  This procedure only provides
  574. ' the user interface and returns user input.  It does
  575. ' not actually carry out the corresponding action.
  576. '
  577. ' Parameters:
  578. '   FileName - returns the name (without path) of the
  579. '           file the user wants to open.  To supply
  580. '           default filename in dialog, assign default
  581. '           to FileName then pass it to this procedure.
  582. '   PathName - returns the path (without filename) of
  583. '           the file the user wants to open.  To supply
  584. '           default path in dialog, assign default to
  585. '           PathName then pass it to this procedure.
  586. '           Note, only pass a valid drive and path. Do
  587. '           not include a filename or file pattern.
  588. '   DefaultExt - sets the default search pattern for the
  589. '           File Listbox.  Default pattern when DefaultExt
  590. '           is null is "*.*".  To specify a different
  591. '           search pattern (i.e. "*.BAS"), assign new
  592. '           value to DefaultExt then pass it to this
  593. '           procedure.
  594. '   DialogTitle - sets the dialog title.  Default title
  595. '           when DialogTitle is null is "Open".  To
  596. '           specify a different title (i.e. "Open My File"),
  597. '           assign new value to DialogTitle then pass it to
  598. '           this procedure.
  599. '   ForeColor - sets the dialog foreground color.  Does not affect
  600. '           SCREEN.ControlPanel color settings.
  601. '   BackColor - sets the dialog background color.  Does not affect
  602. '           SCREEN.ControlPanel color settings.
  603. '   Flags - unused.  Use this to customize dialog action if needed.
  604. '   Cancel - returns whether or not user pressed the dialog's Cancel
  605. '           button.  True (-1) means the user cancelled the dialog.
  606. '
  607. SUB FileOpen (FileName AS STRING, PathName AS STRING, DefaultExt AS STRING, DialogTitle AS STRING, ForeColor AS INTEGER, BackColor AS INTEGER, Flags AS INTEGER, Cancel AS INTEGER)
  608.     ' Set up error handling for option validation.
  609.     ON LOCAL ERROR GOTO FileOpenError
  610.  
  611.     ' Set form caption.
  612.     IF DialogTitle = "" THEN
  613.         frmCmnDlg.Caption = "Open"
  614.     ELSE
  615.         frmCmnDlg.Caption = DialogTitle
  616.     END IF
  617.  
  618.     ' Determine search pattern for file listbox.
  619.     IF DefaultExt <> "" THEN
  620.         frmCmnDlg.filOpenList.Pattern = DefaultExt
  621.     ELSE
  622.         frmCmnDlg.filOpenList.Pattern = "*.*"
  623.     END IF
  624.  
  625.     ' Determine default path.
  626.     IF PathName <> "" THEN
  627.         ' Set drive and path for file-system controls.
  628.         ' Set Directory listbox path.  If PathName is different
  629.         ' than current path, PathChange event will be triggered
  630.         ' which updates Drive listbox drive and File listbox path.
  631.         frmCmnDlg.dirOpenList.Path = PathName
  632.     END IF
  633.     ' Display current path to the user.
  634.     frmCmnDlg.lblOpenPath.Caption = frmCmnDlg.filOpenList.Path
  635.  
  636.     ' Determine default filename to display in edit field.
  637.     IF FileName <> "" THEN
  638.         frmCmnDlg.txtOpenFile.Text = UCASE$(FileName)
  639.     ELSE
  640.         frmCmnDlg.txtOpenFile.Text = frmCmnDlg.filOpenList.Pattern
  641.     END IF
  642.  
  643.     ' Set default and cancel command buttons.
  644.     frmCmnDlg.cmdOpenOK.Default = TRUE
  645.     frmCmnDlg.cmdOpenCancel.Cancel = TRUE
  646.  
  647.     ' Size and position Open/Save container.
  648.     frmCmnDlg.pctFileOpen.BorderStyle = 0
  649.     frmCmnDlg.pctFileOpen.visible = TRUE
  650.  
  651.     ' Size and center dialog.
  652.     frmCmnDlg.MOVE frmCmnDlg.Left, frmCmnDlg.Top, frmCmnDlg.pctFileOpen.Width + 2, frmCmnDlg.pctFileOpen.Height + 2
  653.     frmCmnDlg.MOVE (SCREEN.Width - frmCmnDlg.Width) \ 2, ((SCREEN.Height - frmCmnDlg.Height) \ 2) - 2
  654.  
  655.     ' Set dialog colors.
  656.     frmCmnDlg.ForeColor = ForeColor
  657.     frmCmnDlg.BackColor = BackColor
  658.     frmCmnDlg.pctFileOpen.ForeColor = ForeColor
  659.     frmCmnDlg.pctFileOpen.BackColor = BackColor
  660.     frmCmnDlg.lblOpenFile.ForeColor = ForeColor
  661.     frmCmnDlg.lblOpenFile.BackColor = BackColor
  662.     frmCmnDlg.txtOpenFile.ForeColor = ForeColor
  663.     frmCmnDlg.txtOpenFile.BackColor = BackColor
  664.     frmCmnDlg.lblOpenPath.ForeColor = ForeColor
  665.     frmCmnDlg.lblOpenPath.BackColor = BackColor
  666.     frmCmnDlg.filOpenList.ForeColor = ForeColor
  667.     frmCmnDlg.filOpenList.BackColor = BackColor
  668.     frmCmnDlg.drvOpenList.ForeColor = ForeColor
  669.     frmCmnDlg.drvOpenList.BackColor = BackColor
  670.     frmCmnDlg.dirOpenList.ForeColor = ForeColor
  671.     frmCmnDlg.dirOpenList.BackColor = BackColor
  672.     frmCmnDlg.cmdOpenOK.BackColor = BackColor
  673.     frmCmnDlg.cmdOpenCancel.BackColor = BackColor
  674.  
  675.     ' Display dialog modally.
  676.     frmCmnDlg.SHOW 1
  677.  
  678.     ' Determine if user canceled dialog.
  679.     IF frmCmnDlg.cmdOpenCancel.Tag <> "FALSE" THEN
  680.         Cancel = TRUE
  681.     ' If not, return FileName and PathName.
  682.     ELSE
  683.         Cancel = FALSE
  684.         FileName = frmCmnDlg.txtOpenFile.Text
  685.         PathName = frmCmnDlg.filOpenList.Path
  686.         frmCmnDlg.cmdOpenCancel.Tag = ""
  687.     END IF
  688.  
  689.     ' Hide or unload dialog and return control to user's program.
  690.     ' (Hide if user chose to preload form for performance.)
  691.     IF LEFT$(frmCmnDlg.Tag, 1) = "H" THEN
  692.         frmCmnDlg.pctFileOpen.visible = FALSE
  693.         frmCmnDlg.HIDE
  694.     ELSE
  695.         UNLOAD frmCmnDlg
  696.     END IF
  697.  
  698.     EXIT SUB
  699.  
  700. ' Option error handling routine.
  701. ' Ignore errors here and let dialog's controls
  702. ' handle the errors.
  703. FileOpenError:
  704.     SELECT CASE ERR
  705.     CASE 7:                                       ' Out of memory.
  706.           MSGBOX "Out of memory.  Can't load dialog.", 0, "FileOpen"
  707.           Cancel = TRUE
  708.           EXIT SUB
  709.     CASE ELSE
  710.           RESUME NEXT
  711.     END SELECT
  712. END SUB
  713.  
  714. ' FilePrint common dialog support routine
  715. '
  716. ' Displays Print dialog which allows users to select
  717. ' Print destination (PRINTER.PrintTarget) and the
  718. ' number of copies to print.  This procedure only provides
  719. ' the user interface and returns user input.  It does
  720. ' not actually carry out the corresponding action.
  721. '
  722. ' Parameters:
  723. '   Copies - returns the number of copies (1 to 99) the user wants
  724. '           to print.  To supply default number of copies
  725. '           in dialog, assign default to Copies then
  726. '           pass it to this procedure (default when Copies
  727. '           is 0 is 1).
  728. '   ForeColor - sets the dialog foreground color.  Does not affect
  729. '           SCREEN.ControlPanel color settings.
  730. '   BackColor - sets the dialog background color.  Does not affect
  731. '           SCREEN.ControlPanel color settings.
  732. '   Cancel - returns whether or not user pressed the dialog's Cancel
  733. '           button.  True (-1) means the user cancelled the dialog.
  734. '
  735. SUB FilePrint (Copies AS INTEGER, ForeColor AS INTEGER, BackColor AS INTEGER, Cancel AS INTEGER)
  736.     ON LOCAL ERROR GOTO FilePrintError
  737.  
  738.     frmCmnDlg.Caption = "Print"         ' Set form caption.
  739.  
  740.     ' Determine default number of copies.
  741.     IF Copies = 0 THEN
  742.         frmCmnDlg.txtPrintCopies.Text = "1"
  743.     ELSE
  744.         frmCmnDlg.txtPrintCopies.Text = STR$(Copies)
  745.     END IF
  746.  
  747.     ' Set default and cancel command buttons.
  748.     frmCmnDlg.cmdPrintOK.Default = TRUE
  749.     frmCmnDlg.cmdPrintCancel.Cancel = TRUE
  750.  
  751.     ' Size and position Print container.
  752.     frmCmnDlg.pctFilePrint.BorderStyle = 0
  753.     frmCmnDlg.pctFilePrint.visible = TRUE
  754.  
  755.     ' Size and center dialog.
  756.     frmCmnDlg.MOVE frmCmnDlg.Left, frmCmnDlg.Top, frmCmnDlg.pctFilePrint.Width + 2, frmCmnDlg.pctFilePrint.Height + 2
  757.     frmCmnDlg.MOVE (SCREEN.Width - frmCmnDlg.Width) \ 2, ((SCREEN.Height - frmCmnDlg.Height) \ 2) - 2
  758.  
  759.     ' Set dialog colors.
  760.     frmCmnDlg.ForeColor = ForeColor
  761.     frmCmnDlg.BackColor = BackColor
  762.     frmCmnDlg.pctFilePrint.ForeColor = ForeColor
  763.     frmCmnDlg.pctFilePrint.BackColor = BackColor
  764.     frmCmnDlg.lblPrintCopies.ForeColor = ForeColor
  765.     frmCmnDlg.lblPrintCopies.BackColor = BackColor
  766.     frmCmnDlg.txtPrintCopies.ForeColor = ForeColor
  767.     frmCmnDlg.txtPrintCopies.BackColor = BackColor
  768.     frmCmnDlg.txtPrintFile.ForeColor = ForeColor
  769.     frmCmnDlg.txtPrintFile.BackColor = BackColor
  770.     frmCmnDlg.fraPrintTarget.ForeColor = ForeColor
  771.     frmCmnDlg.fraPrintTarget.BackColor = BackColor
  772.     FOR i% = 0 TO 3
  773.         frmCmnDlg.optPrintTarget(i%).ForeColor = ForeColor
  774.         frmCmnDlg.optPrintTarget(i%).BackColor = BackColor
  775.     NEXT i%
  776.     FOR i% = 0 TO 1
  777.         frmCmnDlg.optPrintAppend(i%).ForeColor = ForeColor
  778.         frmCmnDlg.optPrintAppend(i%).BackColor = BackColor
  779.     NEXT i%
  780.     frmCmnDlg.lblPrintAppend.ForeColor = ForeColor
  781.     frmCmnDlg.lblPrintAppend.BackColor = BackColor
  782.     frmCmnDlg.cmdPrintOK.BackColor = BackColor
  783.     frmCmnDlg.cmdPrintCancel.BackColor = BackColor
  784.     
  785.     ' Display dialog modally.
  786.     frmCmnDlg.SHOW 1
  787.  
  788.     ' Determine if user canceled dialog.
  789.     IF frmCmnDlg.cmdPrintCancel.Tag <> "FALSE" THEN
  790.         Cancel = TRUE
  791.     ' If not, return number of copies to print.
  792.     ELSE
  793.         Cancel = FALSE
  794.         IF VAL(frmCmnDlg.txtPrintCopies.Text) > 99 THEN
  795.             Copies = 99
  796.         ELSEIF VAL(frmCmnDlg.txtPrintCopies.Text) < 1 THEN
  797.             Copies = 1
  798.         ELSE
  799.             Copies = VAL(frmCmnDlg.txtPrintCopies.Text)
  800.         END IF
  801.         frmCmnDlg.cmdPrintCancel.Tag = ""
  802.     END IF
  803.  
  804.     ' Hide or unload dialog and return control to user's program.
  805.     ' (Hide if user chose to preload form for performance.)
  806.     IF LEFT$(frmCmnDlg.Tag, 1) = "H" THEN
  807.         frmCmnDlg.pctFilePrint.visible = FALSE
  808.         frmCmnDlg.HIDE
  809.     ELSE
  810.         UNLOAD frmCmnDlg
  811.     END IF
  812.  
  813.     EXIT SUB
  814.  
  815. ' Error handling routine.
  816. FilePrintError:
  817.     SELECT CASE ERR
  818.     CASE 7:                                       ' Out of memory.
  819.           MSGBOX "Out of memory.  Can't load dialog.", 0, "FindPrint"
  820.           Cancel = TRUE
  821.           EXIT SUB
  822.     CASE ELSE
  823.           RESUME NEXT
  824.     END SELECT
  825. END SUB
  826.  
  827. ' FileSave common dialog support routine
  828. '
  829. ' Displays Save dialog which allows users to specify
  830. ' filename for subsequent file save operation.
  831. ' This procedure only provides the user interface and
  832. ' returns user input.  It does not actually carry out
  833. ' the corresponding action.
  834. '
  835. ' Parameters:
  836. '   FileName - returns the name (without path) of the
  837. '           file for the save operation.  To supply
  838. '           default filename in dialog, assign default
  839. '           to FileName then pass it to this procedure.
  840. '   PathName - returns the path (without filename) of
  841. '           the file for the save operation.  To supply
  842. '           default path in dialog, assign default to
  843. '           PathName then pass it to this procedure.
  844. '           Note, only pass a valid drive and path. Do
  845. '           not include a filename or file pattern.
  846. '   DefaultExt - sets the default search pattern for the
  847. '           File Listbox.  Default pattern when DefaultExt
  848. '           is null is "*.*".  To specify a different
  849. '           search pattern (i.e. "*.BAS"), assign new
  850. '           value to DefaultExt then pass it to this
  851. '           procedure.
  852. '   DialogTitle - sets the dialog title.  Default title
  853. '           when DialogTitle is null is "Save As".  To
  854. '           specify a different title (i.e. "Save My File"),
  855. '           assign new value to DialogTitle then pass it to
  856. '           this procedure.
  857. '   ForeColor - sets the dialog foreground color.  Does not affect
  858. '           SCREEN.ControlPanel color settings.
  859. '   BackColor - sets the dialog background color.  Does not affect
  860. '           SCREEN.ControlPanel color settings.
  861. '   Flags - unused.  Use this to customize dialog action if needed.
  862. '   Cancel - returns whether or not user pressed the dialog's Cancel
  863. '           button.  True (-1) means the user cancelled the dialog.
  864. '
  865. SUB FileSave (FileName AS STRING, PathName AS STRING, DefaultExt AS STRING, DialogTitle AS STRING, ForeColor AS INTEGER, BackColor AS INTEGER, Flags AS INTEGER, Cancel AS INTEGER)
  866.     ' Set up error handling for option validation.
  867.     ON LOCAL ERROR GOTO FileSaveError
  868.  
  869.     ' Set form caption.
  870.     IF DialogTitle = "" THEN
  871.         frmCmnDlg.Caption = "Save As"
  872.     ELSE
  873.         frmCmnDlg.Caption = DialogTitle
  874.     END IF
  875.     frmCmnDlg.Tag = frmCmnDlg.Tag + "SAVE"              ' Set form tag for common unload procedure.
  876.  
  877.     ' Determine search pattern for file listbox.
  878.     IF DefaultExt <> "" THEN
  879.         frmCmnDlg.filOpenList.Pattern = DefaultExt
  880.     ELSE
  881.         frmCmnDlg.filOpenList.Pattern = "*.*"
  882.     END IF
  883.  
  884.     ' Determine default path.
  885.     IF PathName <> "" THEN
  886.         ' If the path ends with a backslash, remove it.
  887.         IF RIGHT$(PathName, 1) = "\" THEN
  888.             PathName = LEFT$(PathName, LEN(PathName) - 1)
  889.         END IF
  890.         ' Set drive and path for file-system controls.
  891.  
  892.         ' Set File listbox path.  If PathName is different
  893.         ' than current path, PathChange event will be triggered
  894.         ' which updates Drive listbox drive and Directory listbox path.
  895.         frmCmnDlg.filOpenList.Path = PathName
  896.     END IF
  897.     ' Display current path to the user.
  898.     frmCmnDlg.lblOpenPath.Caption = frmCmnDlg.filOpenList.Path
  899.  
  900.     ' Determine default filename to display in edit field.
  901.     IF FileName <> "" THEN
  902.         frmCmnDlg.txtOpenFile.Text = UCASE$(FileName)
  903.     ELSE
  904.         frmCmnDlg.txtOpenFile.Text = frmCmnDlg.filOpenList.Pattern
  905.     END IF
  906.  
  907.     ' Set default and cancel command buttons.
  908.     frmCmnDlg.cmdOpenOK.Default = TRUE
  909.     frmCmnDlg.cmdOpenCancel.Cancel = TRUE
  910.  
  911.     ' Size and position Open/Save container.
  912.     frmCmnDlg.pctFileOpen.BorderStyle = 0
  913.     frmCmnDlg.pctFileOpen.visible = TRUE
  914.  
  915.     ' Size and center dialog.
  916.     frmCmnDlg.MOVE frmCmnDlg.Left, frmCmnDlg.Top, frmCmnDlg.pctFileOpen.Width + 2, frmCmnDlg.pctFileOpen.Height + 2
  917.     frmCmnDlg.MOVE (SCREEN.Width - frmCmnDlg.Width) \ 2, ((SCREEN.Height - frmCmnDlg.Height) \ 2) - 2
  918.  
  919.     ' Set dialog colors.
  920.     frmCmnDlg.ForeColor = ForeColor
  921.     frmCmnDlg.BackColor = BackColor
  922.     frmCmnDlg.pctFileOpen.ForeColor = ForeColor
  923.     frmCmnDlg.pctFileOpen.BackColor = BackColor
  924.     frmCmnDlg.lblOpenFile.ForeColor = ForeColor
  925.     frmCmnDlg.lblOpenFile.BackColor = BackColor
  926.     frmCmnDlg.txtOpenFile.ForeColor = ForeColor
  927.     frmCmnDlg.txtOpenFile.BackColor = BackColor
  928.     frmCmnDlg.lblOpenPath.ForeColor = ForeColor
  929.     frmCmnDlg.lblOpenPath.BackColor = BackColor
  930.     frmCmnDlg.filOpenList.ForeColor = ForeColor
  931.     frmCmnDlg.filOpenList.BackColor = BackColor
  932.     frmCmnDlg.drvOpenList.ForeColor = ForeColor
  933.     frmCmnDlg.drvOpenList.BackColor = BackColor
  934.     frmCmnDlg.dirOpenList.ForeColor = ForeColor
  935.     frmCmnDlg.dirOpenList.BackColor = BackColor
  936.     frmCmnDlg.cmdOpenOK.BackColor = BackColor
  937.     frmCmnDlg.cmdOpenCancel.BackColor = BackColor
  938.  
  939.     ' Display dialog modally.
  940.     frmCmnDlg.SHOW 1
  941.  
  942.     ' Determine if user canceled dialog.
  943.     IF frmCmnDlg.cmdOpenCancel.Tag <> "FALSE" THEN
  944.         Cancel = TRUE
  945.     ' If not, return FileName and PathName.
  946.     ELSE
  947.         Cancel = FALSE
  948.         FileName = frmCmnDlg.txtOpenFile.Text
  949.         PathName = frmCmnDlg.filOpenList.Path
  950.         frmCmnDlg.cmdOpenCancel.Tag = ""
  951.     END IF
  952.  
  953.     ' Hide or unload dialog and return control to user's program.
  954.     ' (Hide if user chose to preload form for performance.)
  955.     IF LEFT$(frmCmnDlg.Tag, 1) = "H" THEN
  956.         frmCmnDlg.pctFileOpen.visible = FALSE
  957.         frmCmnDlg.HIDE
  958.         frmCmnDlg.Tag = "H"              ' Reset tag.
  959.     ELSE
  960.         UNLOAD frmCmnDlg
  961.     END IF
  962.  
  963.     EXIT SUB
  964.  
  965. ' Option error handling routine.
  966. ' Ignore errors here and let dialog's controls
  967. ' handle the errors.
  968. FileSaveError:
  969.     SELECT CASE ERR
  970.     CASE 7:                                       ' Out of memory.
  971.           MSGBOX "Out of memory.  Can't load dialog.", 0, "FileSave"
  972.           Cancel = TRUE
  973.           EXIT SUB
  974.     CASE ELSE
  975.           RESUME NEXT
  976.     END SELECT
  977. END SUB
  978.  
  979. ' FindText common dialog support routine.
  980. '
  981. ' Displays Find dialog which allows users to enter text
  982. ' to find.  Also allows user to specify options
  983. ' for Find operation. This procedure only provides
  984. ' the user interface and returns user input.  It does
  985. ' not actually carry out the corresponding action.
  986. '
  987. ' Parameters:
  988. '   FText - returns text the user wants to find.
  989. '           To supply default find text in dialog, assign
  990. '           default to FText then pass it to this procedure.
  991. '   ForeColor - sets the dialog foreground color.  Does not affect
  992. '           SCREEN.ControlPanel color settings.
  993. '   BackColor - sets the dialog background color.  Does not affect
  994. '           SCREEN.ControlPanel color settings.
  995. '   Options - Bit field that returns user's option
  996. '           selections as follows:
  997. '              1 - Match Case (default is no match case)
  998. '              2 - Whole Word (default is no whole word match)
  999. '              4 - Search direction is up (default is down)
  1000. '           To supply default options, set appropriate
  1001. '           bit position in Options then pass it to this
  1002. '           procedure.
  1003. '   Flags - Bit field that determines which dialog options
  1004. '           are available to the user.  Field is defined as follows:
  1005. '              1 - Don't display Match Case check box (default is display check box)
  1006. '              2 - Don't display Whole Word check box (default is display check box)
  1007. '              4 - Don't display Direction option buttons (default is display buttons)
  1008. '           To change option availability, set appropriate
  1009. '           bit position in Flags then pass it to this
  1010. '           procedure.
  1011. '   Cancel - returns whether or not user pressed the dialog's Cancel
  1012. '           button.  True (-1) means the user canceled the dialog.
  1013. '
  1014. SUB FindText (FText AS STRING, ForeColor AS INTEGER, BackColor AS INTEGER, Options AS INTEGER, Flags AS INTEGER, Cancel AS INTEGER)
  1015.     ON LOCAL ERROR GOTO FindTextError
  1016.  
  1017.     frmCmnDlg.Caption = "Find"        ' Set form caption.
  1018.  
  1019.     ' Determine if Match Case check box will be displayed to the user.
  1020.     frmCmnDlg.chkSearchCase.visible = (Flags% AND 1) <> 1
  1021.     frmCmnDlg.chkSearchCase.Top = 5     ' Position check box correctly since Change edit field is not displayed.
  1022.     frmCmnDlg.chkSearchCase.value = (Options AND 1)
  1023.  
  1024.     ' Determine if Whole Word check box will be displayed to the user.
  1025.     frmCmnDlg.chkSearchWord.visible = (Flags% AND 2) <> 2
  1026.     frmCmnDlg.chkSearchWord.Top = 6
  1027.     frmCmnDlg.chkSearchWord.value = (Options AND 2) - .5 * (Options AND 2)
  1028.  
  1029.     ' Determine if Direction option buttons will be displayed to the user.
  1030.     frmCmnDlg.fraSearchDir.visible = (Flags% AND 4) <> 4
  1031.     frmCmnDlg.fraSearchDir.Top = 4
  1032.     frmCmnDlg.optSearchDir(0).value = ((Options AND 4) = 4)
  1033.     frmCmnDlg.optSearchDir(1).value = ((Options AND 4) <> 4)
  1034.  
  1035.     ' Turn off Change edit field and Change All command button
  1036.     ' (only available in ChangeText dialog).
  1037.     frmCmnDlg.txtSearchChange.visible = FALSE
  1038.     frmCmnDlg.lblSearchChange.visible = FALSE
  1039.     frmCmnDlg.cmdSearchChangeAll.visible = FALSE
  1040.     frmCmnDlg.cmdSearchCancel.Top = 4
  1041.     frmCmnDlg.cmdSearchFind.Caption = "Find &Next"
  1042.  
  1043.     ' Supply default find text if present.
  1044.     frmCmnDlg.txtSearchFind.Text = FText
  1045.  
  1046.     ' Set default and cancel command buttons.
  1047.     frmCmnDlg.cmdSearchFind.Default = TRUE
  1048.     frmCmnDlg.cmdSearchCancel.Cancel = TRUE
  1049.  
  1050.     ' Size and position Find/Change container.
  1051.     frmCmnDlg.pctFindText.Height = 8
  1052.     frmCmnDlg.pctFindText.BorderStyle = 0
  1053.     frmCmnDlg.pctFindText.visible = TRUE
  1054.  
  1055.     ' Size and center dialog.
  1056.     frmCmnDlg.MOVE frmCmnDlg.Left, frmCmnDlg.Top, frmCmnDlg.pctFindText.Width + 2, frmCmnDlg.pctFindText.Height + 2
  1057.     frmCmnDlg.MOVE (SCREEN.Width - frmCmnDlg.Width) \ 2, ((SCREEN.Height - frmCmnDlg.Height) \ 2) - 2
  1058.  
  1059.     ' Set dialog colors.
  1060.     frmCmnDlg.ForeColor = ForeColor
  1061.     frmCmnDlg.BackColor = BackColor
  1062.     frmCmnDlg.pctFindText.ForeColor = ForeColor
  1063.     frmCmnDlg.pctFindText.BackColor = BackColor
  1064.     frmCmnDlg.lblSearchFind.ForeColor = ForeColor
  1065.     frmCmnDlg.lblSearchFind.BackColor = BackColor
  1066.     frmCmnDlg.txtSearchFind.ForeColor = ForeColor
  1067.     frmCmnDlg.txtSearchFind.BackColor = BackColor
  1068.     frmCmnDlg.lblSearchChange.ForeColor = ForeColor
  1069.     frmCmnDlg.lblSearchChange.BackColor = BackColor
  1070.     frmCmnDlg.txtSearchChange.ForeColor = ForeColor
  1071.     frmCmnDlg.txtSearchChange.BackColor = BackColor
  1072.     frmCmnDlg.fraSearchDir.ForeColor = ForeColor
  1073.     frmCmnDlg.fraSearchDir.BackColor = BackColor
  1074.     FOR i% = 0 TO 1
  1075.         frmCmnDlg.optSearchDir(i%).ForeColor = ForeColor
  1076.         frmCmnDlg.optSearchDir(i%).BackColor = BackColor
  1077.     NEXT i%
  1078.     frmCmnDlg.chkSearchCase.ForeColor = ForeColor
  1079.     frmCmnDlg.chkSearchCase.BackColor = BackColor
  1080.     frmCmnDlg.chkSearchWord.ForeColor = ForeColor
  1081.     frmCmnDlg.chkSearchWord.BackColor = BackColor
  1082.     frmCmnDlg.cmdSearchFind.BackColor = BackColor
  1083.     frmCmnDlg.cmdSearchCancel.BackColor = BackColor
  1084.     frmCmnDlg.cmdSearchChangeAll.BackColor = BackColor
  1085.  
  1086.     ' Display dialog modally.
  1087.     frmCmnDlg.SHOW 1
  1088.  
  1089.     ' Determine if user canceled dialog.
  1090.     IF frmCmnDlg.cmdSearchCancel.Tag <> "FALSE" THEN
  1091.         Cancel = TRUE
  1092.     ' If not, return find text and user options.
  1093.     ELSE
  1094.         Cancel = FALSE
  1095.         FText = frmCmnDlg.txtSearchFind.Text
  1096.         Options = frmCmnDlg.chkSearchCase.value OR 2 * frmCmnDlg.chkSearchWord.value OR -4 * frmCmnDlg.optSearchDir(0).value
  1097.         frmCmnDlg.cmdSearchCancel.Tag = ""
  1098.     END IF
  1099.  
  1100.     ' Hide or unload dialog and return control to user's program.
  1101.     ' (Hide if user chose to preload form for performance.)
  1102.     IF LEFT$(frmCmnDlg.Tag, 1) = "H" THEN
  1103.         frmCmnDlg.pctFindText.visible = FALSE
  1104.         frmCmnDlg.HIDE
  1105.     ELSE
  1106.         UNLOAD frmCmnDlg
  1107.     END IF
  1108.  
  1109.     EXIT SUB
  1110.  
  1111. ' Error handling routine.
  1112. FindTextError:
  1113.     SELECT CASE ERR
  1114.     CASE 7:                                       ' Out of memory.
  1115.           MSGBOX "Out of memory.  Can't load dialog.", 0, "FindText"
  1116.           Cancel = TRUE
  1117.           EXIT SUB
  1118.     CASE ELSE
  1119.           RESUME NEXT
  1120.     END SELECT
  1121. END SUB
  1122.  
  1123.