Further to the above;
If we want to use the short of long date formats that are set in the windows system, we can set the style of the TDtPicker object to DTS_SHORTDATEFOMAT (= 0 and is the default) or DTS_LONGDATEFORMAT (=4).
For blank dates 'or' the style with DTS_SHOWNONE (= 2 ) (eg. oDtp:nStyle := nor( oDtp:nStyle, 2 ).
Now, we can also use the same class for timeformats or composite DATETIME formats also.
for pure time format ( using DATETIME value ) :
oDtp:nStyle := DTS_TIMEFORMAT
(But this needs some changes in the datepick.c, as explained later).
We can also use this for full datetime values by setting our own format as 'dd/MM/yyy HH:mm:ss' ( or anything like that with any additional text also)
Changes to be made in datepick.c ( to properly handle time part of DATETIME values) :
While setting we need to set hour, mins, secs and millsecs also. Similary while getting, we need to set hour, mins, secs, millisecs also in the datetime value. These changes will make the class useful for picking date or time or datetime.
my revised code is like this :
SETDATETIMEPICK( hWnd, dDateTime, GTD_NONE )
GETDATETIMEPICK( hWnd ) --> dDateTime
- Code: Select all Expand view
HB_FUNC ( SETDATEPICK ) // (hWnd, tDateTime, GTD_NONE )
{
SYSTEMTIME sysTime;
PHB_ITEM pDate;
int iYear, iMonth, iDay, iHour, iMinute, iSecs, iMilli ;
DOUBLE dSecs ;
pDate = hb_param( 2, HB_IT_DATE );
hb_itemGetDT( pDate, &iYear, &iMonth, &iDay, &iHour, &iMinute, &dSecs );
iSecs = (int) dSecs;
dSecs -= (double) iSecs;
dSecs *= 1000.0;
iMilli = (int) dSecs;
sysTime.wYear = iYear;
sysTime.wMonth = iMonth;
sysTime.wDay = iDay;
sysTime.wDayOfWeek = 0;
sysTime.wHour = iHour;
sysTime.wMinute = iMinute;
sysTime.wSecond = iSecs ;
sysTime.wMilliseconds = iMilli ;
SendMessage( ( HWND ) hb_parnl( 1 ), DTM_SETSYSTEMTIME, hb_parni( 3 ),
( LPARAM ) &sysTime );
}
HB_FUNC( GETDATEPICK ) // (hWnd)
SYSTEMTIME st;
DOUBLE dSecs ;
SendMessage( ( HWND ) hb_parnl( 1 ), DTM_GETSYSTEMTIME, 0, ( LPARAM ) &st );
dSecs = (DOUBLE) st.wSecond ;
dSecs += (DOUBLE) st.wMilliseconds * 0.001 ;
hb_retdt( st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, dSecs, 0 ) ;
}
However millisecs are set to zero after the dtpicker class of windows is used. That information is lost, unless we save it and restore later.
NageswaraRao