Announcement

Collapse
No announcement yet.

Date Control - setting the date/no date

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Date Control - setting the date/no date

    I copied this Date Control off the forum, slightly modified it and merged it into my program. I was
    wondering if someone could help me with the code to set the displayed date different from the defaulting
    today's date. If no date has been selected, is it possible to incorporate this with a no-date selection?
    I'd like use it with a multiple date entry for.

    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' A small DDT example of how to create and use Commctrl's Calendar.
    ' Written by Borje Hagsten. Updated by Scott Turchin for easier formatting of output
    ' Public Domain = free To use And modify.
    ' Ideas for usage: Databases of all kinds, "Insert date" functions
    ' in text editors, diaries, PIMs, etc..  :-) Or setting the expiration date on an application
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    #INCLUDE "COMMCTRL.INC"
    %ID_LABEL    = 10
    %ID_CALENDAR = 20
    DECLARE CALLBACK FUNCTION DlgCallback()
    DECLARE FUNCTION GetDate(sTime AS SYSTEMTIME) AS STRING
    
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' PBMAIN - build dialog and controls
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN
        DIM hDlg AS LONG
        LOCAL iccex AS INIT_COMMON_CONTROLSEX  'Initialize the calendar
        iccex.dwSize = SIZEOF(iccex)
        iccex.dwICC = %ICC_DATE_CLASSES
        CALL InitCommonControlsEx(iccex)
        DIALOG NEW 0, "Calendar demo",,, 196, 60, %WS_SYSMENU TO hDlg
        CONTROL ADD LABEL, hDlg, %ID_LABEL, "Click at the Combo's down arrow.", 6, 30, 180, 14
        CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Close", 134, 6, 50, 14
        CONTROL ADD "SysDateTimePick32", hDlg, %ID_CALENDAR, "", 6, 6, 80, 14, %WS_CHILD OR _
            %WS_TABSTOP OR %WS_VISIBLE, CALL DlgCallback
        'Note: You can also use "SysMonthCal32", to get the calendar only,
        '      but then you also have to set the height to e.g. 100 ..  :-)
        'See Commctrl.inc for other useful Constants and Type structures
        DIALOG SHOW MODAL hDlg CALL DlgCallback
    END FUNCTION
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    'Format your output as you like
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION GetDate(sTime AS SYSTEMTIME) EXPORT AS STRING
    LOCAL tDay              AS ASCIIZ * 64
    GetDateFormat %LOCALE_USER_DEFAULT, %NULL, sTime, "MMddyyyy", tDay, 64
    FUNCTION = tDay
    END FUNCTION
    
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' The main callback function for all controls
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgCallback()
    LOCAL hdrX AS NMDATETIMECHANGE PTR
    
       SELECT CASE CBMSG
            CASE %WM_COMMAND
             IF CBCTL = %IDCANCEL THEN DIALOG END CBHNDL, (CBCTL = %IDOK)
            CASE %WM_NOTIFY
             'Use this to detect changes in the calendar
             hdrX = CBLPARAM
             SELECT CASE @hdrX.hdr.code
                    CASE %DTN_CLOSEUP
                    CASE %DTN_DROPDOWN
                    CASE %DTN_DATETIMECHANGE  'Get selected date/time
                        IF @hdrx.dwFlags <> %GDT_VALID THEN EXIT FUNCTION 'Trust but verify SYSTEMTIME STRUCTURE
                        CONTROL SET TEXT CBHNDL, %ID_LABEL, "Selected Date: " & GetDate(@hdrX.st)
             END SELECT
    
       END SELECT
    END FUNCTION
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' The End
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    ------------------
    Henning
    Henning

  • #2
    Henning, take a look in MSDN at http://msdn.microsoft.com/library/wc...i/ctrls_57.htm and you should be able to figure it out from there...

    I hope this helps!


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance,

      I'm making some baby steps here, but still at loss..

      I looked at Setting the Time at MSDN and found the message
      %MCM_SETCURSEL. Opened up COMMCTRL.INC and found %GDT_NONE
      to show a no-date. So this is what I've come up with so far;
      CONTROL SEND hDlg,%ID_CALENDAR,%MCM_SETCURSEL,%GDT_NONE,0

      So that's my command for a no-date selection.
      ....

      I assume that I can use the same CONTROL SEND command to set the
      date by replacing %GDT_NONE with the date.
      What's I don't understand is in what kind of format the date
      parameter has to be in and how to set it. ?

      ------------------
      Henning
      Henning

      Comment


      • #4
        To set the date you must first fill a SYSTEMTIME type with the relevant data
        Code:
        Local ST As SYSTEMTIME
        ST.wYear  = 2001
        ST.wMonth = 6
        ST.wDay   = 4
        Control Send hDlg, %ID_CALENDAR, %MCM_SETCURSEL, 0, VarPtr(ST)

        ------------------
        Peter.
        mailto[email protected][email protected]</A>

        [This message has been edited by Peter Lameijn (edited July 05, 2001).]
        Regards,
        Peter

        Comment


        • #5
          Thank you Peter!

          %MCM_SETTODAY didn't do it, so I had to replace it with
          %MCM_SETCURSEL for the date to change.



          ------------------
          Henning
          Henning

          Comment

          Working...
          X