Set range of a date picker

Set range of a date picker

Postby AntoninoP » Tue Aug 02, 2022 10:36 am

Hello,
because of our needs I created this function
Code: Select all  Expand view

#include <hbapi.h>
#include <hbdate.h>
#include <windows.h>
#include <commctrl.h>

HB_FUNC( DATETIME_SETRANGE ) // ( hWnd, dMin, dMax)
{
    SYSTEMTIME range[2];
    long dMin = hb_pardl(2);
    long dMax = hb_pardl(3);
    int y,m,d;
    HWND hWnd = ( HWND ) hb_parfw( 1 );

    hb_dateDecode(dMin, &y, &m, &d);
    range[0].wYear          = (WORD)y;
    range[0].wMonth         = (WORD)m;
    range[0].wDay           = (WORD)d;
    range[0].wDayOfWeek     = 0;
    range[0].wHour          = 0;
    range[0].wMinute        = 0;
    range[0].wSecond        = 0;
    range[0].wMilliseconds  = 0;
    hb_dateDecode(dMax, &y, &m, &d);
    range[1].wYear          = (WORD)y;
    range[1].wMonth         = (WORD)m;
    range[1].wDay           = (WORD)d;
    range[1].wDayOfWeek     = 0;
    range[1].wHour          = 0;
    range[1].wMinute        = 0;
    range[1].wSecond        = 0;
    range[1].wMilliseconds  = 0;

    DateTime_SetRange(hWnd,
        (dMin!=0? GDTR_MIN : 0) |
        (dMax!=0? GDTR_MAX : 0), range);
   hb_ret();
}
 

I am using a very old version of fivewin (18-01), so I don't know if it is already present in newer versions, but It looks useful so I shared it.

samples of use:
Code: Select all  Expand view

DateTime_SetRange(oDTPicker:hWnd, Date()-10, Date()+10) // enable only from 10 days before to 10 days after today
DateTime_SetRange(oDTPicker:hWnd, Date(), nil) // enable only future dates
DateTime_SetRange(oDTPicker:hWnd, nil, Date()) // enable only past dates
 

It works on Harbour and Visual Studio
can someone try it on xHarbour and bcc?
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Set range of a date picker

Postby Jimmy » Tue Aug 02, 2022 6:47 pm

hi,

as i can say FiveWin have Function in
c:\fwh\source\classes\tdtpicke.prg
Code: Select all  Expand view
METHOD SetRange( dFrom, dUpto ) CLASS TDatePick
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 56 guests

cron