Get date from monthcalendar control

Started by Gary Stout, January 13, 2015, 10:15:29 PM

Previous topic - Next topic

Gary Stout


Does anyone have any tips or sample code to read the date from a monthcalendar control? I searched the forums and found some samples of how to set the date of the calendar control, but so far haven't found what it takes to read the date from it. Just for text purposes, I tried to read the control using FF_Control_GetText, but that doesn't return anything.

Thanks again,
Gary

Gary Stout

#1
I think I am close, but not exactly sure what to do. In searching through Jose' wrappers, I found the MonthCalCtrl.INC, which contains a wrapper for MonthCal_GetCurSel ( BYVAL hmc AS DWORD,BYREF lpSysTime AS SYSTEMTIME ) AS LONG.
I understand the first parameter is the MonthCalendar control handle, but I don't have a clue what I need for the 2nd parameter.

Thanks,
Gary

UPDATE...got it! I found some sample code on the PB forums that Borje had posted that showed me what I needed.

Paul Squires

Don't forget to check Jose's help files because he has many Month Calendar wrappers explained in the WindowsApiHeaders.chm file.

BTW, the SYSTEMTIME structure is a common TYPE defined in in the #Includes:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724950%28v=vs.85%29.aspx
Paul Squires
PlanetSquires Software

Gary Stout

Thanks Paul,

I have been looking through the help file and browsing all of the wrappers available for the many different controls! Wow! Jose has given us a bunch to work with there (Big Thanks Jose!). I really didn't even know all of those wrappers were there until I started researching the Calendar control.

Gary

Richard Kelly

This is the basics of what I have used for some time.

I have a calendar form available on demand by other portions of my applications. This is the function they call when they want to pop up a calendar. You can have the calendar initial date set to whatever you want by passing a pointer over to the forms create method.


Function SelectDate (ByVal hWnd As Long, _
                     ByVal StartingDate As SYSTEMTIME Ptr, _
                     ByRef SelectedDate As SYSTEMTIME) As Long
                     
Local nReturn        As Long

   nReturn = Calendar_Show (hWnd, %TRUE, StartingDate)
   
   Select Case nReturn
   
      Case <> %FALSE
     
         SelectedDate.wYear = Hi(Word, nReturn)
   
         SelectedDate.wMonth = Hi(Byte,Lo(Word,nReturn))
   
         SelectedDate.wDay = Lo(Byte,Lo(Word,nReturn))
         
         nReturn = %TRUE
     
   End Select
   
   Function = nReturn
   
End Function


In the calendar forms CREATE function, pick up any initial date and set the calendar shown to that date.


If UserData <> 0 Then
   
   SendMessage(HWND_CALENDAR_MONTHCALENDAR, %MCM_SETCURSEL, 0, UserData)
     
End If


In whatever control you use to indicate that the currently selected date is to be passed back (like a button control), compress the date into a LONG and send it back.


Local nSelectedDate        As SYSTEMTIME
Local nMonthDay            As Word
Local nSelectDate          As Long

    MonthCal_GetCurSel (HWND_CALENDAR_MONTHCALENDAR, nSelectedDate)
   
    nMonthDay = Mak (Word, nSelectedDate.wDay, nSelectedDate.wMonth)
   
    nSelectDate = Mak (Dword, nMonthDay, nSelectedDate.wYear)
   
    FF_CloseForm (HWND_CALENDAR, nSelectDate)


Rick Kelly

Gary Stout