PlanetSquires Forums

Support Forums => José Roca Software => Topic started by: Richard Kelly on April 23, 2026, 11:18:55 AM

Title: Date Picker Question
Post by: Richard Kelly on April 23, 2026, 11:18:55 AM
After adding a date picker control, I wanted to use a custom format using:

   hCtl = pWindow.AddControl("DATETIMEPICKER", hwndMain, IDC_DATEPICKER, "Date", 60, 25 ,126, 27)
   DateTime_SetFormat(hCtl,"yyyy.MM.dd")

I'm thinking I need to set a format property to custom first and don't see a way to do this with AfxNova.
Title: Re: Date Picker Question
Post by: José Roca on April 23, 2026, 12:19:29 PM
To use the Window's DateTime_SetFormat macro:

DIM fmt AS WSTRING * 260 = "yyyy.MM.dd"
DateTime_SetFormat(hCtl, @fmt)

or

DateTime_SetFormat(hCtl, @WSTR("yyyy.MM.dd"))

You can use instead my CDtPicker static class (available adding #INCLUDE ONCE "AfxNova/CDtPicker.inc")

CDtPicker.SetFormat(hCtl, "yyyy.MM.dd")


Please note that in FreeBasic, @ is equivalent to VARPTR, unlike with PowerBasic, that was used to deference a pointer.
Title: Re: Date Picker Question
Post by: Richard Kelly on April 23, 2026, 08:13:03 PM
Thank you Jose for your speedy assistance. What worked was:

CDtPicker.SetFormat(hCtl, @"yyyy.MM.dd")
Title: Re: Date Picker Question
Post by: José Roca on April 23, 2026, 08:57:00 PM
No, CDtPicker.SetFormat(hCtl, @"yyyy.MM.dd") is incorrect. If you use the CDtPicker static class, the correct way is CDtPicker.SetFormat(hCtl, "yyyy.MM.dd")
Title: Re: Date Picker Question
Post by: Richard Kelly on April 24, 2026, 02:55:11 PM
#INCLUDE ONCE "AfxNova/CDtPicker.inc"
CDtPicker.SetFormat(hCtl, "yyyy.MM.dd")

When I use the string "yyyy.MM.dd" directly, the control only shows the two digit year. I had to add:

#DEFINE UNICODE

and now it works as you provided.
Title: Re: Date Picker Question
Post by: José Roca on April 24, 2026, 04:54:43 PM
You're right. I was using DTM_SETFORMAT. Changed to use DTM_SETFORMATW. Now it doesn't need #define UNICODE.

PRIVATE SUB CDtPicker.SetFormat (BYVAL hDtp AS HWND, BYVAL pwsz AS WSTRING PTR)
   SendMessageW(hDtp, DTM_SETFORMATW, 0, cast(LPARAM, pwsz))
END SUB