home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / dt01 / dt01.bas < prev    next >
BASIC Source File  |  1993-12-01  |  2KB  |  56 lines

  1.  
  2.  
  3.     ' ---------------------------------------------
  4.     ' I don't like globals any more than you.
  5.     ' The alternatives are not so brilliant either.
  6.     ' ---------------------------------------------
  7.     Global gDate
  8.  
  9.     Type POINTAPI
  10.     x As Integer
  11.     y As Integer
  12.     End Type
  13.  
  14.     ' Converts the client coordinates of a given point on the screen to screen coordinates.
  15.     Declare Sub ClientToScreen Lib "User" (ByVal hWnd As Integer, lpPoint As POINTAPI)
  16.  
  17. Sub calendar (cbo As ComboBox)
  18.     
  19.     Dim lp As POINTAPI
  20.  
  21.     ' Set global date, so (.frm) level can see it.
  22.     gDate = cbo.Text
  23.  
  24.     ' -----------------------------------------------------------------
  25.     ' My plan is to position the calendar display directly under
  26.     ' the 'Combo Box'. (good plan). We can get the 'combo bottom'
  27.     ' co-ordinate simply by taking the form top (combo's parent top)
  28.     ' and adding the combo's top & combo's height.
  29.     ' A problem occurs however, if the combo is 'inside' another
  30.     ' control, ie: a frame control. We need then to add that control's
  31.     ' top property to get the correct co-ordinate. What if that frame
  32.     ' is within another frame? and so on... All we want basically,
  33.     ' is the absolute screen location of the combo box, and not it's
  34.     ' "relativitiness" within other controls.
  35.     ' The API function "ClientToScreen" will give us the absolute
  36.     ' screen location of a control. Converting the result from pixels
  37.     ' into twips gives the point we want.
  38.     ' ------------------------------------------------------------------
  39.  
  40.         lp.x = 0
  41.         lp.y = 0
  42.         ClientToScreen cbo.hWnd, lp
  43.  
  44.     ' Position calendar underneath ComboBox
  45.     frmCalendar.Top = lp.y * screen.TwipsPerPixelY + cbo.Height
  46.     frmCalendar.Left = lp.x * screen.TwipsPerPixelX
  47.  
  48.     frmCalendar.Show 1
  49.  
  50.     cbo.Text = Format$(gDate, "dd-mmm-yyyy")
  51.     cbo.SetFocus
  52.     SendKeys "%{UP}"
  53.  
  54. End Sub
  55.  
  56.