Scalabium Software

SMExport advertising
Knowledge for your independence'.
Home Delphi and C++Builder tips

#164: How can I display week numbers in TDateTimePicker?

Standard TDateTimePicker component allow to display the week numbers in dropdowned panel (where calendar displayed with navigator).

For some reason (maybe forgot) the Borland didn't publish this feature and today I want to demonstrate how you may activate this feature.

All what you need is to use the next code in OnDropDown event:

procedure TForm1.DateTimePicker1DropDown(Sender: TObject);
  Style: LongInt;
  hDTP: THandle;

  r: TRect;
  intTodayWidth: Integer;
  {to get a handle of calendar}
  hDTP := DateTime_GetMonthCal(DateTimePicker1.Handle);

  {change a style}
  Style := GetWindowLong(hDTP, GWL_STYLE);
  SetWindowLong(hDTP,  GWL_STYLE, Style or MCS_WEEKNUMBERS);

  {now we must change the width for calendar because week numbers shifted all strings}
  {1. to get the required rect }
  r := Rect(0, 0, 0, 0);
  SendMessage(hDTP, MCM_GETMINREQRECT, 0, Longint(@r));

  {2. to get the maximum width of the "today" string}
  intTodayWidth := SendMessage(hDTP, MCM_GETMAXTODAYWIDTH, 0, 0);

  {3. adjust rect width to fit the "today" string }
  if intTodayWidth > r.Right then
    r.Right := intTodayWidth;

  {4. to set new the height and width }
  SetWindowPos(hDTP, 0,
              r.Left, r.Top, r.Right-r.Left, r.Bottom-r.Top,

As you see, I include the MCS_WEEKNUMBERS style. It's easy and I hope will be useful for your end-users.

Published: April 21, 2004

See also
dBase Viewer
ABA Picture Convert
SMMsg suite
Clarion Viewer
Viewer for MS Outlook Messages
Excel Reader (dll)
ABA Database Convert
DBISAM Password Recovery
Viewer for TNEF-files (winmail.dat)
ABA Spreadsheet Convert

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2023, Scalabium Software. All rights reserved.

SMExport advertising