Scalabium Software

SMExport/SMImport suites
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);
const
  MCM_GETMAXTODAYWIDTH  = MCM_FIRST + 21;
var
  Style: LongInt;
  hDTP: THandle;

  r: TRect;
  intTodayWidth: Integer;
begin
  {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,
              SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOZORDER);
end;

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
 
Excel Web-stream
SMDBGrid
SMExport suite
Viewer for TNEF-files (winmail.dat)
DBLoad
DBExport tools
Metafile Convert
dBase Viewer
Paradox Password Recovery
ExcelFile Viewer
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2024, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMReport Autogenerated