home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / design / calend / calendar.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-02-27  |  11.9 KB  |  374 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. DefInt A-Z
  178. Option Explicit
  179. Dim PreviousIndex As Integer
  180. Dim InputDate     As Variant
  181. Dim CurrentDay    As Integer
  182. Dim CurrentMonth  As Integer
  183. Dim CurrentYear   As Integer
  184. Rem Constants for 3D look.
  185. Const BUTTON_FACE = &H8000000F
  186. Const FIXED_DOUBLE = 3
  187. Const DS_MODALFRAME = &H80&
  188. Const CTL3D_ALL = &HFFFF
  189. Const GWL_STYLE = (-16)
  190. Const GWW_HINSTANCE = (-6)
  191. Rem MessageBox Constant.
  192. Const MB_ICONINFORMATION = 64
  193. Declare Function Ctl3dRegister Lib "CTL3D.DLL" (ByVal hInst)
  194. Declare Function Ctl3dUnregister Lib "CTL3D.DLL" (ByVal hInst)
  195. Declare Function Ctl3dAutoSubclass Lib "CTL3D.DLL" (ByVal hInst)
  196. Declare Function Ctl3dSubclassDlgEx Lib "CTL3D.DLL" (ByVal hWnd, ByVal Flags&)
  197. Declare Function GetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Long
  198. Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
  199. Declare Function SetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
  200. Rem Removing some menus.
  201. Declare Function GetSystemMenu% Lib "User" (ByVal hWnd%, ByVal bRevert%)
  202. Declare Function RemoveMenu% Lib "User" (ByVal hMenu%, ByVal nPosition%, ByVal wFlags%)
  203. Const MF_BYPOSITION = &H400
  204. Sub DayLabel_Click (Index As Integer)
  205. HighLight DayLabel(Index)
  206. End Sub
  207. Sub DayLabel_DblClick (Index As Integer)
  208. MsgBox DateDisplay, MB_ICONINFORMATION, "Calendar"
  209. Unload Me
  210. End Sub
  211. Sub DisplayCalendar ()
  212. Dim i           As Integer
  213. Dim WkDay       As Integer
  214. Dim DateToCheck As String
  215. Dim StartingDay As Integer
  216. Dim ValidDate   As Integer
  217. CurrentDay = Day(InputDate)
  218. CurrentMonth = Month(InputDate)
  219. CurrentYear = Year(InputDate)
  220. Rem Get the weekday to start the calendar.
  221. StartingDay = Weekday(Month(InputDate) & "/1/" & Year(InputDate))
  222. Rem Hide the beginning days not used.
  223. For i = 0 To StartingDay - 1
  224.   DayLabel(i).Visible = False
  225. Rem Loop  until the date is invalid.
  226. Rem This method saves a lot of code, ex: checking for number of days in the month, Leap year, etc.
  227.   WkDay = WkDay + 1
  228.   DateToCheck = Month(InputDate) & "/" & WkDay & "/" & Year(InputDate)
  229.   On Error Resume Next
  230.   ValidDate = Weekday(DateToCheck)
  231.   If Err Then
  232.     Exit Do
  233.   Else
  234.     DayLabel(StartingDay) = Day(DateToCheck)
  235.     DayLabel(StartingDay).Visible = True
  236.     If DayLabel(StartingDay) = CurrentDay Then
  237.       HighLight DayLabel(StartingDay)
  238.     End If
  239.   End If
  240.   StartingDay = StartingDay + 1
  241. Rem Hide the remaining controls that are not used.
  242. For i = StartingDay To 37
  243.   DayLabel(i).Visible = False
  244. End Sub
  245. Sub EnterDate_Click ()
  246. Dim DefaultDate As String
  247. DefaultDate = Format(Str$(CurrentMonth) & "/" & Str$(CurrentDay) & "/" & Str$(CurrentYear), "m/d/yy")
  248. InputDate = InputBox("Enter Date: ", "Calendar", DefaultDate)
  249. Rem Cancel was pressed or no date was entered.
  250. If InputDate = "" Then
  251.   Exit Sub
  252. End If
  253. Rem Check for a valid date.
  254. If Not IsDate(InputDate) Then
  255.   MsgBox InputDate & " is not a valid date.", 16, "Calendar"
  256.   Exit Sub
  257. End If
  258. DisplayCalendar
  259. End Sub
  260. Sub Form_Load ()
  261. Dim i           As Integer
  262. Dim J           As Integer
  263. Dim CurrentTop  As Single
  264. Dim DayCount    As Integer
  265. Dim CurrentLeft As Single
  266. Rem Display the calendar using Today's Date.
  267. CurrentMonth = Month(Now)
  268. CurrentDay = Day(Now)
  269. CurrentYear = Year(Now)
  270. Rem remove some items from the system menu.
  271. RemoveSysMenuItems Me
  272. Rem Register Ctl3D.
  273. RegCtl3D (Me.hWnd)
  274. FrmCtl3d Me
  275. Rem Center the form.
  276. Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
  277. Rem Position the first Label Control.
  278. DayLabel(0).Move 90, 585, 375, 210
  279. DayLabel(0).Alignment = 2
  280. CurrentLeft = DayLabel(0).Left
  281. CurrentTop = DayLabel(0).Top
  282. Rem Dynamically load the rest of the label controls.
  283. For J = 1 To 6
  284.   For i = 1 To 7
  285.     If DayCount = 37 Then
  286.       InputDate = Date
  287.       DisplayCalendar
  288.       Exit Sub
  289.     End If
  290.     DayCount = DayCount + 1
  291.     Load DayLabel(DayCount)
  292.     If DayCount Mod 7 = 1 Then ' Sunday
  293.       DayLabel(DayCount).ForeColor = &HFF& ' Red
  294.     End If
  295.     DayLabel(DayCount).Move CurrentLeft, CurrentTop
  296.     CurrentLeft = CurrentLeft + DayLabel(0).Width + 30
  297.   Next
  298.   CurrentTop = CurrentTop + DayLabel(0).Height
  299.   CurrentLeft = DayLabel(0).Left
  300. End Sub
  301. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  302. UnregCtl3D (Me.hWnd)
  303. End Sub
  304. Sub FrmCtl3d (Frm As Form)
  305. Dim rc            As Integer
  306. Dim hWnd          As Integer
  307. Dim BorderStyle   As Long
  308. Rem Get the form's hWnd property.
  309. hWnd = Frm.hWnd
  310. If Frm.BorderStyle = FIXED_DOUBLE Then
  311.   Frm.BackColor = BUTTON_FACE
  312.   BorderStyle = GetWindowLong(hWnd, GWL_STYLE)
  313.   BorderStyle = BorderStyle Or DS_MODALFRAME
  314.   BorderStyle = SetWindowLong(hWnd, GWL_STYLE, BorderStyle)
  315.   rc = Ctl3dSubclassDlgEx(hWnd, &H0)
  316. End If
  317. End Sub
  318. Sub HighLight (Ctl As Control)
  319. DayLabel(PreviousIndex).BorderStyle = 0
  320. DayLabel(PreviousIndex).FontBold = False
  321. Ctl.BorderStyle = 1
  322. Ctl.FontBold = True
  323. PreviousIndex = Ctl.Index
  324. CurrentDay = Ctl.Caption
  325. DateDisplay = Format(Str$(CurrentMonth) & Str$(CurrentDay) & Str$(CurrentYear), "Long Date")
  326. End Sub
  327. Sub NextMonth_Click ()
  328. InputDate = Str$(CurrentMonth) & "/" & Str$(CurrentDay) & "/" & Str$(CurrentYear)
  329. InputDate = DateAdd("m", 1, InputDate)
  330. DisplayCalendar
  331. Calendar.Refresh
  332. End Sub
  333. Sub NextYear_Click ()
  334. InputDate = Str$(CurrentMonth) & "/" & Str$(CurrentDay) & "/" & Str$(CurrentYear)
  335. InputDate = DateAdd("yyyy", 1, InputDate)
  336. DisplayCalendar
  337. Calendar.Refresh
  338. End Sub
  339. Sub PreviousMonth_Click ()
  340. InputDate = Str$(CurrentMonth) & "/" & Str$(CurrentDay) & "/" & Str$(CurrentYear)
  341. InputDate = DateAdd("m", -1, InputDate)
  342. DisplayCalendar
  343. Calendar.Refresh
  344. End Sub
  345. Sub PreviousYear_Click ()
  346. InputDate = Str$(CurrentMonth) & "/" & Str$(CurrentDay) & "/" & Str$(CurrentYear)
  347. InputDate = DateAdd("yyyy", -1, InputDate)
  348. DisplayCalendar
  349. Calendar.Refresh
  350. End Sub
  351. Sub RegCtl3D (hWnd As Integer)
  352. Dim Inst   As Integer
  353. Dim rc     As Integer
  354. Inst = GetWindowWord(hWnd, GWW_HINSTANCE)
  355. rc = Ctl3dRegister(Inst)
  356. rc = Ctl3dAutoSubclass(Inst)
  357. End Sub
  358. Sub RemoveSysMenuItems (Frm As Form)
  359. Dim rc          As Integer
  360. Dim SysMenuhWnd As Integer
  361. Rem Get the hWnd to the form's system menu.
  362. SysMenuhWnd = GetSystemMenu(Frm.hWnd, False)
  363. Rem Remove all but the Close and Move menu options.
  364. rc = RemoveMenu(SysMenuhWnd, 8, MF_BYPOSITION)
  365. rc = RemoveMenu(SysMenuhWnd, 7, MF_BYPOSITION)
  366. rc = RemoveMenu(SysMenuhWnd, 5, MF_BYPOSITION)
  367. End Sub
  368. Sub UnregCtl3D (hWnd As Integer)
  369. Dim hInst   As Integer
  370. Dim rc      As Integer
  371. hInst = GetWindowWord(hWnd, GWW_HINSTANCE)
  372. rc = Ctl3dUnregister(hInst)
  373. End Sub
  374.