home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / design / calend / calendar.frm < prev    next >
Text File  |  1995-02-27  |  12KB  |  472 lines

  1. VERSION 2.00
  2. Begin Form Calendar 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Calendar"
  6.    ClientHeight    =   2220
  7.    ClientLeft      =   2715
  8.    ClientTop       =   3555
  9.    ClientWidth     =   2985
  10.    ClipControls    =   0   'False
  11.    Height          =   2625
  12.    Icon            =   CALENDAR.FRX:0000
  13.    Left            =   2655
  14.    LinkTopic       =   "Form1"
  15.    MaxButton       =   0   'False
  16.    ScaleHeight     =   2220
  17.    ScaleWidth      =   2985
  18.    Top             =   3210
  19.    Width           =   3105
  20.    Begin CommandButton NextYear 
  21.       Caption         =   ">>"
  22.       Height          =   285
  23.       Left            =   2505
  24.       TabIndex        =   4
  25.       Top             =   1875
  26.       Width           =   400
  27.    End
  28.    Begin CommandButton NextMonth 
  29.       Caption         =   ">"
  30.       Height          =   285
  31.       Left            =   2070
  32.       TabIndex        =   3
  33.       Top             =   1875
  34.       Width           =   400
  35.    End
  36.    Begin CommandButton PreviousMonth 
  37.       Caption         =   "<"
  38.       Height          =   285
  39.       Left            =   510
  40.       TabIndex        =   1
  41.       Top             =   1875
  42.       Width           =   400
  43.    End
  44.    Begin CommandButton PreviousYear 
  45.       Caption         =   "<<"
  46.       Height          =   285
  47.       Left            =   75
  48.       TabIndex        =   0
  49.       Top             =   1875
  50.       Width           =   400
  51.    End
  52.    Begin CommandButton EnterDate 
  53.       Caption         =   "New &Date..."
  54.       FontBold        =   0   'False
  55.       FontItalic      =   0   'False
  56.       FontName        =   "MS Sans Serif"
  57.       FontSize        =   8.25
  58.       FontStrikethru  =   0   'False
  59.       FontUnderline   =   0   'False
  60.       Height          =   285
  61.       Left            =   945
  62.       TabIndex        =   2
  63.       Top             =   1875
  64.       Width           =   1100
  65.    End
  66.    Begin Line Line1 
  67.       BorderColor     =   &H00808080&
  68.       X1              =   75
  69.       X2              =   2881
  70.       Y1              =   480
  71.       Y2              =   480
  72.    End
  73.    Begin Label DateDisplay 
  74.       Alignment       =   2  'Center
  75.       BackStyle       =   0  'Transparent
  76.       ForeColor       =   &H00FF0000&
  77.       Height          =   215
  78.       Left            =   0
  79.       TabIndex        =   13
  80.       Top             =   50
  81.       Width           =   2985
  82.    End
  83.    Begin Label DayLabel 
  84.       Alignment       =   2  'Center
  85.       BackStyle       =   0  'Transparent
  86.       FontBold        =   0   'False
  87.       FontItalic      =   0   'False
  88.       FontName        =   "MS Sans Serif"
  89.       FontSize        =   8.25
  90.       FontStrikethru  =   0   'False
  91.       FontUnderline   =   0   'False
  92.       Height          =   210
  93.       Index           =   0
  94.       Left            =   90
  95.       TabIndex        =   5
  96.       Top             =   585
  97.       Width           =   375
  98.    End
  99.    Begin Label Label1 
  100.       Alignment       =   2  'Center
  101.       BackStyle       =   0  'Transparent
  102.       Caption         =   "Sat"
  103.       Height          =   285
  104.       Index           =   6
  105.       Left            =   2520
  106.       TabIndex        =   12
  107.       Top             =   270
  108.       Width           =   375
  109.    End
  110.    Begin Label Label1 
  111.       Alignment       =   2  'Center
  112.       BackStyle       =   0  'Transparent
  113.       Caption         =   "Fri"
  114.       Height          =   285
  115.       Index           =   5
  116.       Left            =   2115
  117.       TabIndex        =   11
  118.       Top             =   270
  119.       Width           =   375
  120.    End
  121.    Begin Label Label1 
  122.       Alignment       =   2  'Center
  123.       BackStyle       =   0  'Transparent
  124.       Caption         =   "Thu"
  125.       Height          =   285
  126.       Index           =   4
  127.       Left            =   1710
  128.       TabIndex        =   10
  129.       Top             =   270
  130.       Width           =   375
  131.    End
  132.    Begin Label Label1 
  133.       Alignment       =   2  'Center
  134.       BackStyle       =   0  'Transparent
  135.       Caption         =   "Wed"
  136.       Height          =   285
  137.       Index           =   3
  138.       Left            =   1305
  139.       TabIndex        =   9
  140.       Top             =   270
  141.       Width           =   375
  142.    End
  143.    Begin Label Label1 
  144.       Alignment       =   2  'Center
  145.       BackStyle       =   0  'Transparent
  146.       Caption         =   "Tue"
  147.       Height          =   285
  148.       Index           =   2
  149.       Left            =   900
  150.       TabIndex        =   8
  151.       Top             =   270
  152.       Width           =   375
  153.    End
  154.    Begin Label Label1 
  155.       Alignment       =   2  'Center
  156.       BackStyle       =   0  'Transparent
  157.       Caption         =   "Mon"
  158.       Height          =   285
  159.       Index           =   1
  160.       Left            =   495
  161.       TabIndex        =   7
  162.       Top             =   270
  163.       Width           =   375
  164.    End
  165.    Begin Label Label1 
  166.       Alignment       =   2  'Center
  167.       BackStyle       =   0  'Transparent
  168.       Caption         =   "Sun"
  169.       ForeColor       =   &H000000FF&
  170.       Height          =   285
  171.       Index           =   0
  172.       Left            =   90
  173.       TabIndex        =   6
  174.       Top             =   270
  175.       Width           =   375
  176.    End
  177. End
  178. DefInt A-Z
  179.  
  180. Option Explicit
  181.  
  182. Dim PreviousIndex As Integer
  183. Dim InputDate     As Variant
  184. Dim CurrentDay    As Integer
  185. Dim CurrentMonth  As Integer
  186. Dim CurrentYear   As Integer
  187.  
  188. Rem Constants for 3D look.
  189. Const BUTTON_FACE = &H8000000F
  190. Const FIXED_DOUBLE = 3
  191. Const DS_MODALFRAME = &H80&
  192. Const CTL3D_ALL = &HFFFF
  193. Const GWL_STYLE = (-16)
  194. Const GWW_HINSTANCE = (-6)
  195.  
  196. Rem MessageBox Constant.
  197. Const MB_ICONINFORMATION = 64
  198.  
  199. Declare Function Ctl3dRegister Lib "CTL3D.DLL" (ByVal hInst)
  200. Declare Function Ctl3dUnregister Lib "CTL3D.DLL" (ByVal hInst)
  201. Declare Function Ctl3dAutoSubclass Lib "CTL3D.DLL" (ByVal hInst)
  202. Declare Function Ctl3dSubclassDlgEx Lib "CTL3D.DLL" (ByVal hWnd, ByVal Flags&)
  203. Declare Function GetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Long
  204. Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
  205. Declare Function SetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
  206.  
  207. Rem Removing some menus.
  208. Declare Function GetSystemMenu% Lib "User" (ByVal hWnd%, ByVal bRevert%)
  209. Declare Function RemoveMenu% Lib "User" (ByVal hMenu%, ByVal nPosition%, ByVal wFlags%)
  210. Const MF_BYPOSITION = &H400
  211.  
  212. Sub DayLabel_Click (Index As Integer)
  213.  
  214. HighLight DayLabel(Index)
  215.  
  216. End Sub
  217.  
  218. Sub DayLabel_DblClick (Index As Integer)
  219.  
  220. Hide
  221.  
  222. MsgBox DateDisplay, MB_ICONINFORMATION, "Calendar"
  223.  
  224. Unload Me
  225.  
  226. End Sub
  227.  
  228. Sub DisplayCalendar ()
  229.  
  230. Dim i           As Integer
  231. Dim WkDay       As Integer
  232. Dim DateToCheck As String
  233. Dim StartingDay As Integer
  234. Dim ValidDate   As Integer
  235.  
  236. CurrentDay = Day(InputDate)
  237. CurrentMonth = Month(InputDate)
  238. CurrentYear = Year(InputDate)
  239.  
  240. Rem Get the weekday to start the calendar.
  241. StartingDay = Weekday(Month(InputDate) & "/1/" & Year(InputDate))
  242.  
  243. Rem Hide the beginning days not used.
  244. For i = 0 To StartingDay - 1
  245.   DayLabel(i).Visible = False
  246. Next
  247.  
  248. Rem Loop  until the date is invalid.
  249. Rem This method saves a lot of code, ex: checking for number of days in the month, Leap year, etc.
  250. Do
  251.   
  252.   WkDay = WkDay + 1
  253.   DateToCheck = Month(InputDate) & "/" & WkDay & "/" & Year(InputDate)
  254.   
  255.   On Error Resume Next
  256.   ValidDate = Weekday(DateToCheck)
  257.  
  258.   If Err Then
  259.     Exit Do
  260.   Else
  261.     DayLabel(StartingDay) = Day(DateToCheck)
  262.     DayLabel(StartingDay).Visible = True
  263.     If DayLabel(StartingDay) = CurrentDay Then
  264.       HighLight DayLabel(StartingDay)
  265.     End If
  266.   End If
  267.   
  268.   StartingDay = StartingDay + 1
  269.  
  270. Loop
  271.  
  272. Rem Hide the remaining controls that are not used.
  273. For i = StartingDay To 37
  274.   DayLabel(i).Visible = False
  275. Next
  276.  
  277. End Sub
  278.  
  279. Sub EnterDate_Click ()
  280.  
  281. Dim DefaultDate As String
  282.  
  283. DefaultDate = Format(Str$(CurrentMonth) & "/" & Str$(CurrentDay) & "/" & Str$(CurrentYear), "m/d/yy")
  284.  
  285. InputDate = InputBox("Enter Date: ", "Calendar", DefaultDate)
  286.  
  287. Rem Cancel was pressed or no date was entered.
  288. If InputDate = "" Then
  289.   Exit Sub
  290. End If
  291.  
  292. Rem Check for a valid date.
  293. If Not IsDate(InputDate) Then
  294.   MsgBox InputDate & " is not a valid date.", 16, "Calendar"
  295.   Exit Sub
  296. End If
  297.  
  298. DisplayCalendar
  299.  
  300.  
  301. End Sub
  302.  
  303. Sub Form_Load ()
  304.  
  305. Dim i           As Integer
  306. Dim J           As Integer
  307. Dim CurrentTop  As Single
  308. Dim DayCount    As Integer
  309. Dim CurrentLeft As Single
  310.  
  311. Rem Display the calendar using Today's Date.
  312. CurrentMonth = Month(Now)
  313. CurrentDay = Day(Now)
  314. CurrentYear = Year(Now)
  315.  
  316. Rem remove some items from the system menu.
  317. RemoveSysMenuItems Me
  318.  
  319. Rem Register Ctl3D.
  320. RegCtl3D (Me.hWnd)
  321. FrmCtl3d Me
  322.  
  323. Rem Center the form.
  324. Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
  325.  
  326. Rem Position the first Label Control.
  327. DayLabel(0).Move 90, 585, 375, 210
  328. DayLabel(0).Alignment = 2
  329.  
  330. CurrentLeft = DayLabel(0).Left
  331. CurrentTop = DayLabel(0).Top
  332.  
  333. Rem Dynamically load the rest of the label controls.
  334. For J = 1 To 6
  335.   For i = 1 To 7
  336.     If DayCount = 37 Then
  337.       InputDate = Date
  338.       DisplayCalendar
  339.       Exit Sub
  340.     End If
  341.     DayCount = DayCount + 1
  342.     Load DayLabel(DayCount)
  343.     If DayCount Mod 7 = 1 Then ' Sunday
  344.       DayLabel(DayCount).ForeColor = &HFF& ' Red
  345.     End If
  346.     DayLabel(DayCount).Move CurrentLeft, CurrentTop
  347.     CurrentLeft = CurrentLeft + DayLabel(0).Width + 30
  348.   Next
  349.   CurrentTop = CurrentTop + DayLabel(0).Height
  350.   CurrentLeft = DayLabel(0).Left
  351. Next
  352.  
  353. End Sub
  354.  
  355. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  356.  
  357. UnregCtl3D (Me.hWnd)
  358.  
  359. End Sub
  360.  
  361. Sub FrmCtl3d (Frm As Form)
  362.  
  363. Dim rc            As Integer
  364. Dim hWnd          As Integer
  365. Dim BorderStyle   As Long
  366.  
  367. Rem Get the form's hWnd property.
  368. hWnd = Frm.hWnd
  369.  
  370. If Frm.BorderStyle = FIXED_DOUBLE Then
  371.   Frm.BackColor = BUTTON_FACE
  372.   BorderStyle = GetWindowLong(hWnd, GWL_STYLE)
  373.   BorderStyle = BorderStyle Or DS_MODALFRAME
  374.   BorderStyle = SetWindowLong(hWnd, GWL_STYLE, BorderStyle)
  375.   rc = Ctl3dSubclassDlgEx(hWnd, &H0)
  376. End If
  377.  
  378. End Sub
  379.  
  380. Sub HighLight (Ctl As Control)
  381.  
  382. DayLabel(PreviousIndex).BorderStyle = 0
  383. DayLabel(PreviousIndex).FontBold = False
  384.  
  385. Ctl.BorderStyle = 1
  386. Ctl.FontBold = True
  387.   
  388. PreviousIndex = Ctl.Index
  389.  
  390. CurrentDay = Ctl.Caption
  391.  
  392. DateDisplay = Format(Str$(CurrentMonth) & Str$(CurrentDay) & Str$(CurrentYear), "Long Date")
  393.  
  394. End Sub
  395.  
  396. Sub NextMonth_Click ()
  397.  
  398. InputDate = Str$(CurrentMonth) & "/" & Str$(CurrentDay) & "/" & Str$(CurrentYear)
  399. InputDate = DateAdd("m", 1, InputDate)
  400. DisplayCalendar
  401.  
  402. Calendar.Refresh
  403.  
  404. End Sub
  405.  
  406. Sub NextYear_Click ()
  407.  
  408. InputDate = Str$(CurrentMonth) & "/" & Str$(CurrentDay) & "/" & Str$(CurrentYear)
  409. InputDate = DateAdd("yyyy", 1, InputDate)
  410. DisplayCalendar
  411.  
  412. Calendar.Refresh
  413.  
  414. End Sub
  415.  
  416. Sub PreviousMonth_Click ()
  417.  
  418. InputDate = Str$(CurrentMonth) & "/" & Str$(CurrentDay) & "/" & Str$(CurrentYear)
  419. InputDate = DateAdd("m", -1, InputDate)
  420. DisplayCalendar
  421.  
  422. Calendar.Refresh
  423.  
  424. End Sub
  425.  
  426. Sub PreviousYear_Click ()
  427.  
  428. InputDate = Str$(CurrentMonth) & "/" & Str$(CurrentDay) & "/" & Str$(CurrentYear)
  429. InputDate = DateAdd("yyyy", -1, InputDate)
  430. DisplayCalendar
  431.  
  432. Calendar.Refresh
  433.  
  434. End Sub
  435.  
  436. Sub RegCtl3D (hWnd As Integer)
  437.  
  438. Dim Inst   As Integer
  439. Dim rc     As Integer
  440.  
  441. Inst = GetWindowWord(hWnd, GWW_HINSTANCE)
  442. rc = Ctl3dRegister(Inst)
  443. rc = Ctl3dAutoSubclass(Inst)
  444.  
  445. End Sub
  446.  
  447. Sub RemoveSysMenuItems (Frm As Form)
  448.  
  449. Dim rc          As Integer
  450. Dim SysMenuhWnd As Integer
  451.  
  452. Rem Get the hWnd to the form's system menu.
  453. SysMenuhWnd = GetSystemMenu(Frm.hWnd, False)
  454.  
  455. Rem Remove all but the Close and Move menu options.
  456. rc = RemoveMenu(SysMenuhWnd, 8, MF_BYPOSITION)
  457. rc = RemoveMenu(SysMenuhWnd, 7, MF_BYPOSITION)
  458. rc = RemoveMenu(SysMenuhWnd, 5, MF_BYPOSITION)
  459.  
  460. End Sub
  461.  
  462. Sub UnregCtl3D (hWnd As Integer)
  463.  
  464. Dim hInst   As Integer
  465. Dim rc      As Integer
  466.  
  467. hInst = GetWindowWord(hWnd, GWW_HINSTANCE)
  468. rc = Ctl3dUnregister(hInst)
  469.  
  470. End Sub
  471.  
  472.