home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / tool / various / kalend / test3.frm < prev    next >
Text File  |  1995-02-27  |  8KB  |  274 lines

  1. VERSION 2.00
  2. Begin Form Form3 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Drag 'N Drop (and DrawOnDay event)"
  5.    ClientHeight    =   3780
  6.    ClientLeft      =   3210
  7.    ClientTop       =   645
  8.    ClientWidth     =   6450
  9.    Height          =   4710
  10.    Left            =   3150
  11.    LinkTopic       =   "Form3"
  12.    ScaleHeight     =   3780
  13.    ScaleWidth      =   6450
  14.    Top             =   -225
  15.    Width           =   6570
  16.    Begin PictureBox pctTop 
  17.       Align           =   1  'Align Top
  18.       BackColor       =   &H00C0C0C0&
  19.       Height          =   600
  20.       Left            =   0
  21.       ScaleHeight     =   570
  22.       ScaleWidth      =   6420
  23.       TabIndex        =   1
  24.       Top             =   0
  25.       Width           =   6450
  26.       Begin TextBox Text1 
  27.          DragIcon        =   TEST3.FRX:0000
  28.          Height          =   300
  29.          Left            =   4290
  30.          TabIndex        =   2
  31.          Text            =   "Text1"
  32.          Top             =   0
  33.          Width           =   2010
  34.       End
  35.       Begin Label Label2 
  36.          BackColor       =   &H00C0C0C0&
  37.          Caption         =   "Or, drag a date from the Kalendar to the Text Box or another date."
  38.          FontBold        =   0   'False
  39.          FontItalic      =   0   'False
  40.          FontName        =   "MS Sans Serif"
  41.          FontSize        =   8.25
  42.          FontStrikethru  =   0   'False
  43.          FontUnderline   =   0   'False
  44.          Height          =   210
  45.          Left            =   60
  46.          TabIndex        =   4
  47.          Top             =   300
  48.          Width           =   5775
  49.       End
  50.       Begin Label Label1 
  51.          BackColor       =   &H00C0C0C0&
  52.          Caption         =   "Type something here and drag it to the Kalendar."
  53.          FontBold        =   0   'False
  54.          FontItalic      =   0   'False
  55.          FontName        =   "MS Sans Serif"
  56.          FontSize        =   8.25
  57.          FontStrikethru  =   0   'False
  58.          FontUnderline   =   0   'False
  59.          Height          =   210
  60.          Left            =   75
  61.          TabIndex        =   3
  62.          Top             =   60
  63.          Width           =   4230
  64.       End
  65.    End
  66.    Begin Kalendar Kalendar1 
  67.       BackColor       =   &H00FFFFFF&
  68.       BorderStyle     =   1  'Fixed Single
  69.       DateDispStyle   =   2  'User
  70.       DayAlignment    =   0  'Upper Left
  71.       DOWAlign        =   2  'Center
  72.       DOWBackColor    =   &H00808080&
  73.       DOWBorder       =   -1  'True
  74.       DOWDispStyle    =   2  'Medium
  75.       DOWFontBold     =   0   'False
  76.       DOWFontItalic   =   0   'False
  77.       DOWFontName     =   "Arial"
  78.       DOWFontSize     =   10
  79.       DOWFontStrikeThru=   0   'False
  80.       DOWFontUnderline=   0   'False
  81.       DOWForeColor    =   &H00FFFFFF&
  82.       DragIcon        =   TEST3.FRX:0302
  83.       EnableKeys      =   0   'False
  84.       FirstDOW        =   0  'Sunday
  85.       FixedDayHeight  =   0   'False
  86.       FontBold        =   0   'False
  87.       FontItalic      =   0   'False
  88.       FontName        =   "Arial"
  89.       FontSize        =   9.75
  90.       FontStrikethru  =   0   'False
  91.       FontUnderline   =   0   'False
  92.       ForeColor       =   &H00000000&
  93.       Height          =   3255
  94.       Left            =   0
  95.       LineColor       =   &H00000000&
  96.       MonAlign        =   2  'Center
  97.       MonBackColor    =   &H00C0C0C0&
  98.       MonDispStyle    =   2  'Month/Year
  99.       MonFontBold     =   0   'False
  100.       MonFontItalic   =   0   'False
  101.       MonFontName     =   "Times New Roman"
  102.       MonFontSize     =   14
  103.       MonFontStrikeThru=   0   'False
  104.       MonFontUnderline=   0   'False
  105.       MonForeColor    =   &H00000000&
  106.       OtherMonBackColor=   &H00C0C0C0&
  107.       OtherMonForeColor=   &H00FFFFFF&
  108.       SelDayBackColor =   &H00C0C0C0&
  109.       SelDayForeColor =   &H00000000&
  110.       ShowAllDays     =   0   'False
  111.       ShowArrows      =   -1  'True
  112.       ShowLines       =   -1  'True
  113.       ShowSelection   =   0   'False
  114.       TabIndex        =   0
  115.       Text            =   "06/16/94"
  116.       Top             =   585
  117.       Width           =   6435
  118.    End
  119.    Begin Menu mnuFile 
  120.       Caption         =   "&File"
  121.       Begin Menu mnuFPrint 
  122.          Caption         =   "&Print"
  123.       End
  124.    End
  125. End
  126. Option Explicit
  127.  
  128. Dim draggingDay As Variant
  129.  
  130. Dim couldDrag As Integer
  131. Dim downAtX As Single, downAtY As Single
  132.  
  133. Dim txtHeight As Long       ' Used to determine how much space is required to show the day numbers.
  134.                 ' It is set differently for the printer and the screen.
  135.  
  136. Sub Form_Activate ()
  137.     SetDescription Sample3Description()
  138. End Sub
  139.  
  140. Sub Form_Load ()
  141.     Kalendar1.Text = Date
  142.  
  143.     txtHeight = TextHeight("I") / Screen.TwipsPerPixelY
  144. End Sub
  145.  
  146. Sub Form_Resize ()
  147.     If Form3.ScaleWidth > 0 And Form3.ScaleHeight - pctTop.Height > 0 Then
  148.     Kalendar1.Move 0, pctTop.Height, Form3.ScaleWidth, Form3.ScaleHeight - pctTop.Height
  149.     End If
  150. End Sub
  151.  
  152. Sub Kalendar1_DragDrop (Source As Control, x As Single, y As Single)
  153.     Kalendar1.PointX = x
  154.     Kalendar1.PointY = y
  155.  
  156.     If Kalendar1.DateAtPoint <> "" Then
  157.  
  158.     If TypeOf Source Is TextBox Then
  159.         DateInfoAdd (Kalendar1.DateAtPointJul), (Text1.Text)
  160.         Text1.Text = ""
  161.     Else
  162.         DateInfoMove (draggingDay), (Kalendar1.DateAtPointJul)
  163.     End If
  164.     Kalendar1.Refresh
  165.     End If
  166. End Sub
  167.  
  168. Sub Kalendar1_DrawOnDay (hDC As Integer, STATE As Integer, theDay As Long, x As Single, y As Single, x2 As Single, y2 As Single)
  169. Dim retval As Integer
  170. Dim r As Rect
  171. Dim StrTmp As String
  172. Dim oldColor As Long, oldTextColor As Long
  173. Dim lx As Long
  174. Dim oldBkMode As Integer
  175. Dim OldFont As Integer
  176. Dim HFont As Integer
  177. Dim th As Long
  178.  
  179.     '--- Draw out some text
  180.     StrTmp = GetDateInfo(theDay)
  181.  
  182.     If Len(StrTmp) > 0 Then
  183.     '--- Make a Windows API rectangle to draw in.
  184.     KalWindowAPIRect x, y, x2, y2, r
  185.     InflateRect r, -1, -1
  186.     
  187.     r.top = r.top + txtHeight
  188.     
  189.     '--- Set up the drawing information
  190.     oldBkMode = setBkMode(hDC, TRANSPARENT)
  191.     oldTextColor = SetTextColor(hDC, RGB(0, 128, 0))
  192.     
  193.     ' Create an 8 point Arial font, and select into device context.
  194.     HFont = CreateFont(-(8 * GetDeviceCaps(hDC, LOGPIXELSY) / 72), 0, 0, 0, FW_NORMAL, False, False, False, 0, 0, 0, 0, DEFAULT_PITCH Or FF_DONTCARE, "Arial")
  195.     OldFont = SelectObject(hDC, HFont)
  196.     
  197.     retval = DrawText(hDC, StrTmp, Len(StrTmp), r, DT_LEFT Or DT_WORDBREAK)
  198.     
  199.     ' Clean up after myself.
  200.     retval = SelectObject(hDC, OldFont)
  201.     retval = DeleteObject(HFont)
  202.     
  203.     '--- Restore the old drawing information
  204.     oldBkMode = setBkMode(hDC, oldBkMode)
  205.     lx = SetTextColor(hDC, oldTextColor)
  206.     End If
  207. End Sub
  208.  
  209. Sub Kalendar1_MouseDown (Button As Integer, Shift As Integer, x As Single, y As Single)
  210.  
  211.     Kalendar1.PointX = x
  212.     Kalendar1.PointY = y
  213.  
  214.     If Kalendar1.DateAtPoint <> "" Then
  215.     downAtX = x
  216.     downAtY = y
  217.     couldDrag = True
  218.     End If
  219. End Sub
  220.  
  221. Sub Kalendar1_MouseMove (Button As Integer, Shift As Integer, x As Single, y As Single)
  222.  
  223.     If couldDrag And (Abs(downAtX - x) > 75 Or Abs(downAtY - y) > 75) Then
  224.     couldDrag = False
  225.     Kalendar1.Drag 1
  226.     draggingDay = Kalendar1.DateAtPointJul
  227.     End If
  228. End Sub
  229.  
  230. Sub Kalendar1_MouseUp (Button As Integer, Shift As Integer, x As Single, y As Single)
  231.  
  232.     couldDrag = False
  233.     Kalendar1.Drag 2
  234. End Sub
  235.  
  236. Sub mnuFPrint_Click ()
  237. Dim saveBackColor As Long
  238.  
  239.     saveBackColor = Kalendar1.MonBackColor
  240.     txtHeight = TextHeight("I") / Printer.TwipsPerPixelY
  241.  
  242.     Kalendar1.MonBackColor = RGB(255, 255, 255)
  243.     Kalendar1.PrintHDC = Printer.hDC
  244.     Kalendar1.PrintAction = KAL_PRINT_PORTRAIT
  245.     
  246.     Kalendar1.MonBackColor = saveBackColor
  247.     txtHeight = TextHeight("I") / Screen.TwipsPerPixelY
  248.     
  249.     Printer.EndDoc
  250. End Sub
  251.  
  252. Function Sample3Description () As String
  253. Dim s As String
  254.  
  255.     s = "This sample shows drag and drop implemented in a Kalendar. The "
  256.     s = s & "DrawOnDay event is used to display the text. " & CR
  257.     s = s & "NOTE: Maximize the window to see more of the text."
  258.  
  259.     Sample3Description = s
  260. End Function
  261.  
  262. Sub Text1_DragDrop (Source As Control, x As Single, y As Single)
  263.     Text1.Text = GetDateInfo((draggingDay))
  264. End Sub
  265.  
  266. Sub Text1_MouseDown (Button As Integer, Shift As Integer, x As Single, y As Single)
  267.     Text1.Drag 1
  268. End Sub
  269.  
  270. Sub Text1_MouseUp (Button As Integer, Shift As Integer, x As Single, y As Single)
  271.     Text1.Drag 2
  272. End Sub
  273.  
  274.