home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 24 / CDACTUAL24.iso / corel / DRAW / SCRIPTS / SCRIPTS / CALENDAR.CSC < prev    next >
Encoding:
Text File  |  1998-01-06  |  67.6 KB  |  1,917 lines

  1. REM El Asistente de calendarios (Calendar Wizard)
  2. REM Creates a calendar
  3.  
  4. '********************************************************************
  5. '   Script:    Calendar.csc
  6. '   Copyright 1996 Corel Corporation. Reservados todos los derechos.
  7. '   Descripci≤n: El gui≤n de CorelDRAW para crear calendarios.
  8. '                Dispone de un interfaz tipo asistente que le permite al
  9. '                usuario personalizar un calendario.
  10. '********************************************************************
  11.  
  12. #addfol  "..\..\..\scripts"
  13. #include "ScpConst.csi"
  14. #include "DrwConst.csi"
  15.  
  16. '/////FUNCTION & SUBROUTINE DECLARATIONS/////////////////////////////
  17. DECLARE SUB CreateText ( InText AS STRING, \\
  18.                          InFontName AS STRING, \\
  19.                     InFontSize AS LONG, \\
  20.                         InBold AS BOOLEAN, \\
  21.                         InItalic AS BOOLEAN, \\
  22.                         InStrikeout AS BOOLEAN, \\
  23.                     InUnderline AS BOOLEAN, \\
  24.                        InRed AS INTEGER, \\
  25.                        InGreen AS INTEGER, \\
  26.                        InBlue AS INTEGER )
  27. DECLARE FUNCTION GetWeekday( Wkd AS DATE ) AS INTEGER
  28. DECLARE FUNCTION GetNumRows( InMonthNum AS INTEGER, InYear AS INTEGER ) \\
  29.                          AS INTEGER
  30. DECLARE FUNCTION GetNumDays( InMonthNum AS INTEGER, InYear AS INTEGER ) \\
  31.                          AS INTEGER
  32. DECLARE FUNCTION FileExists( InFileName AS STRING ) AS BOOLEAN
  33. DECLARE SUB DoGraphics(     InUsePicture AS BOOLEAN,       \\
  34.                         InUseBorder AS BOOLEAN,        \\
  35.                         InPictureFile AS STRING,       \\
  36.                      InBorderFile AS STRING,        \\
  37.                      BYREF InTopLeftX AS LONG,      \\
  38.                      BYREF InTopLeftY AS LONG,      \\
  39.                      BYREF InBottomRightX AS LONG,  \\
  40.                      BYREF InBottomRightY AS LONG )
  41. DECLARE FUNCTION Min( Val1 AS LONG, Val2 AS LONG ) AS LONG
  42. DECLARE SUB AddMargins( BYREF InTopLeftX AS LONG, \\
  43.                         BYREF InTopLeftY AS LONG, \\
  44.                         BYREF InBottomRightX AS LONG, \\
  45.                         BYREF InBottomRightY AS LONG )
  46. DECLARE FUNCTION CalcHowMany( InHowMany AS INTEGER, \\
  47.                               InMonth AS INTEGER, \\
  48.                               InYear AS INTEGER ) AS LONG
  49.  
  50. DECLARE FUNCTION CreateDC LIB "gdi32" (BYVAL lpDriverName AS STRING, \\
  51.                                        BYVAL lpDeviceName AS LONG, \\
  52.                                        BYVAL lpOutput AS LONG, \\
  53.                                        BYVAL lpInitData AS LONG) AS LONG ALIAS "CreateDCA"
  54. DECLARE FUNCTION GetDeviceCaps LIB "gdi32" (BYVAL hDC AS LONG, \\
  55.                                             BYVAL nIndex AS LONG) AS LONG ALIAS "GetDeviceCaps"
  56. DECLARE FUNCTION DeleteDC LIB "gdi32" (BYVAL hDC AS LONG) AS LONG ALIAS "DeleteDC"
  57. DECLARE FUNCTION GetNumberOfDisplayColors( ) AS LONG
  58.  
  59. '/////GLOBAL VARIABLES & CONSTANTS///////////////////////////////////
  60. GLOBAL CONST TITLE_ERRORBOX$      = "Error del Asistente de calendarios"
  61. GLOBAL CONST TITLE_INFOBOX$       = "Informaci≤n sobre Asistente de calendarios"
  62. GLOBAL NL AS STRING         ' These must be declared as 
  63. GLOBAL NL2 AS STRING     ' variables, not constants, because
  64. NL$ = CHR(10) + CHR(13)    ' we cannot assign expressions
  65. NL2$ = NL + NL             ' to constants.
  66.  
  67. 'Constants for Dialog Return Values
  68. GLOBAL CONST DIALOG_RETURN_OK%     = 1
  69. GLOBAL CONST DIALOG_RETURN_CANCEL% = 2
  70. GLOBAL CONST DIALOG_RETURN_NEXT% = 3
  71. GLOBAL CONST DIALOG_RETURN_BACK% = 4
  72.  
  73. ' The bitmap graphic names.
  74. GLOBAL BITMAP_INTRODIALOG AS STRING
  75. GLOBAL CONST BITMAP_PREVIEW_SIMPLE AS STRING   = "\Cal1.bmp"
  76. GLOBAL CONST BITMAP_PREVIEW_LEFT AS STRING    = "\Cal2.bmp"
  77. GLOBAL CONST BITMAP_PREVIEW_RIGHT AS STRING    = "\Cal3.bmp"
  78. DIM NumColors AS LONG
  79. NumColors& = GetNumberOfDisplayColors()
  80. IF NumColors& <= 256 THEN
  81.     BITMAP_INTRODIALOG$ = "\CalB16.bmp"
  82. ELSE
  83.     BITMAP_INTRODIALOG$ = "\CalB.bmp"
  84. ENDIF
  85.  
  86. ' The previous wizard page's position.
  87. GLOBAL LastPageX AS LONG
  88. GLOBAL LastPageY AS LONG
  89. LastPageX& = -1
  90. LastPageY& = -1
  91.  
  92. ' The current directory when the script was started.
  93. GLOBAL CurDir AS STRING
  94.  
  95. ' The return value of various functions.
  96. GLOBAL GenReturn& AS LONG
  97.  
  98. ' Check to see if CorelDRAW's automation object is available.
  99. ON ERROR RESUME NEXT
  100. WITHOBJECT OBJECT_DRAW
  101.     IF (ERRNUM > 0) THEN
  102.         ' Failed to create the automation object.
  103.         ERRNUM = 0
  104.         GenReturn& = MESSAGEBOX( "No ha podido encontrar CorelDRAW."+NL2+\\
  105.                               "Si este error persiste,"+ \\
  106.                              "puede que necesite volver a instalar"+      \\
  107.                              "CorelDRAW.",                  \\
  108.                                 TITLE_ERRORBOX,              \\
  109.                              MB_STOP_ICON )
  110.         STOP
  111.     ENDIF
  112. ON ERROR EXIT
  113.  
  114. '/////INTRODUCTORY DIALOG//////////////////////////////////////////////
  115.  
  116. BEGIN DIALOG OBJECT IntroDialog 290, 180, "Asistente de calendarios", SUB IntroDialogEventHandler
  117.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Siguiente>"
  118.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Atrßs"
  119.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  120.     TEXT  93, 10, 181, 20, .Text1, "Bienvenido al Asistente de calendarios de Corel."
  121.     TEXT  93, 56, 187, 18, .Text3, "Para empezar a crear su calendario, haga clic en Siguiente."
  122.     IMAGE  10, 10, 75, 130, .IntroImage
  123.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  124.     TEXT  93, 30, 189, 21, .Text4, "Este asistente le guiarß a travΘs de las etapas necesarias para crear un bonito calendario."
  125. END DIALOG
  126.  
  127. SUB IntroDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  128.     IF Event% = EVENT_INITIALIZATION THEN     
  129.         IntroDialog.BackButton.Enable FALSE 
  130.     ENDIF
  131.     IF Event% = EVENT_MOUSE_CLICK THEN     ' Mouse click event.
  132.         SELECT CASE ControlID%
  133.             CASE IntroDialog.NextButton.GetID()
  134.                 LastPageX& = IntroDialog.GetLeftPosition()
  135.                 LastPageY& = IntroDialog.GetTopPosition()
  136.                 IntroDialog.CloseDialog DIALOG_RETURN_NEXT%
  137.             CASE IntroDialog.CancelButton.GetID()
  138.                 IntroDialog.CloseDialog DIALOG_RETURN_CANCEL%
  139.         END SELECT
  140.     ENDIF
  141.  
  142. END FUNCTION
  143.  
  144. '/////PAGE SIZE DIALOG//////////////////////////////////////////////
  145.  
  146. ' Arrays of page sizes and dimensions.
  147. GLOBAL ArrayPageNames$(6) : GLOBAL ArrayPageDim!(6, 2)
  148. ' Letter size
  149.     ArrayPageNames$(1)     = "Carta - 8.50 x 11.00 pulg."
  150.     ArrayPageDim!(1, 1)    = 8.50
  151.     ArrayPageDim!(1, 2)    = 11.0
  152. ' Legal size
  153.     ArrayPageNames$(2)    = "Oficio - 8.50 x 14.00 pulg."
  154.     ArrayPageDim!(2, 1) = 8.50
  155.     ArrayPageDim!(2, 2) = 14.0
  156. ' Executive size
  157.     ArrayPageNames$(3)    = "Ejecutivo - 7.25 x 10.50 pulg."
  158.     ArrayPageDim!(3, 1)    = 7.25
  159.     ArrayPageDim!(3, 2)    = 10.50
  160. ' A4 size
  161.     ArrayPageNames$(4)    = "A4 - 8.26 x 11.69 pulg."
  162.     ArrayPageDim!(4, 1) = 8.26
  163.     ArrayPageDim!(4, 2) = 11.69
  164. ' A5 size
  165.     ArrayPageNames$(5)    = "A5 - 5.83 x 8.26 pulg."
  166.     ArrayPageDim!(5, 1)    = 5.83
  167.     ArrayPageDim!(5, 2)    = 8.26
  168. ' B5 size
  169.     ArrayPageNames$(6)    = "B5 - 7.17 x 10.13 pulg."
  170.     ArrayPageDim!(6, 1)    = 7.17
  171.     ArrayPageDim!(6, 2) = 10.13
  172.  
  173. ' Variables needed for the dialog.
  174. GLOBAL PageSize AS INTEGER    ' The user's selected page size.
  175.  
  176. ' Set up the page size default.
  177. PageSize% = 1
  178.  
  179. BEGIN DIALOG OBJECT SizeDialog 0, 0, 290, 180, "Asistente de calendarios", SUB SizeDialogEventHandler
  180.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Siguiente >"
  181.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Atrßs"
  182.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  183.     LISTBOX  94, 23, 187, 81, .SizesList
  184.     TEXT  94, 10, 186, 10, .Text1, "Seleccione el tama±o de pßgina de su calendario."
  185.     IMAGE  10, 10, 75, 130, .SizeImage
  186.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  187. END DIALOG
  188.  
  189. SUB SizeDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  190.  
  191.     SELECT CASE Event%
  192.         CASE EVENT_INITIALIZATION&
  193.             ' Set up the page sizes list box.
  194.             SizeDialog.SizesList.SetArray ArrayPageNames$        
  195.             SizeDialog.SizesList.SetSelect PageSize%
  196.  
  197.         CASE EVENT_MOUSE_CLICK&
  198.             SELECT CASE ControlID%
  199.                 CASE SizeDialog.BackButton.GetID()
  200.                     LastPageX& = SizeDialog.GetLeftPosition()
  201.                     LastPageY& = SizeDialog.GetTopPosition()
  202.                     SizeDialog.CloseDialog DIALOG_RETURN_BACK%
  203.                 CASE SizeDialog.NextButton.GetID()
  204.                     LastPageX& = SizeDialog.GetLeftPosition()
  205.                     LastPageY& = SizeDialog.GetTopPosition()    
  206.                     SizeDialog.CloseDialog DIALOG_RETURN_NEXT%
  207.                 CASE SizeDialog.CancelButton.GetID()
  208.                     SizeDialog.CloseDialog DIALOG_RETURN_CANCEL%
  209.                 CASE SizeDialog.SizesList.GetID()
  210.                     PageSize% = SizeDialog.SizesList.GetSelect()                    
  211.             END SELECT
  212.     END SELECT    
  213.  
  214. END SUB
  215.  
  216. '/////ORIENTATION DIALOG/////////////////////////////////////////
  217.  
  218. ' Variables needed for the dialog.
  219. GLOBAL Orient AS INTEGER    ' The user's selected page orientation.
  220.  
  221. ' Constants for the orientation.
  222. GLOBAL CONST CAL_ORIENT_PORTRAIT% = 1
  223. GLOBAL CONST CAL_ORIENT_LANDSCAPE% = 2
  224.  
  225. ' Set up the orientation default.
  226. Orient% = CAL_ORIENT_PORTRAIT%
  227.  
  228. BEGIN DIALOG OBJECT OrientDialog 0, 0, 290, 180, "Asistente de calendarios", SUB OrientDialogEventHandler
  229.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Siguiente>"
  230.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Atrßs"
  231.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  232.     TEXT  94, 10, 186, 20, .Text1, "Seleccione una orientaci≤n de pßgina."
  233.     IMAGE  10, 10, 75, 130, .OrientImage
  234.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  235.     OPTIONGROUP .OrientGroup
  236.         OPTIONBUTTON  102, 32, 104, 11, .Portrait, "Vertical"
  237.         OPTIONBUTTON  102, 46, 82, 12, .Landscape, "Horizontal"
  238. END DIALOG
  239.  
  240. SUB OrientDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  241.  
  242.     SELECT CASE Event%
  243.         CASE EVENT_INITIALIZATION&
  244.             ' Set up the page orientation option buttons.
  245.             IF Orient% = CAL_ORIENT_PORTRAIT% THEN
  246.                 OrientDialog.Portrait.SetValue TRUE
  247.             ELSE
  248.                 OrientDialog.Landscape.SetValue TRUE
  249.             ENDIF
  250.  
  251.         CASE EVENT_MOUSE_CLICK&
  252.             SELECT CASE ControlID%
  253.                 CASE OrientDialog.BackButton.GetID()
  254.                     LastPageX& = OrientDialog.GetLeftPosition()
  255.                     LastPageY& = OrientDialog.GetTopPosition()
  256.                     OrientDialog.CloseDialog DIALOG_RETURN_BACK%
  257.                 CASE OrientDialog.NextButton.GetID()
  258.                     LastPageX& = OrientDialog.GetLeftPosition()
  259.                     LastPageY& = OrientDialog.GetTopPosition()        
  260.                     OrientDialog.CloseDialog DIALOG_RETURN_NEXT%
  261.                 CASE OrientDialog.CancelButton.GetID()
  262.                     OrientDialog.CloseDialog DIALOG_RETURN_CANCEL%
  263.                 CASE OrientDialog.Portrait.GetID()
  264.                     Orient% = CAL_ORIENT_PORTRAIT%
  265.                 CASE OrientDialog.Landscape.GetID()
  266.                     Orient% = CAL_ORIENT_LANDSCAPE%                    
  267.             END SELECT
  268.     END SELECT    
  269.  
  270. END SUB
  271.  
  272. '/////STYLE CHOICE DIALOG//////////////////////////////////////////////
  273.  
  274. ' The calendar styles.
  275. GLOBAL CONST CAL_STYLE_SIMPLE%   = 1
  276. GLOBAL CONST CAL_STYLE_LEFT%     = 2
  277. GLOBAL CONST CAL_STYLE_RIGHT%    = 3
  278. GLOBAL CalChoices$(3)
  279. CalChoices$(CAL_STYLE_SIMPLE%) = "Estßndar"
  280. CalChoices$(CAL_STYLE_LEFT%) = "Tφtulo de pßgina izquierda"
  281. CalChoices$(CAL_STYLE_RIGHT%) = "Tφtulo de pßgina derecha"
  282.  
  283. ' The default calendar style.
  284. GLOBAL CONST CAL_DEFAULT_STYLE% = CAL_STYLE_SIMPLE%
  285.  
  286. ' Variables needed for the dialog.
  287. GLOBAL CalStyle AS INTEGER    ' The selected calendar style.
  288.  
  289. ' Set up defaults.
  290. CalStyle = CAL_DEFAULT_STYLE%
  291.  
  292. BEGIN DIALOG OBJECT StyleDialog 0, 0, 290, 180, "Asistente de calendarios", SUB StyleDialogEventHandler
  293.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Siguiente >"
  294.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Atrßs"
  295.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  296.     IMAGE  10, 10, 75, 130, .StyleImage
  297.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  298.     DDLISTBOX  113, 35, 131, 144, .StyleList
  299.     IMAGE  135, 50, 89, 90, .PreviewImage
  300.     TEXT  94, 10, 181, 24, .Text2, "Seleccione un estilo para su calendario. El estilo seleccionado podrß previsualizarse en el cuadro presentado mßs abajo."
  301. END DIALOG
  302.  
  303. SUB StyleDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  304.  
  305.     SELECT CASE Event%
  306.         CASE EVENT_INITIALIZATION&
  307.             StyleDialog.StyleList.SetArray CalChoices$
  308.             StyleDialog.StyleList.SetSelect CalStyle%
  309.             
  310.             ' Update the preview image.
  311.             SELECT CASE CalStyle%
  312.                 CASE CAL_STYLE_SIMPLE%
  313.                     StyleDialog.PreviewImage.SetImage CurDir$ + BITMAP_PREVIEW_SIMPLE$
  314.                 CASE CAL_STYLE_LEFT%
  315.                     StyleDialog.PreviewImage.SetImage CurDir$ + BITMAP_PREVIEW_LEFT$
  316.                 CASE CAL_STYLE_RIGHT%
  317.                     StyleDialog.PreviewImage.SetImage CurDir$ + BITMAP_PREVIEW_RIGHT$
  318.             END SELECT
  319.             StyleDialog.PreviewImage.SetStyle STYLE_IMAGE_CENTERED
  320.  
  321.         CASE EVENT_MOUSE_CLICK&
  322.             SELECT CASE ControlID%
  323.                 CASE StyleDialog.BackButton.GetID()
  324.                     LastPageX& = StyleDialog.GetLeftPosition()
  325.                     LastPageY& = StyleDialog.GetTopPosition()
  326.                     StyleDialog.CloseDialog DIALOG_RETURN_BACK%
  327.                 CASE StyleDialog.NextButton.GetID()
  328.                     LastPageX& = StyleDialog.GetLeftPosition()
  329.                     LastPageY& = StyleDialog.GetTopPosition()
  330.                     StyleDialog.CloseDialog DIALOG_RETURN_NEXT%
  331.                 CASE StyleDialog.CancelButton.GetID()
  332.                     StyleDialog.CloseDialog DIALOG_RETURN_CANCEL%
  333.                 CASE StyleDialog.StyleList.GetID()
  334.                     CalStyle% = StyleDialog.StyleList.GetSelect()
  335.                     
  336.                     ' Update the preview image.
  337.                     SELECT CASE CalStyle%
  338.                         CASE CAL_STYLE_SIMPLE%
  339.                             StyleDialog.PreviewImage.SetImage CurDir$ + BITMAP_PREVIEW_SIMPLE$
  340.                         CASE CAL_STYLE_LEFT%
  341.                             StyleDialog.PreviewImage.SetImage CurDir$ + BITMAP_PREVIEW_LEFT$
  342.                         CASE CAL_STYLE_RIGHT%
  343.                             StyleDialog.PreviewImage.SetImage CurDir$ + BITMAP_PREVIEW_RIGHT$
  344.                     END SELECT
  345.  
  346.         END SELECT
  347.     END SELECT
  348.  
  349. END FUNCTION
  350.  
  351. '/////FONT CHOICE DIALOG//////////////////////////////////////////////
  352.  
  353. ' The text defaults.
  354. GLOBAL CONST CAL_DEFAULT_TEXT_SIZE% = 24
  355. GLOBAL CONST CAL_DEFAULT_TEXT_FONT$ = "Arial"
  356. GLOBAL CONST CAL_DEFAULT_TEXT_STYLE$ = "Regular"
  357.  
  358. ' Variables needed for the dialog.
  359. GLOBAL FontName AS STRING    ' The selected font name.
  360. GLOBAL PointSize AS INTEGER    ' The selected font size.
  361. GLOBAL Red AS INTEGER        ' The selected font's red component.
  362. GLOBAL Green AS INTEGER        ' The selected font's green component.
  363. GLOBAL Blue AS INTEGER        ' The selected font's blue component.
  364. GLOBAL Weight AS INTEGER        ' The selected font's weight.
  365. GLOBAL StrikeOut AS BOOLEAN    ' The selected font's strikeout setting.
  366. GLOBAL Underline AS BOOLEAN    ' The selected font's underline setting.
  367. GLOBAL Bold AS BOOLEAN        ' The selected font's bold setting.
  368. GLOBAL Italic AS BOOLEAN        ' The selected font's italic setting.
  369.  
  370. ' Set up defaults.
  371. FontName$ = CAL_DEFAULT_TEXT_FONT$
  372. PointSize% = CAL_DEFAULT_TEXT_SIZE%
  373. Red% = 0
  374. Green% = 0
  375. Blue% = 0
  376. Weight% = FONT_NORMAL&
  377. Strikeout = FALSE
  378. Underline = FALSE
  379. Bold = FALSE
  380. Italic = FALSE
  381.  
  382. BEGIN DIALOG OBJECT FontDialog 0, 0, 290, 180, "Asistente de calendarios", SUB FontDialogEventHandler
  383.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Siguiente>"
  384.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Atrßs"
  385.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  386.     TEXT  94, 53, 116, 19, .Text1, "Consejo:"
  387.     IMAGE  10, 10, 75, 130, .FontImage
  388.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  389.     PUSHBUTTON  147, 37, 76, 14, .FontButton, "Seleccione fuente"
  390.     TEXT  94, 10, 181, 25, .Text2, "Puede darle un nuevo aspecto a su calendario seleccionando una fuente y un color. Para ello pulse el bot≤n de mßs abajo."
  391.     TEXT  125, 53, 162, 39, .Text4, "No se preocupe de seleccionar el tama±o de la fuente. El Asistente de calendarios seleccionarß automßticamente el tama±o de la fuentes que necesite."
  392. END DIALOG
  393.  
  394. SUB FontDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  395.  
  396.     DIM FontReturn AS INTEGER    ' The return value of the font dialog.
  397.  
  398.     SELECT CASE Event%
  399.         CASE EVENT_INITIALIZATION&
  400.             ' Nothing to initialize.
  401.  
  402.         CASE EVENT_MOUSE_CLICK&
  403.             SELECT CASE ControlID%
  404.                 CASE FontDialog.BackButton.GetID()
  405.                     LastPageX& = FontDialog.GetLeftPosition()
  406.                     LastPageY& = FontDialog.GetTopPosition()
  407.                     FontDialog.CloseDialog DIALOG_RETURN_BACK%
  408.                 CASE FontDialog.NextButton.GetID()
  409.                     LastPageX& = FontDialog.GetLeftPosition()
  410.                     LastPageY& = FontDialog.GetTopPosition()
  411.                     FontDialog.CloseDialog DIALOG_RETURN_NEXT%
  412.                 CASE FontDialog.CancelButton.GetID()
  413.                     FontDialog.CloseDialog DIALOG_RETURN_CANCEL%
  414.                 CASE FontDialog.FontButton.GetID()
  415.     
  416.                     ' Display the font dialog box.
  417.                     FontReturn% = GetFont(FontName$,                 \\
  418.                                       PointSize%,                 \\
  419.                                       Weight%,                 \\
  420.                                       Italic,                 \\
  421.                                       Underline,                 \\
  422.                                       Strikeout,                 \\
  423.                                       Red,                     \\
  424.                                       Green,                     \\
  425.                                       Blue) 
  426.                     IF NOT FontReturn% THEN
  427.                         ' The user pressed cancel.  We should not have
  428.                         ' to restore the defaults, but if GetFont
  429.                         ' empties FontName and Style, we must.
  430.                         IF (LEN(FontName$) = 0) THEN
  431.                             FontName$ = CAL_DEFAULT_TEXT_FONT$
  432.                         ENDIF
  433.                         IF (PointSize% = 0) THEN
  434.                             PointSize% = CAL_DEFAULT_TEXT_SIZE%
  435.                         ENDIF
  436.                     ENDIF
  437.                     ' Convert the weight value to either bold or non-bold.
  438.                     IF (Weight% > FONT_NORMAL&) THEN
  439.                         Bold = TRUE
  440.                     ELSE
  441.                         Bold = FALSE
  442.                     ENDIF
  443.  
  444.         END SELECT
  445.     END SELECT
  446.  
  447. END FUNCTION
  448.  
  449. '/////DATE CHOICE DIALOG///////////////////////////////////////////
  450.  
  451. ' Set the months of the year.
  452. GLOBAL Months$(12)
  453. Months$(1) =  FORMATDATE(CDAT("1996-01-01"), "MMMM")
  454. Months$(2) =  FORMATDATE(CDAT("1996-02-01"), "MMMM")
  455. Months$(3) =  FORMATDATE(CDAT("1996-03-01"), "MMMM")
  456. Months$(4) =  FORMATDATE(CDAT("1996-04-01"), "MMMM")
  457. Months$(5) =  FORMATDATE(CDAT("1996-05-01"), "MMMM")
  458. Months$(6) =  FORMATDATE(CDAT("1996-06-01"), "MMMM")
  459. Months$(7) =  FORMATDATE(CDAT("1996-07-01"), "MMMM")
  460. Months$(8) =  FORMATDATE(CDAT("1996-08-01"), "MMMM")
  461. Months$(9) =  FORMATDATE(CDAT("1996-09-01"), "MMMM")
  462. Months$(10) = FORMATDATE(CDAT("1996-10-01"), "MMMM")
  463. Months$(11) = FORMATDATE(CDAT("1996-11-01"), "MMMM")
  464. Months$(12) = FORMATDATE(CDAT("1996-12-01"), "MMMM")
  465.  
  466. ' Set the days of the week.
  467. GLOBAL Weekdays$(7)
  468. Weekdays$(1) = FORMATDATE(CDAT("1996-01-07"), "dddd")
  469. Weekdays$(2) = FORMATDATE(CDAT("1996-01-01"), "dddd")
  470. Weekdays$(3) = FORMATDATE(CDAT("1996-01-02"), "dddd")
  471. Weekdays$(4) = FORMATDATE(CDAT("1996-01-03"), "dddd")
  472. Weekdays$(5) = FORMATDATE(CDAT("1996-01-04"), "dddd")
  473. Weekdays$(6) = FORMATDATE(CDAT("1996-01-05"), "dddd")
  474. Weekdays$(7) = FORMATDATE(CDAT("1996-01-06"), "dddd")
  475.  
  476. ' Abbreviated days of the week.
  477. GLOBAL WeekdaysShort$(7)
  478. WeekdaysShort$(1) = FORMATDATE(CDAT("1996-01-07"), "ddd")
  479. WeekdaysShort$(2) = FORMATDATE(CDAT("1996-01-01"), "ddd")
  480. WeekdaysShort$(3) = FORMATDATE(CDAT("1996-01-02"), "ddd")
  481. WeekdaysShort$(4) = FORMATDATE(CDAT("1996-01-03"), "ddd")
  482. WeekdaysShort$(5) = FORMATDATE(CDAT("1996-01-04"), "ddd")
  483. WeekdaysShort$(6) = FORMATDATE(CDAT("1996-01-05"), "ddd")
  484. WeekdaysShort$(7) = FORMATDATE(CDAT("1996-01-06"), "ddd")
  485.  
  486. ' Variables needed by the dialog.
  487. GLOBAL Year AS INTEGER     ' The year of the first calendar to generate.
  488. GLOBAL Month AS INTEGER     ' The month of the first calendar to generate.
  489. GLOBAL HowMany AS INTEGER ' How many months to generate.
  490.  
  491. ' Set up defaults.
  492. Year% = 1996
  493. Month% = 9 
  494. HowMany% = 1
  495.  
  496. BEGIN DIALOG OBJECT DateDialog 0, 0, 290, 180, "Asistente de calendarios", SUB DateDialogEventHandler
  497.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Terminar"
  498.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Atrßs"
  499.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  500.     IMAGE  10, 10, 75, 130, .DateImage
  501.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  502.     TEXT  106, 37, 24, 10, .Text2, "Mes"
  503.     DDLISTBOX  133, 35, 55, 168, .MonthList
  504.     TEXT  94, 10, 181, 17, .Text5, "Seleccione el primer mes del a±o y el a±o para los que desea crear un calendario."
  505.     TEXT  201, 37, 17, 13, .Text4, "A±o"
  506.     TEXT  94, 58, 181, 27, .Text9, "Inserte el n·mero de meses de calendarios que desee generar. Puede crear un a±o completo de calendarios insertando el n·mero 12."
  507.     TEXT  132, 91, 59, 12, .Text6, "N·mero de meses"
  508.     SPINCONTROL  222, 35, 35, 13, .YearSpin
  509.     SPINCONTROL  196, 88, 33, 13, .RepeatSpin
  510. END DIALOG
  511.  
  512. SUB DateDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  513.  
  514.     DIM MBReturn AS INTEGER    ' The return value of the MESSAGEBOX function.
  515.     DIM TodayDate AS DATE    ' Today's date (used to set the month and year).
  516.     DIM TodayYear AS LONG    ' The current year.
  517.     DIM TodayMonth AS LONG    ' The current month.
  518.     DIM TodayDay AS LONG    ' The current day.
  519.     DIM TodayDW AS LONG        ' Today's day of the week.
  520.     
  521.     SELECT CASE Event%
  522.         CASE EVENT_INITIALIZATION&
  523.             ' Use the current month and year as defaults.
  524.             TodayDate = GETCURRDATE()
  525.             GETDATEINFO TodayDate, TodayYear&, TodayMonth&, TodayDay&, TodayDW&
  526.             Year% = TodayYear&
  527.             Month% = TodayMonth&
  528.         
  529.             DateDialog.YearSpin.SetValue Year%
  530.             DateDialog.RepeatSpin.SetValue HowMany%
  531.             DateDialog.MonthList.SetArray Months$
  532.             DateDialog.MonthList.SetSelect Month%
  533.             
  534.         CASE EVENT_MOUSE_CLICK&
  535.             SELECT CASE ControlID%
  536.                 CASE DateDialog.BackButton.GetID()
  537.                     LastPageX& = DateDialog.GetLeftPosition()
  538.                     LastPageY& = DateDialog.GetTopPosition()
  539.                     IF (DateDialog.YearSpin.GetValue() < 1900) OR \\
  540.                        (DateDialog.YearSpin.GetValue() > 2300) THEN
  541.                         MBReturn = MESSAGEBOX("Inserte un a±o entre" + \\
  542.                                               "1900 y 2300 inclusive.",      \\
  543.                                               TITLE_INFOBOX,                  \\
  544.                                               MB_INFORMATION_ICON)
  545.                         DateDialog.YearSpin.SetValue Year%    
  546.                     ELSEIF (DateDialog.RepeatSpin.GetValue() < 1) OR \\
  547.                            (DateDialog.RepeatSpin.GetValue() > 999) THEN
  548.                          MBReturn = MESSAGEBOX("Inserte un n·mero de" + \\
  549.                                                "meses entre 1 y 999 inclusive.",\\
  550.                                                TITLE_INFOBOX, MB_INFORMATION_ICON)
  551.                         DateDialog.RepeatSpin.SetValue HowMany%
  552.                     ELSE
  553.                         Year% = DateDialog.YearSpin.GetValue()
  554.                         HowMany% = DateDialog.RepeatSpin.GetValue()
  555.                         DateDialog.CloseDialog DIALOG_RETURN_BACK%
  556.                     ENDIF
  557.                 CASE DateDialog.NextButton.GetID()
  558.                     LastPageX& = DateDialog.GetLeftPosition()
  559.                     LastPageY& = DateDialog.GetTopPosition()
  560.                     IF (DateDialog.YearSpin.GetValue() < 1900) OR \\
  561.                        (DateDialog.YearSpin.GetValue() > 2300) THEN
  562.                         MBReturn = MESSAGEBOX("Inserte un a±o entre" + \\
  563.                                               "1900 y 2300 inclusive.",      \\
  564.                                               TITLE_INFOBOX,                   \\
  565.                                               MB_INFORMATION_ICON)
  566.                         DateDialog.YearSpin.SetValue Year%    
  567.                     ELSEIF (DateDialog.RepeatSpin.GetValue() < 1) OR \\
  568.                            (DateDialog.RepeatSpin.GetValue() > 18) THEN
  569.                          MBReturn = MESSAGEBOX("Inserte un n·mero de" + \\
  570.                                                "meses entre 1 y 18 inclusive.",\\
  571.                                                TITLE_INFOBOX, MB_INFORMATION_ICON)
  572.                         DateDialog.RepeatSpin.SetValue HowMany%
  573.                     ELSE
  574.                         Year% = DateDialog.YearSpin.GetValue()
  575.                         HowMany% = DateDialog.RepeatSpin.GetValue()
  576.                         DateDialog.CloseDialog DIALOG_RETURN_NEXT%
  577.                     ENDIF
  578.                 CASE DateDialog.CancelButton.GetID()
  579.                     DateDialog.CloseDialog DIALOG_RETURN_CANCEL%
  580.                 CASE DateDialog.MonthList.GetID()
  581.                     Month% = DateDialog.MonthList.GetSelect()
  582.             END SELECT
  583.             
  584.         CASE EVENT_CHANGE_IN_CONTENT&
  585.             SELECT CASE ControlID%
  586.                 CASE DateDialog.YearSpin.GetID()
  587.                     IF (DateDialog.YearSpin.GetValue() < 1900) THEN
  588.                         MBReturn = MESSAGEBOX("Inserte un a±o entre" + \\
  589.                                               "1900 y 2300 inclusive.",      \\
  590.                                               TITLE_INFOBOX,                   \\
  591.                                               MB_INFORMATION_ICON)
  592.                         DateDialog.YearSpin.SetValue 1900
  593.                     ELSEIF (DateDialog.YearSpin.GetValue() > 2300) THEN
  594.                         MBReturn = MESSAGEBOX("Inserte un a±o entre" + \\
  595.                                               "1900 y 2300 inclusive.",      \\
  596.                                               TITLE_INFOBOX,                   \\
  597.                                               MB_INFORMATION_ICON)
  598.                         DateDialog.YearSpin.SetValue 2300
  599.                     ENDIF
  600.                 CASE DateDialog.RepeatSpin.GetID()
  601.                     IF (DateDialog.RepeatSpin.GetValue() < 1) THEN
  602.                          MBReturn = MESSAGEBOX("Inserte un n·mero de" + \\
  603.                                                "meses entre 1 y 18 inclusive.",\\
  604.                                                TITLE_INFOBOX, MB_INFORMATION_ICON)
  605.                         DateDialog.RepeatSpin.SetValue 1
  606.                     ELSEIF (DateDialog.RepeatSpin.GetValue() > 18) THEN
  607.                          MBReturn = MESSAGEBOX("Inserte un n·mero de" + \\
  608.                                                "meses entre 1 y 18 inclusive.",\\
  609.                                                TITLE_INFOBOX, MB_INFORMATION_ICON)
  610.                         DateDialog.RepeatSpin.SetValue 18
  611.                     ENDIF
  612.                 
  613.             END SELECT
  614.             
  615.     END SELECT
  616.  
  617. END FUNCTION
  618.  
  619. '/////PICTURE AND BORDER CHOICE DIALOG///////////////////////////////
  620.  
  621. ' Variables needed by the dialog.
  622. GLOBAL UsePicture AS BOOLEAN    ' Add a picture to the calendar?
  623. GLOBAL UseBorder AS BOOLEAN   ' Add a border to the calendar?
  624. GLOBAL PictureFile AS STRING  ' Name and path of the picture.
  625. GLOBAL BorderFile AS STRING   ' Name and path of the border.
  626. GLOBAL TmpFileName AS STRING  ' A temporary file name.
  627.  
  628. ' Set up defaults.
  629. UsePicture = FALSE
  630. UseBorder  = FALSE
  631. PictureFile$ = ""
  632. BorderFile$ = ""
  633.  
  634. BEGIN DIALOG OBJECT PicDialog 0, 0, 290, 180, "Asistente de calendarios", SUB PicDialogEventHandler
  635.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Siguiente>"
  636.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Atrßs"
  637.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  638.     IMAGE  10, 10, 75, 130, .PicImage
  639.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  640.     TEXT  90, 110, 28, 11, .Text9, "Consejo:"
  641.     TEXT  90, 10, 181, 17, .Text5, "┐Desea a±adir una imagen a su calendario?"
  642.     CHECKBOX  90, 25, 90, 12, .PictureCheck, "Sφ.Nombre del arch. es:"
  643.     TEXTBOX  180, 24, 50, 13, .PicTextBox
  644.     PUSHBUTTON  233, 24, 53, 13, .PictureButton, "Selecc. archi."
  645.     CHECKBOX  90, 76, 90, 12, .BorderCheck, "Sφ.Nombre del arch. es:"
  646.     TEXTBOX  180, 75, 50, 13, .BorderTextBox
  647.     PUSHBUTTON  233, 75, 53, 13, .BorderButton, "Selecc. archi."
  648.     TEXT  90, 45, 181, 27, .Text6, "TambiΘn puede a±adirle un margen a su calendario. Para obtener resultados ≤ptimos, deberφa seleccionar un margen del directorio de clipart Mßrgenes/Marcos."
  649.     TEXT  125, 110, 157, 40, .Text8, "Para un aspecto ≤ptimo de su calendario, seleccione como mßximo una de las opciones arriba. De otra manera, puede que no tenga suficiente espacio en su pßgina para el calendario."
  650. END DIALOG
  651.  
  652. SUB PicDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  653.  
  654.     DIM MBReturn AS INTEGER    ' The return value of the MESSAGEBOX function.
  655.     DIM NoGo AS BOOLEAN        ' Whether the user is allowed to move to
  656.                         ' another pane of the wizard.
  657.     
  658.     SELECT CASE Event%
  659.         CASE EVENT_INITIALIZATION&
  660.             IF UsePicture THEN
  661.                 PicDialog.PictureCheck.SetValue 1
  662.             ELSE
  663.                 PicDialog.PictureCheck.SetValue 0
  664.             ENDIF
  665.             PicDialog.PictureCheck.SetThreeState FALSE
  666.             IF UseBorder THEN
  667.                 PicDialog.BorderCheck.SetValue 1
  668.             ELSE
  669.                 PicDialog.BorderCheck.SetValue 0
  670.             ENDIF
  671.             PicDialog.BorderCheck.SetThreeState FALSE
  672.             PicDialog.PicTextBox.SetText PictureFile$
  673.             PicDialog.BorderTextBox.SetText BorderFile$
  674.             IF PicDialog.PictureCheck.GetValue() THEN
  675.                 PicDialog.PicTextBox.Enable TRUE
  676.                 PicDialog.PictureButton.Enable TRUE
  677.             ELSE
  678.                 PicDialog.PicTextBox.Enable FALSE
  679.                 PicDialog.PictureButton.Enable FALSE
  680.             ENDIF
  681.             IF PicDialog.BorderCheck.GetValue() THEN
  682.                 PicDialog.BorderTextBox.Enable TRUE
  683.                 PicDialog.BorderButton.Enable TRUE
  684.             ELSE
  685.                 PicDialog.BorderTextBox.Enable FALSE
  686.                 PicDialog.BorderButton.Enable FALSE
  687.             ENDIF                    
  688.  
  689.         CASE EVENT_MOUSE_CLICK&
  690.             SELECT CASE ControlID%
  691.                 CASE PicDialog.PictureCheck.GetID()
  692.                     IF PicDialog.PictureCheck.GetValue() THEN
  693.                         PicDialog.PicTextBox.Enable TRUE
  694.                         PicDialog.PictureButton.Enable TRUE
  695.                         UsePicture = TRUE
  696.                     ELSE
  697.                         PicDialog.PicTextBox.Enable FALSE
  698.                         PicDialog.PictureButton.Enable FALSE
  699.                         UsePicture = FALSE
  700.                     ENDIF
  701.                 CASE PicDialog.BorderCheck.GetID()
  702.                     IF PicDialog.BorderCheck.GetValue() THEN
  703.                         PicDialog.BorderTextBox.Enable TRUE
  704.                         PicDialog.BorderButton.Enable TRUE
  705.                         UseBorder = TRUE
  706.                     ELSE
  707.                         PicDialog.BorderTextBox.Enable FALSE
  708.                         PicDialog.BorderButton.Enable FALSE
  709.                         UseBorder = FALSE
  710.                     ENDIF                    
  711.                 CASE PicDialog.PictureButton.GetID()
  712.                     TmpFileName$ = GETFILEBOX( \\
  713.                            "Todos los archivos|*.*", \\
  714.                            "Seleccione una imagen", \\
  715.                            FILE_OPEN )
  716.                        IF LEN(TmpFileName$) > 0 THEN
  717.                            PicDialog.PicTextBox.SetText TmpFileName$
  718.                        ENDIF
  719.                 CASE PicDialog.BorderButton.GetID()
  720.                     TmpFileName$ = GETFILEBOX( \\
  721.                            "*.*", \\
  722.                            "Seleccione un margen", \\
  723.                            FILE_OPEN )
  724.                        IF LEN(TmpFileName$) > 0 THEN
  725.                            PicDialog.BorderTextBox.SetText TmpFileName$
  726.                        ENDIF                
  727.                 CASE PicDialog.BackButton.GetID()
  728.                     LastPageX& = PicDialog.GetLeftPosition()
  729.                     LastPageY& = PicDialog.GetTopPosition()
  730.                     NoGo = FALSE
  731.                     IF PicDialog.PictureCheck.GetValue() THEN
  732.                         IF (NOT FileExists( \\
  733.                             PicDialog.PicTextBox.GetText())) THEN
  734.                         NoGo = TRUE
  735.                         ENDIF
  736.                     ELSEIF PicDialog.BorderCheck.GetValue() THEN
  737.                         IF (NOT FileExists( \\
  738.                             PicDialog.BorderTextBox.GetText())) THEN
  739.                          NoGo = TRUE
  740.                         ENDIF
  741.                     ENDIF
  742.                     IF PicDialog.PictureCheck.GetValue() AND \\
  743.                        PicDialog.BorderCheck.GetValue() AND \\
  744.                        Orient% = CAL_ORIENT_LANDSCAPE% THEN
  745.                         MBReturn% = MESSAGEBOX( "No es" + \\
  746.                                        "posible crear un calendario" + \\
  747.                                        "con orientaci≤n horizontal y" + \\
  748.                                        "tambiΘn una imagen y un margen.  " + \\
  749.                                        "No hay suficiente espacio" + \\
  750.                                        "en la pßgina." + NL2 + \\
  751.                                        "Seleccione o bien una imagen o un" + \\
  752.                                        "margen, o bien ninguno y vuΘlvalo a intentarlo.", \\
  753.                                        TITLE_INFOBOX$, \\
  754.                                        MB_OK_ONLY& )
  755.                         NoGo = TRUE
  756.                     ENDIF
  757.                     IF NOT NoGo THEN
  758.                         PictureFile$ = PicDialog.PicTextBox.GetText()
  759.                         BorderFile$ = PicDialog.BorderTextBox.GetText()
  760.                         UsePicture = PicDialog.PictureCheck.GetValue()
  761.                         UseBorder = PicDialog.BorderCheck.GetValue()
  762.                         PicDialog.CloseDialog DIALOG_RETURN_BACK%
  763.                     ENDIF
  764.                 CASE PicDialog.NextButton.GetID()
  765.                     LastPageX& = PicDialog.GetLeftPosition()
  766.                     LastPageY& = PicDialog.GetTopPosition()
  767.                     NoGo = FALSE
  768.                     IF PicDialog.PictureCheck.GetValue() THEN
  769.                         IF (NOT FileExists( \\
  770.                             PicDialog.PicTextBox.GetText())) THEN
  771.                         NoGo = TRUE
  772.                         ENDIF
  773.                     ELSEIF PicDialog.BorderCheck.GetValue() THEN
  774.                         IF (NOT FileExists( \\
  775.                             PicDialog.BorderTextBox.GetText())) THEN
  776.                          NoGo = TRUE
  777.                         ENDIF
  778.                     ENDIF
  779.                     IF PicDialog.PictureCheck.GetValue() AND \\
  780.                        PicDialog.BorderCheck.GetValue() AND \\
  781.                        Orient% = CAL_ORIENT_LANDSCAPE THEN
  782.                         MBReturn% = MESSAGEBOX( "No es" + \\
  783.                                        "posible crear un calendario" + \\
  784.                                        "con una orientaci≤n horizontal y" + \\
  785.                                        "tambiΘn una imagen y un margen.  " + \\
  786.                                        "No hay suficiente espacio" + \\
  787.                                        "en la pßgina." + NL2 + \\
  788.                                        "Seleccione o bien una imagen o un" + \\
  789.                                        "margen, o bien ninguno y vuΘlvalo a intentarlo.", \\
  790.                                        TITLE_INFOBOX$, \\
  791.                                        MB_OK_ONLY& )
  792.                         NoGo = TRUE
  793.                     ENDIF
  794.                     IF NOT NoGo THEN
  795.                         PictureFile$ = PicDialog.PicTextBox.GetText()
  796.                         BorderFile$ = PicDialog.BorderTextBox.GetText()
  797.                         UsePicture = PicDialog.PictureCheck.GetValue()
  798.                         UseBorder = PicDialog.BorderCheck.GetValue()
  799.                         PicDialog.CloseDialog DIALOG_RETURN_NEXT%
  800.                     ENDIF
  801.                 CASE PicDialog.CancelButton.GetID()
  802.                     DateDialog.CloseDialog DIALOG_RETURN_CANCEL%
  803.             END SELECT
  804.     END SELECT
  805.  
  806. END FUNCTION
  807.  
  808. '/////PROCESSING DIALOG/////////////////////////////////////////////////////
  809.  
  810. BEGIN DIALOG OBJECT ProcessingDialog 204, 50, "Asistente de calendarios - Procesando", SUB ProcessingDialogEventHandler
  811.     TEXT  39, 7, 143, 13, .Text5, "Su calendario se estß elaborando. Espere."
  812.     PROGRESS 22, 27, 162, 11, .Progress
  813. END DIALOG
  814.  
  815. SUB ProcessingDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  816.  
  817.     DIM MessageText AS STRING    ' Text to use in a MESSAGEBOX.
  818.     DIM GenReturn AS INTEGER        ' The return value of various routines.
  819.     
  820.     SELECT CASE Event%
  821.         CASE EVENT_INITIALIZATION&
  822.  
  823. ' <<<<< BEGIN REVERSE INDENT TO SAVE SPACE
  824.  
  825. ' Initialize the progress bar.
  826. ProcessingDialog.Progress.SETMINRANGE 0
  827. ProcessingDialog.Progress.SETMAXRANGE CalcHowMany( HowMany%, Month%, Year% )
  828. ProcessingDialog.Progress.SETINCREMENT 1
  829.  
  830. ' Determine the necessary page dimensions.
  831. DIM PageX AS LONG : DIM PageY AS LONG
  832. IF (Orient% = CAL_ORIENT_PORTRAIT%) THEN
  833.     PageX& = ArrayPageDim!(PageSize%, 1)
  834.     PageY& = ArrayPageDim!(PageSize%, 2)
  835. ELSE
  836.     PageX& = ArrayPageDim!(PageSize%, 2)
  837.     PageY& = ArrayPageDim!(PageSize%, 1)
  838. ENDIF
  839.  
  840. ' Connect to CorelDRAW, then create a new document for the calendar.
  841. .FileNew
  842. .SuppressPainting FALSE
  843.  
  844. ' Loop through all the calendars we have to create, and build each one.
  845. DIM Counter AS INTEGER
  846. DIM WeekdayCounter AS INTEGER
  847. DIM RowCounter AS INTEGER
  848. DIM DayCounter AS INTEGER
  849. DIM CurMonth AS INTEGER
  850. CurMonth% = Month%
  851. DIM CurYear AS INTEGER
  852. CurYear% = Year%
  853. DIM PageX_TM AS LONG    ' The horizontal page size in tenths of a micron.
  854. DIM PageY_TM AS LONG    ' The vertical page size in tenths of a micron. 
  855. DIM TitleX AS LONG        ' The generated width of the title text.
  856. DIM TitleY As LONG        ' The generated height of the title text.
  857. DIM DayX AS LONG        ' The width of the text for a specific day.
  858. DIM DayY AS LONG        ' The height of the text for a specific day.
  859. DIM NeededY AS LONG        ' The required height for the weekday names.
  860. DIM NumRows AS INTEGER    ' The number of rows needed in this month.
  861. DIM RowHeight AS LONG    ' The height of a row.
  862. DIM ColWidth AS LONG    ' The width of a column.
  863. DIM CurRow AS INTEGER    ' The current row number being processed.
  864. DIM CurCol AS INTEGER    ' The current column number being processed.
  865. DIM DaySize AS LONG        ' The size (in points) we need for the numbers.
  866. DIM WeekdayBarHeight AS LONG    ' The height of the weekday bar.
  867.  
  868. FOR Counter% = 1 TO HowMany%
  869.  
  870.     ' Create a new page.
  871.     IF NOT (Counter% = 1) THEN
  872.         .InsertPages 0, 1
  873.     ENDIF
  874.     
  875.     ' Set the page orientation.    
  876.     IF (Orient% = CAL_ORIENT_PORTRAIT%) THEN
  877.         .SetPageOrientation DRAW_ORIENT_PORTRAIT&
  878.     ELSE
  879.         .SetPageOrientation DRAW_ORIENT_LANDSCAPE&
  880.     ENDIF
  881.  
  882.     ' Set the size of the new page.    
  883.     PageX_TM& = PageX&*LENGTHCONVERT(LC_INCHES&, LC_TENTHS_OFA_MICRON&, 1)
  884.     PageY_TM& = PageY&*LENGTHCONVERT(LC_INCHES&, LC_TENTHS_OFA_MICRON&, 1)
  885.     .SetPageSize PageX_TM&, PageY_TM&
  886.  
  887.     ' Determine the boundaries within which we can draw the calendar.
  888.     ' These coordinates are relative to the center of the page.
  889.     DIM TopLeftX AS LONG : DIM TopLeftY AS LONG      ' The top left corner.
  890.     DIM BottomRightX AS LONG : DIM BottomRightY AS LONG ' The bottom right corner.
  891.     TopLeftX& = (PageX& / -2)*LENGTHCONVERT(LC_INCHES&, LC_TENTHS_OFA_MICRON&, 1)
  892.     TopLeftY& = (PageY& / 2)*LENGTHCONVERT(LC_INCHES&, LC_TENTHS_OFA_MICRON&, 1)
  893.     BottomRightX& = (PageX& / 2)*LENGTHCONVERT(LC_INCHES&, LC_TENTHS_OFA_MICRON&, 1)
  894.     BottomRightY& = (PageY& / -2)*LENGTHCONVERT(LC_INCHES&, LC_TENTHS_OFA_MICRON&, 1)
  895.  
  896.     ' Factor in the margins.
  897.     AddMargins TopLeftX&, TopLeftY&, BottomRightX&, BottomRightY&
  898.  
  899.     ' Draw the borders and/or picture, if necessary.
  900.     ' Adjust the calendar boundaries appropriately.
  901.     DoGraphics UsePicture, \\
  902.                UseBorder, \\
  903.                PictureFile$, \\
  904.                BorderFile$, \\
  905.                TopLeftX&, \\
  906.                TopLeftY&, \\
  907.                BottomRightX&, \\
  908.                BottomRightY&
  909.  
  910.     ' Create the title (the month and year).
  911.     CreateText Months$(CurMonth%) + " " + CSTR(CurYear%), \\
  912.                FontName$,                                 \\
  913.              24,                                          \\
  914.                Bold,                                      \\
  915.                Italic,                                    \\
  916.                Strikeout,                                 \\
  917.              Underline,                            \\
  918.                Red%,                                      \\
  919.                Green%,                                    \\
  920.                Blue%
  921.  
  922.     ' Create the title differently depending on the style selected.
  923.     IF CalStyle% = CAL_STYLE_SIMPLE% THEN
  924.     
  925.         ' Make the text proportional to the size it should occupy
  926.         ' on the page.
  927.         .GetSize TitleX&, TitleY&
  928.         .SetSize BottomRightX& - TopLeftX&, \\
  929.                  (BottomRightX& - TopLeftX&) * (TitleY& / TitleX&)
  930.     
  931.         ' Add in some whitespace above and below for effect.
  932.         .GetSize TitleX&, TitleY&
  933.         .SetPosition TopLeftX&, TopLeftY&
  934.         TopLeftY& = TopLeftY& - TitleY& - (0.3 * TitleY&)
  935.  
  936.     ELSEIF CalStyle% = CAL_STYLE_LEFT% THEN
  937.  
  938.         ' Rotate the text by 90 degrees.
  939.         .RotateObject 90 * 1000000, -1, 0,0
  940.  
  941.         ' Make the text proportional to the size it should occupy
  942.         ' on the page.
  943.         .GetSize TitleX&, TitleY&
  944.         .SetSize (TopLeftY& - BottomRightY&) * (TitleX& / TitleY&), \\
  945.                    TopLeftY& - BottomRightY&
  946.  
  947.         ' Position the text along the left hand side.
  948.         .SetPosition TopLeftX&, TopLeftY&
  949.         .GetSize TitleX&, TitleY&
  950.         TopLeftX& = TopLeftX& + TitleX& + (0.3 * TitleX&)
  951.  
  952.     ELSEIF CalStyle% = CAL_STYLE_RIGHT% THEN
  953.  
  954.         ' Rotate the text back by 90 degrees.
  955.         .RotateObject -90 * 1000000, -1, 0,0
  956.  
  957.         ' Make the text proportional to the size it should occupy
  958.         ' on the page.
  959.         .GetSize TitleX&, TitleY&
  960.         .SetSize (TopLeftY& - BottomRightY&) * (TitleX& / TitleY&), \\
  961.                    TopLeftY& - BottomRightY&
  962.  
  963.         ' Position the text along the right hand side.
  964.         .SetReferencePoint DRAW_REF_TOP_RIGHT&
  965.         .SetPosition BottomRightX&, TopLeftY&
  966.         .SetReferencePoint DRAW_REF_TOP_LEFT&
  967.         .GetSize TitleX&, TitleY&
  968.         BottomRightX& = BottomRightX& - TitleX& - (0.3 * TitleX&)
  969.  
  970.     ENDIF    
  971.  
  972.     ProcessingDialog.Progress.Step
  973.  
  974.     ' Determine how big the weekday names need to be.
  975.     CreateText "MiΘrcoles",                               \\
  976.                FontName$,                                 \\
  977.              24,                                    \\
  978.                Bold,                                      \\
  979.                Italic,                                    \\
  980.                Strikeout,                                 \\
  981.              Underline,                            \\
  982.                Red%,                                      \\
  983.                Green%,                                    \\
  984.                Blue%
  985.     .GetSize DayX&, DayY&
  986.     .SetSize (BottomRightX& - TopLeftX&)/7 * 0.8, \\
  987.              ((BottomRightX& - TopLeftX&)/7) * 0.8 * (DayY& / DayX&)
  988.     .GetSize DayX&, DayY&
  989.     NeededY& = DayY&
  990.     .DeleteObject
  991.     
  992.     ' Create a background rectangle.
  993.     WeekdayBarHeight& = DayY& * 2
  994.     .CreateRectangle TopLeftY&, \\
  995.                      TopLeftX&, \\
  996.                      TopLeftY& - WeekdayBarHeight&, \\
  997.                      BottomRightX&
  998.     .StoreColor DRAW_COLORMODEL_RGB&, Red%, Green%, Blue%, 0
  999.     .ApplyUniformFillColor
  1000.     .StoreColor DRAW_COLORMODEL_RGB&, Red%, Green%, Blue%, 0
  1001.     .SetOutlineColor
  1002.  
  1003.     ' Create a rectangle enclosing the whole calendar.
  1004.     .CreateRectangle TopLeftY&, TopLeftX&, BottomRightY&, BottomRightX&
  1005.     .ApplyOutline LENGTHCONVERT(LC_INCHES, LC_TENTHS_OFA_MICRON, 0.03), \\
  1006.               DRAW_OUTLINE_TYPE_SOLID, \\
  1007.               DRAW_OUTLINE_CAPS_BUTT,  \\
  1008.               DRAW_OUTLINE_JOIN_MITER, \\
  1009.               100, \\
  1010.               0, \\
  1011.               0, \\
  1012.               0, \\
  1013.               0, \\
  1014.               0
  1015.     .StoreColor DRAW_COLORMODEL_RGB&, Red%, Green%, Blue%, 0
  1016.     .SetOutlineColor
  1017.     ProcessingDialog.Progress.Step
  1018.  
  1019.     ' Generate the weekday names.
  1020.     FOR WeekdayCounter% = 1 TO 7 
  1021.     
  1022.         ' Create the text (in white), scale it, then position it.
  1023.         CreateText Weekdays$(WeekdayCounter),          \\
  1024.                     FontName$,                          \\
  1025.                  24,                              \\
  1026.                     Bold,                               \\
  1027.                     Italic,                             \\
  1028.                     Strikeout,                          \\
  1029.                   Underline,                      \\
  1030.                     255,                                \\
  1031.                     255,                                \\
  1032.                     255%
  1033.         .GetSize DayX&, DayY&
  1034.         .SetSize NeededY& * (DayX& / DayY&), NeededY&
  1035.         
  1036.         ' Center the text vertically.
  1037.         .SetReferencePoint DRAW_REF_MIDDLE_LEFT&
  1038.         .SetPosition TopLeftX& + (WeekdayCounter% - 1)* \\
  1039.                      ((BottomRightX& - TopLeftX&)/7),   \\
  1040.                      TopLeftY& - (WeekdayBarHeight&/2)
  1041.         .SetReferencePoint DRAW_REF_TOP_LEFT&
  1042.         
  1043.         ' Draw vertical rulings.
  1044.         .BeginDrawCurve  TopLeftX& + (WeekdayCounter%)* \\
  1045.                          ((BottomRightX& - TopLeftX&)/7), TopLeftY&
  1046.         .DrawCurveLineTo TopLeftX& + (WeekdayCounter%)* \\
  1047.                          ((BottomRightX& - TopLeftX&)/7), BottomRightY&
  1048.         .EndDrawCurve
  1049.         .ApplyOutline LENGTHCONVERT(LC_INCHES, LC_TENTHS_OFA_MICRON, 0.03), \\
  1050.                       DRAW_OUTLINE_TYPE_SOLID, \\
  1051.                       DRAW_OUTLINE_CAPS_BUTT,  \\
  1052.                       DRAW_OUTLINE_JOIN_MITER, \\
  1053.                       100, \\
  1054.                       0, \\
  1055.                       0, \\
  1056.                       0, \\
  1057.                       0, \\
  1058.                       0
  1059.         .StoreColor DRAW_COLORMODEL_RGB&, Red%, Green%, Blue%, 0
  1060.         .SetOutlineColor
  1061.         ProcessingDialog.Progress.Step
  1062.  
  1063.     NEXT WeekdayCounter
  1064.     
  1065.     ' Subtract the amount of space that was used by the weekdays bar.
  1066.     TopLeftY& = TopLeftY& - WeekdayBarHeight&
  1067.     
  1068.     ' Determine how many rows we need for this month.
  1069.     NumRows% = GetNumRows(CurMonth, CurYear)
  1070.  
  1071.     ' Calculate the height and width of the columns.
  1072.     RowHeight& = (TopLeftY& - BottomRightY&) / NumRows%
  1073.     ColWidth&  = (TopLeftX& - BottomRightX&) / 7
  1074.     
  1075.     ' Draw in the row lines.
  1076.     FOR RowCounter% = 1 TO (NumRows% - 1)
  1077.     
  1078.         .BeginDrawCurve TopLeftX&, TopLeftY&-RowHeight&*RowCounter%
  1079.         .DrawCurveLineTo BottomRightX&, TopLeftY&-RowHeight&*RowCounter%
  1080.         .EndDrawCurve
  1081.         .ApplyOutline LENGTHCONVERT(LC_INCHES, LC_TENTHS_OFA_MICRON, 0.03), \\
  1082.                       DRAW_OUTLINE_TYPE_SOLID, \\
  1083.                       DRAW_OUTLINE_CAPS_BUTT,  \\
  1084.                       DRAW_OUTLINE_JOIN_MITER, \\
  1085.                       100, \\
  1086.                       0, \\
  1087.                       0, \\
  1088.                       0, \\
  1089.                       0, \\
  1090.                       0
  1091.         .StoreColor DRAW_COLORMODEL_RGB&, Red%, Green%, Blue%, 0
  1092.         .SetOutlineColor
  1093.     
  1094.     NEXT RowCounter%
  1095.     ProcessingDialog.Progress.Step
  1096.  
  1097.     ' Due to the nature of typeface numerics, it would not be
  1098.     ' aesthetically pleasing to do a proportional resize on the
  1099.     ' day numbers.  So we will calculate an appropriate point size.
  1100.     DaySize& = LENGTHCONVERT( LC_TENTHS_OFA_MICRON&, \\
  1101.                               LC_POINTS&, \\
  1102.                               RowHeight& * 0.15 )
  1103.  
  1104.     ' Draw in the day numbers.
  1105.     CurRow% = 1
  1106.     CurCol% = GetWeekday(CDAT( STR(CurYear%) + "-" + STR(CurMonth%) + "-1"))
  1107.     FOR DayCounter% = 1 TO GetNumDays( CurMonth%, CurYear% )
  1108.     
  1109.         ' Create the day number.
  1110.         CreateText STR(DayCounter%),                 \\
  1111.                     FontName$,                        \\
  1112.                  DaySize&,                       \\
  1113.                     Bold,                             \\
  1114.                     Italic,                           \\
  1115.                     Strikeout,                        \\
  1116.                   Underline,                    \\
  1117.                     Red%,                             \\
  1118.                     Green%,                           \\
  1119.                     Blue% 
  1120.         .SetPosition TopLeftX&-((CurCol%-1)*ColWidth&)-ColWidth&*0.07, \\
  1121.                      TopLeftY&-(CurRow%*RowHeight&)+RowHeight&*0.92
  1122.  
  1123.         ' Update the current row and column.
  1124.         IF (CurCol% = 7) THEN
  1125.            CurCol% = 1
  1126.            CurRow% = CurRow% + 1
  1127.         ELSE
  1128.            CurCol% = CurCol% + 1
  1129.         ENDIF
  1130.  
  1131.         ' Update the progress bar.
  1132.         ProcessingDialog.Progress.Step
  1133.     
  1134.     NEXT DayCounter%
  1135.     
  1136.     ' Update the year and month we are processing.
  1137.     IF CurMonth% = 12 THEN
  1138.         CurMonth% = 1
  1139.         CurYear% = CurYear% + 1
  1140.     ELSE
  1141.         CurMonth% = CurMonth% + 1
  1142.     ENDIF
  1143.  
  1144. NEXT Counter%
  1145.  
  1146. .ResumePainting
  1147.  
  1148. GenReturn% = MESSAGEBOX( "íHa terminado de crear su calendario!", \\
  1149.                          TITLE_INFOBOX$, \\
  1150.                          MB_OK_ONLY& )
  1151. ProcessingDialog.CloseDialog DIALOG_RETURN_OK%
  1152.  
  1153. ' >>>>> END REVERSE INDENT
  1154.                                     
  1155.     END SELECT
  1156.  
  1157. END FUNCTION
  1158.  
  1159. '********************************************************************
  1160. ' MAIN
  1161. '
  1162. '
  1163. '********************************************************************
  1164.  
  1165. '/////LOCAL VARIABLES////////////////////////////////////////////////
  1166. DIM MessageText AS STRING    ' Text to use in a MESSAGEBOX.
  1167. DIM CurStep AS INTEGER        ' The user's current dialog number.
  1168.  
  1169. ' Set up a general error handler.
  1170. ON ERROR GOTO MainErrorHandler
  1171.  
  1172. ' Retrieve the directory where the script was started.
  1173. CurDir$ = GETCURRFOLDER()
  1174. IF MID(CurDir$, LEN(CurDir$), 1) = "\" THEN
  1175.     CurDir$ = LEFT(CurDir$, LEN(CurDir$) - 1)
  1176. ENDIF
  1177.  
  1178. CONST NS_FINISH%         = 0
  1179. CONST NS_INTRODIALOG%     = 1
  1180. CONST NS_SIZEDIALOG%      = 2
  1181. CONST NS_ORIENTDIALOG%     = 3
  1182. CONST NS_STYLEDIALOG%     = 4
  1183. CONST NS_DATEDIALOG%     = 5
  1184. CONST NS_PICDIALOG%       = 6
  1185. CONST NS_FONTDIALOG%      = 7
  1186.  
  1187. ' Loop, displaying dialogs in the required order.
  1188. CurStep% = NS_INTRODIALOG%
  1189. WHILE (CurStep% <> NS_FINISH%)
  1190.  
  1191.     SELECT CASE CurStep%
  1192.         CASE NS_INTRODIALOG%
  1193.             IF (LastPageX& <> -1) THEN
  1194.                 IntroDialog.Move LastPageX&, LastPageY&
  1195.             ENDIF        
  1196.             IntroDialog.IntroImage.SetImage CurDir$ + BITMAP_INTRODIALOG$
  1197.             IntroDialog.IntroImage.SetStyle STYLE_SUNKEN
  1198.             IntroDialog.IntroImage.SetStyle STYLE_IMAGE_CENTERED
  1199.             IntroDialog.SetStyle STYLE_NOMINIMIZEBOX
  1200.             GenReturn& = DIALOG(IntroDialog)
  1201.             SELECT CASE GenReturn&
  1202.                 CASE DIALOG_RETURN_NEXT%
  1203.                     CurStep% = NS_SIZEDIALOG%
  1204.                 CASE DIALOG_RETURN_CANCEL%
  1205.                     STOP        
  1206.                 CASE ELSE
  1207.                     CurStep% = NS_INTRODIALOG%
  1208.             END SELECT
  1209.  
  1210.         CASE NS_SIZEDIALOG%
  1211.             SizeDialog.Move LastPageX&, LastPageY&
  1212.             SizeDialog.SizeImage.SetImage CurDir$ + BITMAP_INTRODIALOG$
  1213.             SizeDialog.SizeImage.SetStyle STYLE_SUNKEN
  1214.             SizeDialog.SizeImage.SetStyle STYLE_IMAGE_CENTERED
  1215.             SizeDialog.SetStyle STYLE_NOMINIMIZEBOX
  1216.             GenReturn& = DIALOG(SizeDialog)
  1217.             SELECT CASE GenReturn&
  1218.                 CASE DIALOG_RETURN_NEXT%
  1219.                     CurStep% = NS_ORIENTDIALOG%
  1220.                 CASE DIALOG_RETURN_BACK%
  1221.                     CurStep% = NS_INTRODIALOG%
  1222.                 CASE DIALOG_RETURN_CANCEL%
  1223.                     STOP                            
  1224.                 CASE ELSE
  1225.                     CurStep% = NS_SIZEDIALOG%
  1226.             END SELECT
  1227.  
  1228.         CASE NS_ORIENTDIALOG%
  1229.             OrientDialog.Move LastPageX&, LastPageY&
  1230.             OrientDialog.OrientImage.SetImage CurDir$ + BITMAP_INTRODIALOG$
  1231.             OrientDialog.OrientImage.SetStyle STYLE_SUNKEN
  1232.             OrientDialog.OrientImage.SetStyle STYLE_IMAGE_CENTERED
  1233.             OrientDialog.SetStyle STYLE_NOMINIMIZEBOX
  1234.             GenReturn& = DIALOG(OrientDialog)
  1235.             SELECT CASE GenReturn&
  1236.                 CASE DIALOG_RETURN_NEXT%
  1237.                     CurStep% = NS_STYLEDIALOG%
  1238.                 CASE DIALOG_RETURN_BACK%
  1239.                     CurStep% = NS_SIZEDIALOG%
  1240.                 CASE DIALOG_RETURN_CANCEL%
  1241.                     STOP                            
  1242.                 CASE ELSE
  1243.                     CurStep% = NS_ORIENTDIALOG%
  1244.             END SELECT
  1245.             
  1246.         CASE NS_STYLEDIALOG%
  1247.             StyleDialog.Move LastPageX&, LastPageY&
  1248.             StyleDialog.StyleImage.SetImage CurDir$ + BITMAP_INTRODIALOG
  1249.             StyleDialog.StyleImage.SetStyle STYLE_SUNKEN
  1250.             StyleDialog.StyleImage.SetStyle STYLE_IMAGE_CENTERED
  1251.             StyleDialog.PreviewImage.SetStyle STYLE_SUNKEN
  1252.             StyleDialog.PreviewImage.SetStyle STYLE_IMAGE_CENTERED
  1253.             StyleDialog.SetStyle STYLE_NOMINIMIZEBOX
  1254.             GenReturn& = DIALOG(StyleDialog)
  1255.             SELECT CASE GenReturn&
  1256.                 CASE DIALOG_RETURN_NEXT%
  1257.                     CurStep% = NS_FONTDIALOG%
  1258.                 CASE DIALOG_RETURN_BACK%
  1259.                     CurStep% = NS_ORIENTDIALOG%
  1260.                 CASE DIALOG_RETURN_CANCEL%
  1261.                     STOP                            
  1262.                 CASE ELSE
  1263.                     CurStep% = NS_STYLEDIALOG%
  1264.             END SELECT
  1265.  
  1266.         CASE NS_FONTDIALOG%
  1267.             FontDialog.Move LastPageX&, LastPageY&
  1268.             FontDialog.FontImage.SetImage CurDir$ + BITMAP_INTRODIALOG
  1269.             FontDialog.FontImage.SetStyle STYLE_SUNKEN
  1270.             FontDialog.FontImage.SetStyle STYLE_IMAGE_CENTERED
  1271.             FontDialog.SetStyle STYLE_NOMINIMIZEBOX
  1272.             GenReturn& = DIALOG(FontDialog)
  1273.             SELECT CASE GenReturn&
  1274.                 CASE DIALOG_RETURN_NEXT%
  1275.                     CurStep% = NS_PICDIALOG%
  1276.                 CASE DIALOG_RETURN_BACK%
  1277.                     CurStep% = NS_STYLEDIALOG%
  1278.                 CASE DIALOG_RETURN_CANCEL%
  1279.                     STOP                            
  1280.                 CASE ELSE
  1281.                     CurStep% = NS_FONTDIALOG%
  1282.             END SELECT
  1283.  
  1284.         CASE NS_DATEDIALOG%
  1285.             DateDialog.Move LastPageX&, LastPageY&
  1286.             DateDialog.DateImage.SetImage CurDir$ + BITMAP_INTRODIALOG$
  1287.             DateDialog.DateImage.SetStyle STYLE_SUNKEN
  1288.             DateDialog.DateImage.SetStyle STYLE_IMAGE_CENTERED
  1289.             DateDialog.SetStyle STYLE_NOMINIMIZEBOX
  1290.             GenReturn& = DIALOG(DateDialog)
  1291.             SELECT CASE GenReturn&
  1292.                 CASE DIALOG_RETURN_NEXT%
  1293.                     CurStep% = NS_FINISH%
  1294.                 CASE DIALOG_RETURN_BACK%
  1295.                     CurStep% = NS_PICDIALOG%
  1296.                 CASE DIALOG_RETURN_CANCEL%
  1297.                     STOP                            
  1298.                 CASE ELSE
  1299.                     CurStep% = NS_DATEDIALOG%
  1300.             END SELECT
  1301.  
  1302.         CASE NS_PICDIALOG%
  1303.             PicDialog.Move LastPageX&, LastPageY&
  1304.             PicDialog.PicImage.SetImage CurDir$ + BITMAP_INTRODIALOG
  1305.             PicDialog.PicImage.SetStyle STYLE_SUNKEN
  1306.             PicDialog.PicImage.SetStyle STYLE_IMAGE_CENTERED
  1307.             PicDialog.SetStyle STYLE_NOMINIMIZEBOX
  1308.             GenReturn& = DIALOG(PicDialog)
  1309.             SELECT CASE GenReturn&
  1310.                 CASE DIALOG_RETURN_NEXT%
  1311.                     CurStep% = NS_DATEDIALOG%
  1312.                 CASE DIALOG_RETURN_BACK%
  1313.                     CurStep% = NS_FONTDIALOG%
  1314.                 CASE DIALOG_RETURN_CANCEL%
  1315.                     STOP                            
  1316.                 CASE ELSE
  1317.                     CurStep% = NS_PICDIALOG%
  1318.             END SELECT
  1319.  
  1320.     END SELECT
  1321. WEND
  1322.  
  1323. ' Create the calendars, then end.
  1324. GenReturn& = DIALOG(ProcessingDialog)
  1325. STOP
  1326.  
  1327. MainErrorHandler:
  1328.     ERRNUM = 0
  1329.     MessageText$ = "Ha ocurrido un error general durante el"
  1330.     MessageText$ = MessageText$ + "procesamiento del asistente." + NL2
  1331.     MessageText$ = MessageText$ + "Puede intentarlo de nuevo."
  1332.     GenReturn& = MESSAGEBOX(MessageText$, TITLE_ERRORBOX$, \\
  1333.                             MB_OK_ONLY& OR MB_EXCLAMATION_ICON&)
  1334.  
  1335.     ' Just to be safe, though DRAW is supposed to do it anyway if
  1336.     ' a script terminates, re-enable painting.
  1337.     ON ERROR RESUME NEXT
  1338.     .ResumePainting
  1339.     ERRNUM = 0
  1340.     STOP
  1341.  
  1342. '********************************************************************
  1343. '
  1344. '    Name:    CreateText (subroutine)
  1345. '
  1346. '    Action:    Creates a string of artistic text within CorelDRAW.
  1347. '              Does not size it.
  1348. '
  1349. '    Params:    InMonth - The month of the calendar.
  1350. '              InYear  - The year of the calendar.
  1351. '              InFontName - The font to use.
  1352. '            InFontSize - The size of font (points).
  1353. '              InBold - Make the font bold?
  1354. '              InItalic - Make the font italic?
  1355. '              InStrikeout - Use strikeout?
  1356. '              InRed, InGreen, InBlue - Colour values.
  1357. '
  1358. '    Returns:    None.
  1359. '
  1360. '    Comments:    None.
  1361. '
  1362. '********************************************************************
  1363. SUB CreateText ( InText AS STRING, \\
  1364.                InFontName AS STRING, \\
  1365.               InFontSize AS LONG, \\
  1366.                InBold AS BOOLEAN, \\
  1367.                InItalic AS BOOLEAN, \\
  1368.                InStrikeout AS BOOLEAN, \\
  1369.               InUnderline AS BOOLEAN, \\
  1370.               InRed AS INTEGER, \\
  1371.               InGreen AS INTEGER, \\
  1372.               InBlue AS INTEGER)
  1373.  
  1374.     DIM DrawStyleCode AS INTEGER ' The font style to send to DRAW.
  1375.     DIM DrawPointSize AS INTEGER ' The font size to send to DRAW.
  1376.     DIM DrawUnderline AS INTEGER ' The underline code to send to DRAW.
  1377.     DIM DrawStrikeout AS INTEGER ' The strikeout code to send to DRAW.
  1378.  
  1379.     ' Create the title's text.
  1380.     .CreateArtisticText InText$, 0, 0
  1381.  
  1382.     ' Determine the settings to send to DRAW.
  1383.     IF InBold AND InItalic THEN
  1384.         DrawStyleCode% = DRAW_FONT_STYLE_BOLD_ITALIC%
  1385.     ELSEIF Bold THEN
  1386.         DrawStyleCode% = DRAW_FONT_STYLE_BOLD%
  1387.     ELSEIF Italic THEN
  1388.         DrawStyleCode% = DRAW_FONT_STYLE_NORMAL_ITALIC%
  1389.     ELSE
  1390.         DrawStyleCode% = DRAW_FONT_STYLE_NORMAL%
  1391.     ENDIF 
  1392.     DrawPointSize% = InFontSize * 10 
  1393.     IF InUnderline THEN
  1394.         DrawUnderline% = DRAW_FONT_UNDERLINE_SINGLE_THICK%
  1395.     ELSE
  1396.         DrawUnderline% = DRAW_FONT_UNDERLINE_NONE%
  1397.     ENDIF
  1398.     IF InStrikeout THEN
  1399.         DrawStrikeout% = DRAW_FONT_STRIKEOUT_SINGLE_THICK%
  1400.     ELSE
  1401.         DrawStrikeout% = DRAW_FONT_STRIKEOUT_NONE%
  1402.     ENDIF
  1403.  
  1404.     ' Apply the formatting.
  1405.     .SetCharacterAttributes 0, \\
  1406.                         30000, \\
  1407.                         InFontName$, \\
  1408.                         DrawStyleCode%, \\
  1409.                         DrawPointSize%, \\
  1410.                         DrawUnderline%, \\
  1411.                         DRAW_FONT_OVERLINE_NONE%, \\
  1412.                         DrawStrikeout%, \\
  1413.                         DRAW_FONT_PLACEMENT_NORMAL%, \\
  1414.                         0,    \\ 
  1415.                         1000, \\ 
  1416.                         1000, \\
  1417.                         DRAW_FONT_ALIGNMENT_NONE%            
  1418.     .StoreColor DRAW_COLORMODEL_RGB&, InRed%, InGreen%, InBlue%, 0
  1419.     .ApplyUniformFillColor
  1420.  
  1421. END SUB
  1422.  
  1423. '********************************************************************
  1424. '
  1425. '    Name:    FileExists (function)
  1426. '
  1427. '    Action:    Determines if a given file exists.
  1428. '              If it does not exist, displays an error message.
  1429. '
  1430. '    Params:    InFileName - The file name and path to test.
  1431. '
  1432. '    Returns:    TRUE if the file exists.  FALSE otherwise, along
  1433. '              with displaying an error message.
  1434. '
  1435. '    Comments:    None.
  1436. '
  1437. '********************************************************************
  1438. FUNCTION FileExists( InFileName AS STRING ) AS BOOLEAN
  1439.  
  1440.     DIM ReturnedSize AS LONG  ' The size of InFileName.
  1441.     DIM MsgResult AS LONG     ' The result of the MESSAGEBOX call.
  1442.     
  1443.     ' Grab the size of InFileName.
  1444.     ReturnedSize& = FILESIZE( InFileName$ )
  1445.     
  1446.     ' If InFileName is empty, complain.
  1447.     IF LEN(InFileName$) = 0 THEN
  1448.         MsgResult = MESSAGEBOX("Por cada cuadro que desee comprobar, "+\\
  1449.                                "debe especificar el nombre del archivo."+\\
  1450.                                "No puede salir del espacio en blanco."+NL2+\\
  1451.                                "Vuelva a intentarlo.", \\
  1452.                                 TITLE_ERRORBOX, \\
  1453.                               MB_OK_ONLY)
  1454.         FileExists = FALSE
  1455.         EXIT FUNCTION
  1456.     ENDIF
  1457.     
  1458.     ' If it doesn't exist, complain.
  1459.     IF (ReturnedSize& > 0) THEN
  1460.         FileExists = TRUE
  1461.     ELSE
  1462.         MsgResult = MESSAGEBOX("No se ha encontrado el archivo'" + \\
  1463.                                InFileName$ + "'." + NL2 + \\
  1464.                                "Inserte el nombre de otro archivo y" + \\
  1465.                                "acceso.", \\
  1466.                                 TITLE_ERRORBOX, \\
  1467.                               MB_OK_ONLY)
  1468.         FileExists = FALSE
  1469.     ENDIF
  1470.  
  1471. END FUNCTION
  1472.  
  1473. '********************************************************************
  1474. '
  1475. '    Name:    GetWeekday (function)
  1476. '
  1477. '    Action:    Returns a number which indicates which day of the
  1478. '              week a date refers to.  (Day 1 is Sunday.)
  1479. '
  1480. '    Params:    Wkd - The date to investigate.
  1481. '
  1482. '    Returns:    A number which indicates which day of the week the
  1483. '              date falls on.
  1484. '
  1485. '    Comments:    None.
  1486. '
  1487. '********************************************************************
  1488. FUNCTION GetWeekday( Wkd AS DATE ) AS INTEGER
  1489.  
  1490.     CONST Offset% = 6       ' An offset to use in the calculations.
  1491.     DIM WeekTemp AS LONG ' A temporary variable in the calculations.
  1492.     
  1493.     ' These calculations are based on the fact that all dates in
  1494.     ' CorelSCRIPT are actually represented by the number of days
  1495.     ' since December 31, 1899.
  1496.     WeekTemp& = INT(Wkd) + Offset%
  1497.     GetWeekday = (WeekTemp& MOD 7) + 1
  1498.  
  1499. END FUNCTION
  1500.  
  1501. '********************************************************************
  1502. '
  1503. '    Name:    GetNumRows (function)
  1504. '
  1505. '    Action:    Returns the number of rows needed in a calendar whose
  1506. '              first column is Sunday for a given month and year.
  1507. '
  1508. '    Params:    InMonthNum - The month number (January is 1).
  1509. '              InYearNum  - The year.
  1510. '
  1511. '    Returns:    Either 4, 5, or 6 depending on how many rows are needed
  1512. '              (4 is very rare -- happens in Feb. 1998, for example).
  1513. '
  1514. '    Comments:    Months$(12) must be global.
  1515. '
  1516. '********************************************************************
  1517. FUNCTION GetNumRows( InMonthNum AS INTEGER, InYear AS INTEGER ) AS INTEGER
  1518.  
  1519.     DIM RowCount AS INTEGER    ' The number of rows used up so far.
  1520.     DIM CurDay AS INTEGER    ' The current day being processed.
  1521.     DIM CurDate AS DATE        ' The current date being processed.
  1522.     
  1523.     ' Loop through all the days in this month.
  1524.     RowCount% = 1
  1525.     CurDay% = 1
  1526.     WHILE CurDay% < GetNumDays(InMonthNum%, InYear%)
  1527.         CurDate = STR(CurDay%) + " " + Months$(InMonthNum%) + \\
  1528.                   " " + STR(InYear%)
  1529.         IF (GetWeekday(CurDate) = 7) THEN
  1530.             RowCount% = RowCount% + 1
  1531.         ENDIF
  1532.         CurDay% = CurDay% + 1
  1533.     WEND
  1534.     
  1535.     ' Return the result.
  1536.     GetNumRows% = RowCount%
  1537.  
  1538. END FUNCTION
  1539.  
  1540. '********************************************************************
  1541. '
  1542. '    Name:    GetNumDays (function)
  1543. '
  1544. '    Action:    Returns the number of days in a given month for a
  1545. '              given year.
  1546. '
  1547. '    Params:    InMonthNum - The month number (January is 1).
  1548. '              InYearNum  - The year.
  1549. '
  1550. '    Returns:    A number from 28 to 31.
  1551. '
  1552. '    Comments:    Leap years are properly taken into account.
  1553. '
  1554. '********************************************************************
  1555. FUNCTION GetNumDays( InMonthNum AS INTEGER, InYear AS INTEGER ) AS INTEGER
  1556.  
  1557.     ' The days in each month.
  1558.     DIM DaysInMonths%(12)
  1559.     DaysInMonths%(1) = 31        
  1560.     DaysInMonths%(2) = 28 ' Leap years are taken into account later.            
  1561.     DaysInMonths%(3) = 31
  1562.     DaysInMonths%(4) = 30
  1563.     DaysInMonths%(5) = 31
  1564.     DaysInMonths%(6) = 30
  1565.     DaysInMonths%(7) = 31
  1566.     DaysInMonths%(8) = 31
  1567.     DaysInMonths%(9) = 30
  1568.     DaysInMonths%(10) = 31
  1569.     DaysInMonths%(11) = 30
  1570.     DaysInMonths%(12) = 31    
  1571.  
  1572.     ' Adjust for leap years.
  1573.     IF (InYear MOD 4 = 0 AND InYear MOD 100 <> 0) OR InYear MOD 400 = 0 THEN
  1574.         DaysInMonths%(2) = 29
  1575.     END IF
  1576.  
  1577.     ' Return the proper number.
  1578.     GetNumDays% = DaysInMonths%(InMonthNum%)
  1579.  
  1580. END FUNCTION
  1581.  
  1582. '********************************************************************
  1583. '
  1584. '    Name:    Min (function)
  1585. '
  1586. '    Action:    Returns the lowest of two numbers.
  1587. '
  1588. '    Params:    Val1 - The first number.
  1589. '            Val2 - The second number.
  1590. '
  1591. '    Returns:    Whichever is smallest, Val1 or Val2.
  1592. '
  1593. '    Comments:    None.
  1594. '
  1595. '********************************************************************
  1596. FUNCTION Min( Val1 AS LONG, Val2 AS LONG ) AS LONG
  1597.  
  1598.     IF Val1& < Val2& THEN
  1599.         Min& = Val1&
  1600.     ELSE
  1601.         Min& = Val2&
  1602.     ENDIF
  1603.  
  1604. END FUNCTION
  1605.  
  1606. '********************************************************************
  1607. '
  1608. '    Name:    DoGraphics (subroutine)
  1609. '
  1610. '    Action:    Draws a picture and/or a border if necessary on
  1611. '              the current page in CorelDRAW.  Adjusts the calendar
  1612. '              rectangle variables to account for the picture and/or
  1613. '              border.
  1614. '
  1615. '    Params:    UsePicture - Use a picture?
  1616. '              UseBorder  - Use a border?
  1617. '              PictureFile$ - The name of the picture file to use.
  1618. '              BorderFile$  - The name of the border file to use.
  1619. '              TopLeftX& - The top left-hand corner of the calendar
  1620. '                          rectangle;  X-coordinate.
  1621. '              TopLeftY& - The top left-hand corner of the calendar
  1622. '                          rectangle;  Y-coordinate.
  1623. '              BottomRightX& - The bottom right-hand corner of the
  1624. '                              calendar rectangle;  X-coordinate.
  1625. '              BottomRightY& - The bottom right-hand corner of the
  1626. '                              calendar rectangle;  Y-coordinate.  
  1627. '
  1628. '    Returns:    None.
  1629. '
  1630. '    Comments:    The 'calendar rectangle' reflects the space where
  1631. '              the actual 'calendar' part of the calendar will be
  1632. '              drawn (minus graphics and border).
  1633. '              May stop the wizard (with an appropriate error
  1634. '              message) if the border or picture is in a format
  1635. '              DRAW cannot recognize.
  1636. '
  1637. '********************************************************************
  1638. SUB DoGraphics( InUsePicture AS BOOLEAN,       \\
  1639.                 InUseBorder AS BOOLEAN,        \\
  1640.                 InPictureFile AS STRING,       \\
  1641.              InBorderFile AS STRING,        \\
  1642.              BYREF InTopLeftX AS LONG,      \\
  1643.              BYREF InTopLeftY AS LONG,      \\
  1644.              BYREF InBottomRightX AS LONG,  \\
  1645.              BYREF InBottomRightY AS LONG )
  1646.  
  1647.     DIM CurFile AS STRING    ' The current file we're trying to import.
  1648.     DIM BorderOffsetX AS LONG ' How much space to leave on the sides.
  1649.     DIM BorderOffsetY AS LONG' How much space to leave on the top and bottom.
  1650.     DIM PicXSize AS LONG    ' The X size of the imported picture.
  1651.     DIM PicYSize AS LONG    ' The Y size of the imported picture.
  1652.     DIM AvailableX AS LONG    ' How much X space we have for the picture.
  1653.     DIM AvailableY AS LONG    ' How much Y space we have for the picture.
  1654.     DIM NeededX AS LONG        ' How big should the picture be?
  1655.     DIM NeededY AS LONG        ' How big should the picture be?
  1656.     DIM TempTopLeftY AS LONG ' A temporary variable storing InTopLeftY.
  1657.  
  1658.     ' Borders should be factored in first.
  1659.     IF InUseBorder THEN
  1660.         
  1661.         ' Set up an error handler to capture file import errors.
  1662.         ON ERROR GOTO DG_Error_Import
  1663.         
  1664.         ' Import the border.
  1665.         CurFile$ = InBorderFile$
  1666.         .FileImport CurFile$
  1667.  
  1668.         ' Successfully finished the import.
  1669.         ON ERROR EXIT
  1670.         
  1671.         ' For borders, we will resize to fit the page.  Aspect
  1672.         ' ratio is not taken into account here, because most
  1673.         ' borders look good even when distorted.
  1674.         .SetSize InBottomRightX& - InTopLeftX&, \\
  1675.                  InTopLeftY& - InBottomRightY&
  1676.         .SetPosition InTopLeftX&, InTopLeftY&
  1677.  
  1678.         ' We have no way of knowing how wide the border is.
  1679.         ' Conveniently, however, the borders in BORDERS\FRAMES
  1680.         ' need about 1.4 inches on the sides and 1.5 on the top
  1681.         ' and bottom.
  1682.         BorderOffsetX& = LENGTHCONVERT( LC_INCHES&, \\
  1683.                                        LC_TENTHS_OFA_MICRON&, \\
  1684.                                        1.4 )
  1685.         BorderOffsetY& = LENGTHCONVERT( LC_INCHES&, \\
  1686.                                        LC_TENTHS_OFA_MICRON&, \\
  1687.                                        1.5 )
  1688.         InTopLeftX& = InTopLeftX& + BorderOffsetX&
  1689.         InTopLeftY& = InTopLeftY& - BorderOffsetY&
  1690.         InBottomRightX& = InBottomRightX& - BorderOffsetX&
  1691.         InBottomRightY& = InBottomRightY& + BorderOffsetY&
  1692.  
  1693.     ENDIF
  1694.     
  1695.     ' Next, we process graphics.  These should go inside the
  1696.     ' border (if there is one) and take up the top half of
  1697.     ' the calendar rectangle.
  1698.     IF InUsePicture THEN
  1699.         
  1700.         ' Set up an error handler to capture file import errors.
  1701.         ON ERROR GOTO DG_Error_Import
  1702.         
  1703.         ' Import the picture.
  1704.         CurFile$ = InPictureFile$
  1705.         .FileImport CurFile$
  1706.  
  1707.         ' Successfully finished the import.
  1708.         ON ERROR EXIT
  1709.         
  1710.         ' Calculate how much space we have for the picture.
  1711.         AvailableX& = InBottomRightX& - InTopLeftX&
  1712.         AvailableY& = (InTopLeftY& - InBottomRightY&) / 2
  1713.         
  1714.         ' Pictures require an aspect ratio based resize so
  1715.         ' that their proportions do not become distorted.
  1716.         .GetSize PicXSize&, PicYSize&
  1717.         TempTopLeftY& = InTopLeftY&
  1718.         IF (PicXSize& > PicYSize&) THEN
  1719.             NeededX& = AvailableX& 
  1720.             NeededY& = NeededX& * (PicYSize& / PicXSize&)
  1721.  
  1722.             ' Make special provisions so that the calendar does
  1723.             ' not get too small.
  1724.             IF (NeededY& > AvailableY&) THEN
  1725.                 NeededY& = AvailableY& 
  1726.                 NeededX& = NeededY& * (PicXSize& / PicYSize&)
  1727.             ENDIF
  1728.  
  1729.             ' Recalculate the calendar space.
  1730.             InTopLeftY& = InTopLeftY& - \\
  1731.                              Min(CLNG((AvailableX& * (PicYSize& / PicXSize&))), \\
  1732.                                  AvailableY&)
  1733.         ELSE
  1734.             NeededY& = AvailableY&
  1735.             NeededX& = NeededY& * (PicXSize& / PicYSize&)
  1736.  
  1737.             ' Recalculate the calendar space.
  1738.             InTopLeftY& = InTopLeftY& - AvailableY&
  1739.         ENDIF
  1740.         .SetSize NeededX&, NeededY&
  1741.         
  1742.         ' Center the picture horizontally in the picture area.
  1743.         .SetReferencePoint DRAW_REF_TOP_MIDDLE&
  1744.         .SetPosition InTopLeftX& + (AvailableX& / 2), \\
  1745.                    TempTopLeftY&
  1746.         .SetReferencePoint DRAW_REF_TOP_LEFT&
  1747.  
  1748.         ' Add in some extra margin space above the month name.
  1749.         InTopLeftY& = InTopLeftY& - LENGTHCONVERT( LC_INCHES&, \\
  1750.                                                      LC_TENTHS_OFA_MICRON&, \\
  1751.                                                      0.25 )
  1752.  
  1753.     ENDIF
  1754.     
  1755.     EXIT SUB
  1756.     
  1757. DG_Error_Import:
  1758.     ERRNUM = 0
  1759.     DIM MsgReturn AS LONG    ' The return value of MESSAGEBOX.
  1760.     MsgReturn& = MESSAGEBOX( "No se ha podido importar el archivo'" + \\
  1761.                         CurFile$ + "'." + NL2 +     \\
  1762.                         "Verifique que CorelDRAW puede" + \\
  1763.                         "importar este tipo de archivo de grßficos" + \\
  1764.                         "y vuelva a ejecutar este asistente.", \\
  1765.                         TITLE_ERRORBOX$, \\
  1766.                         MB_STOP_ICON& )
  1767.     STOP
  1768.     
  1769. END SUB
  1770.  
  1771. '********************************************************************
  1772. '
  1773. '    Name:    AddMargins (subroutine)
  1774. '
  1775. '    Action:    Reduces the size of the calendar rectangle on
  1776. '              all sides equivalent to a margin size that will
  1777. '              work with most printers (0.5 in.)
  1778. '
  1779. '    Params:    TopLeftX& - The top left-hand corner of the calendar
  1780. '                          rectangle;  X-coordinate.
  1781. '              TopLeftY& - The top left-hand corner of the calendar
  1782. '                          rectangle;  Y-coordinate.
  1783. '              BottomRightX& - The bottom right-hand corner of the
  1784. '                              calendar rectangle;  X-coordinate.
  1785. '              BottomRightY& - The bottom right-hand corner of the
  1786. '                              calendar rectangle;  Y-coordinate.  
  1787. '
  1788. '    Returns:    None.
  1789. '
  1790. '    Comments:    The 'calendar rectangle' reflects the space where
  1791. '              the actual 'calendar' part of the calendar will be
  1792. '              drawn (minus graphics and border).
  1793. '
  1794. '********************************************************************
  1795. SUB AddMargins( BYREF InTopLeftX AS LONG, \\
  1796.                 BYREF InTopLeftY AS LONG, \\
  1797.                 BYREF InBottomRightX AS LONG, \\
  1798.                 BYREF InBottomRightY AS LONG )
  1799.  
  1800.     CONST ReductionInches! = 0.5  ' The reduction in inches.
  1801.     DIM ReductionAmount AS LONG    ' How much to reduce each side by.
  1802.  
  1803.     ' Calculate the reduction in tenths of a micron.    
  1804.     ReductionAmount& = LENGTHCONVERT( LC_INCHES&, \\
  1805.                                        LC_TENTHS_OFA_MICRON&, \\
  1806.                                        ReductionInches! )
  1807.  
  1808.     ' Make the adjustments.
  1809.     InTopLeftX& = InTopLeftX& + ReductionAmount&
  1810.     InTopLeftY& = InTopLeftY& - ReductionAmount&
  1811.     InBottomRightX& = InBottomRightX& - ReductionAmount&
  1812.     InBottomRightY& = InBottomRightY& + ReductionAmount&
  1813.  
  1814. END SUB
  1815.  
  1816. '********************************************************************
  1817. '
  1818. '    Name:    CalcHowMany (function)
  1819. '
  1820. '    Action:    Calculates the number of ticks there should be
  1821. '              on the processing progress bar.
  1822. '
  1823. '    Params:    HowMany - The number of months we're generating.
  1824. '              Month - The first month we're generating.
  1825. '              Year - The first year we're generating. 
  1826. '
  1827. '    Returns:    A LONG number of ticks.
  1828. '
  1829. '    Comments:    This calculation assumes one tick per day, plus 10
  1830. '              extra ticks for each month.
  1831. '
  1832. '********************************************************************
  1833. FUNCTION CalcHowMany( InHowMany AS INTEGER, \\
  1834.                       InMonth AS INTEGER, \\
  1835.                       InYear AS INTEGER ) AS LONG
  1836.  
  1837.     CONST Offset& = 10        ' A number to add for each month.
  1838.  
  1839.     DIM Counter AS INTEGER    ' A counter for the loop.
  1840.     DIM Accum AS LONG        ' An accumulator variable.
  1841.     DIM CurYear AS INTEGER    ' The current year.
  1842.     DIM CurMonth AS INTEGER    ' The current month.
  1843.  
  1844.     Accum& = 0
  1845.     CurMonth% = InMonth%
  1846.     CurYear% = InYear%
  1847.     FOR Counter% = 1 TO InHowMany%
  1848.         ' Update the accumulator based on the number of days in
  1849.         ' the current month.
  1850.         Accum& = Accum& + GetNumDays( CurMonth%, CurYear% ) + Offset&
  1851.  
  1852.         ' Increment the month.
  1853.         IF CurMonth% = 12 THEN
  1854.             CurMonth% = 1
  1855.             CurYear% = CurYear% + 1
  1856.         ELSE
  1857.             CurMonth% = CurMonth% + 1
  1858.         ENDIF
  1859.     NEXT Counter%
  1860.  
  1861.     ' Return the accumulated value.
  1862.     CalcHowMany& = Accum&
  1863.  
  1864. END FUNCTION
  1865.  
  1866. '********************************************************************
  1867. '
  1868. '    Name:    GetNumberOfDisplayColors (function)
  1869. '
  1870. '    Action:    Returns the number of colors the user's screen
  1871. '              currently supports.
  1872. '
  1873. '    Params:    None.  
  1874. '
  1875. '    Returns:    None.
  1876. '
  1877. '    Comments:    To avoid overflows, this routine never returns
  1878. '              a number of colors greater than 16777216.  If there
  1879. '              are more colors, it returns this maximum.
  1880. '
  1881. '********************************************************************
  1882. FUNCTION GetNumberOfDisplayColors( ) AS LONG
  1883.  
  1884.     ' Constants to send to GetDeviceCaps.
  1885.     CONST BITSPIXEL& = 12    ' Gets the number of color bits per pixel.
  1886.     CONST PLANES& = 14        ' Gets the number of color planes.
  1887.     
  1888.     DIM hDC AS LONG        ' A display DC to query.
  1889.     DIM NumColors AS SINGLE    ' The retrieved number of colors.    
  1890.     DIM NumPlanes AS LONG    ' The retrieved number of planes.
  1891.     DIM NumBitsPixel AS LONG ' The retrieved number of bits per pixel.
  1892.     DIM RetVal AS LONG        
  1893.     
  1894.     ' Create a DC, then query it for the number of colors.
  1895.     hDC& = CreateDC("DISPLAY", 0, 0, 0)
  1896.     NumPlanes& = GetDeviceCaps(hDC, Planes&)
  1897.     NumBitsPixel& = GetDeviceCaps(hDC, BitsPixel&)
  1898.     NumColors! = CSNG(2) ^ CSNG(CSNG(NumPlanes&) * CSNG(NumBitsPixel&))
  1899.     RetVal& = DeleteDC(hDC)
  1900.     
  1901.     ' To avoid overflows with really high color displays, the
  1902.     ' maximum will be 24 bit color.
  1903.     IF NumColors! > 16777216 THEN
  1904.         GetNumberOfDisplayColors = 16777216
  1905.     ELSE
  1906.         GetNumberOfDisplayColors = NumColors!
  1907.     ENDIF
  1908.     
  1909. END FUNCTION
  1910.  
  1911. END WITHOBJECT
  1912.  
  1913.