Có, bạn có thể thực hiện việc này. Trước tiên, bạn phải khởi tạo điều khiển:
const
DTM_GETMCSTYLE = DTM_FIRST + 12;
DTM_SETMCSTYLE = DTM_FIRST + 11;
...
SendMessage(DateTimePicker1.Handle,
DTM_SETMCSTYLE,
0,
SendMessage(DateTimePicker1.Handle, DTM_GETMCSTYLE, 0, 0) or MCS_DAYSTATE);
(uses CommCtrl
).
Sau đó, bạn chỉ cần trả lời thông báo MCN_GETDAYSTATE
. Hoặc bạn có thể tạo ra con cháu của riêng bạn TDateTimePicker
hoặc bạn có thể sử dụng 'lớp ngăn chặn'.
type
TDateTimePicker = class(ComCtrls.TDateTimePicker)
protected
procedure WndProc(var Message: TMessage); override;
end;
...
procedure TDateTimePicker.WndProc(var Message: TMessage);
var
i: integer;
begin
inherited;
case Message.Msg of
WM_NOTIFY:
with PNMDayState(Message.LParam)^ do
if nmhdr.code = MCN_GETDAYSTATE then
begin
// The first visible day is SystemTimeToDateTime(stStart);
// cDayState is probably three, because most often three months are
// visible at the same time. Of course, the second of these is the
// 'currently displayed month'.
// Each month is represented by a DWORD (32-bit unsigned integer)
// bitfield, where 0 means not bold, and 1 means bold.
// For instance, the following code will select all days:
for i := 0 to cDayState - 1 do
PMonthDayState(Cardinal(prgDayState) + i*sizeof(TMonthDayState))^ := $FFFFFFFF;
end;
end;
end;
Một ví dụ khác: Giả sử rằng màn hình hiện hành bao gồm ba tháng, và rằng bạn chỉ muốn chọn ngày trong 'tháng đang hiển thị', có nghĩa là, trong tháng giữa. Giả sử bạn muốn mỗi ngày thứ ba được chọn, bắt đầu với một ngày đã chọn.
Sau đó, bạn muốn sử dụng bitfields
Month Bitfield
0 00000000000000000000000000000000
1 01001001001001001001001001001001
2 00000000000000000000000000000000
là
Month Bitfield
0 $00000000
1 $49249249
2 $00000000
trong hệ thập lục phân. Vì vậy, bạn làm
for i := 0 to cDayState - 1 do
if i = 1 then
PMonthDayState(cardinal(prgDayState) + i*sizeof(TMonthDayState))^ := $49249249
else
PMonthDayState(cardinal(prgDayState) + i*sizeof(TMonthDayState))^ := $00000000;
Screenshot http://privat.rejbrand.se/datetimepick.png
Lưu ý rằng thao tác này sẽ chỉ hoạt động trên Windows Vista trở lên, ví dụ: vì ['DTM_GETMCSTYLE'] (http://msdn.microsoft.com/en-us/library/bb761763 (VS.85) .aspx) được giới thiệu trong Vista. –
Tôi cho rằng hệ điều hành phân bổ và giải phóng bộ đệm 'prgDayState' ... Tài liệu chưa hoàn toàn rõ ràng về điểm này. –
Làm việc tốt Andreas. –