Afficher le numéro de la semaine dans un TDateTimePicker

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;

type
TForm1 = class(TForm)
DateTimePicker1: TDateTimePicker;
procedure DateTimePicker1DropDown(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
type
THackCommonCalendar = class(TCommonCalendar);

var
Form1: TForm1;

implementation

{$R *.DFM}
uses
CommCtrl;

procedure TForm1.DateTimePicker1DropDown(Sender: TObject);
var
Style: Integer;
ReqRect: TRect;
MaxTodayWidth: Integer;
begin
with THackCommonCalendar(DateTimePicker1) do
begin
// set style to include week numbers
Style := GetWindowLong(CalendarHandle, GWL_STYLE);
SetWindowLong(CalendarHandle, GWL_STYLE, Style or MCS_WEEKNUMBERS);
FillChar(ReqRect, SizeOf(TRect), 0);
// get required rect
Win32Check(MonthCal_GetMinReqRect(CalendarHandle, ReqRect));
// get max today string width
MaxTodayWidth := MonthCal_GetMaxTodayWidth(CalendarHandle);
// adjust rect width to fit today string
if MaxTodayWidth > ReqRect.Right then
ReqRect.Right := MaxTodayWidth;
// set new height & width
SetWindowPos(CalendarHandle, 0, 0, 0, ReqRect.Right, ReqRect.Bottom,
SWP_NOACTIVATE or SWP_NOMOVE
or SWP_NOZORDER);
end;
end;

end.
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour19/05/2002
VisualisationVu 1225 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Objet
Auteur de l'article
SwissDelphiCenter SwissDelphiCenter
connecté le 02/11/2011
329 articles dans la section
Contacter l'auteur