How do you convert the date information resulting from a call to SelectDay,
so that it can be displayed in a non-editable field on a form?  I am working
in C with CodeWarrior.  Here is my current coding attempt.  Is there a
simpler way to allow the user to select a date, and then display the
selected date according to the user preference for date format?

static void ShowDatePicker (void)
{
        CharPtr titlePtr;
        VoidHand titleHand;
        SWord month, day, year;
        FieldPtr dateFieldPtr;
        FormPtr frmPtr;
        CharPtr datePtr;
        VoidHand dateHand;
        Byte dayB, monthB;
        Word yearW;
        DateFormatType dateFormat;

        // get the title for the date picker dialog box
        titleHand = DmGetResource (strRsc, 1000);
        titlePtr = MemHandleLock (titleHand);

        // provide the SelectDay function with a valid date
        day = 21;
        month = 3;
        year = 1965;
        
        // display the date picker
        if (SelectDay (selectDayByDay, &month, &day, &year, titlePtr))
        {
                dayB = (Byte)day;
                monthB = (Byte)month;
                yearW = (Word)year;
                
                dateHand = DmGetResource (strRsc, 1100);
                datePtr = MemHandleLock (dateHand);
                
                //get the current user preference for date format

                dateFormat =
(DateFormatType)PrefGetPreference(prefDateFormat);
                
                //convert the date information returned from SelectDay to a
string
                DateToDOWDMFormat (monthB, dayB, yearW, dateFormat,
datePtr);
                
                //display a date string in the date field on the form
                frmPtr = FrmGetActiveForm();
                dateFieldPtr =
FrmGetObjectPtr(frmPtr,FrmGetObjectIndex(frmPtr,DateField));
                FldSetTextAllocatedSize(dateFieldPtr,StrLen(datePtr)+1);
                FldSetTextPtr(dateFieldPtr,datePtr);
                FldDrawField(dateFieldPtr);     
        }
        MemHandleUnlock (titleHand);
        MemHandleUnlock (dateHand);
}



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to