gpt4 book ai didi

delphi - 如何以编程方式在 Delphi TDateTimePicker 日历中标记日期?

转载 作者:行者123 更新时间:2023-12-03 14:56:30 25 4
gpt4 key购买 nike

当用户单击 DateTimePicker 并设置为下拉日历时,我希望以某种方式突出显示各种日期(通过我创建的代码选择)——彩色背景、粗体字体、彩色字体,这并不重要。我只想标记某些日期。 ...我该怎么做?

最佳答案

是的,你可以做到这一点。首先,您必须初始化控件:

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);

(使用 CommCtrl)。

然后您只需响应 MCN_GETDAYSTATE 通知即可。您可以创建自己的 TDateTimePicker 后代,也可以使用“拦截器类”。

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;

另一个例子:假设当前显示由三个月组成,并且您只想选择“当前显示的月份”(即中间月份)中的日期。假设您希望从选定的一天开始,每三天选择一次。

然后你想使用位域

Month  Bitfield
0 00000000000000000000000000000000
1 01001001001001001001001001001001
2 00000000000000000000000000000000

哪些是

Month  Bitfield
0 $00000000
1 $49249249
2 $00000000

以十六进制表示。所以你这样做

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

关于delphi - 如何以编程方式在 Delphi TDateTimePicker 日历中标记日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7210565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com