TDateTimePicker的BoldDays?

时间:2010-11-19 08:29:09

标签: delphi delphi-7 datetimepicker typography monthcalendar

我正在使用Delphi7,我想在TDateTimePicker控件的某些日子大胆。

我读过,原来,它是TMonthCalendar的后代,因此它应该是可能的。

我也找到了一些示例代码,但它在C#中: http://social.msdn.microsoft.com/Forums/en/winforms/thread/03527023-694d-41ab-bffb-18c59fca1fda

请注意,我不想使用任何第三方DateTimePicker控件,我希望使用标准控件。

2 个答案:

答案 0 :(得分:4)

你是对是错: - )

请参阅: http://www.experts-exchange.com/Programming/System/Windows__Programming/MFC/Q_23927552.html

你是对的,你不能在XP下设置BoldDays。 但你错了,因为在Vista / Win7下你可以!

以下是修改后的代码:

procedure TForm1.DateTimePicker1DropDown(Sender: TObject);
const
  DTM_GETMCSTYLE = (DTM_FIRST + 12);
  DTM_SETMCSTYLE = (DTM_FIRST + 11);
  MCS_NOTRAILINGDATES = $0040;
  MCS_SHORTDAYSOFWEEK = $0080;
  MCS_NOSELCHANGEONNAV = $0100;
var
  monthCalHandle: THandle;
  boldDates: array[0..2] of integer;
  style, prevstyle: LResult;
begin
  style := SendMessage(DateTimePicker1.Handle, DTM_GETMCSTYLE, 0, 0);
  style := style or MCS_DAYSTATE; //or MCS_NOSELCHANGEONNAV or MCS_WEEKNUMBERS;
  prevstyle := SendMessage(DateTimePicker1.Handle, DTM_SETMCSTYLE, 0, style);

  monthCalHandle := SendMessage(dateTimePicker1.Handle, DTM_GETMONTHCAL, 0, 0);

  boldDates[0]:=$5a5a5a;
  boldDates[1]:=$5a5a5a;
  boldDates[2]:=$5a5a5a;
  SendMessage(monthCalHandle, MCM_SETDAYSTATE, 3, integer(@boldDates));
end;

注意:请务必在文件中添加vista清单,否则无效!

常量来自更新的commctrl.h文件,可在此处找到: http://www.koders.com/cpp/fid6A6537D52B537D0920D7A760D2073F7B65ADE310.aspx?s=WM_CAP_DRIVER_CONNECT

感谢您的帮助,您引导我找到解决方案! : - )

答案 1 :(得分:2)

你无法做你想做的事,因为在DateTimePicker中按下dropDown按钮响应时显示的MonthCalendar是没有设置MCS_DAYSTATE样式的MonthCalendar。这是微软的决定。它不是VCL限制,所以根据我的知识,你可以做任何改变它。唯一不会使用它并实例化你自己的真实MonthCalendar以响应用户按下拉下拉按钮;或者使用一些已经可用的自定义组件。

为了证明这一点,这里是您发布的相同C#代码的Pascal版本。它不起作用,据我所知它永远不会。如果要测试它,请将其挂钩到DateTimePicker的DropDown事件中。

procedure TForm1.DateTimePicker1DropDown(Sender: TObject);
 var
   monthCalHandle: THandle;
   boldDates: array[0..2] of integer;

 begin
  { obtain the MonthCalendar handle using the DTM_GETMONTHCAL message
    note that the handle returned changes for every time the
    drop down calendar is displayed. }
  monthCalHandle := SendMessage(dateTimePicker1.Handle, DTM_GETMONTHCAL, 0, 0);

  { Send the MCM_SETDAYSTATE message. This message takes an array of
    3 MONTHDAYSTATEs. Every MONTHDAYSTATE is a bit set that represents a month.
    Each bit (0 through 30) represents the state of a day. Whan a bit is on,
    its corresponding day is emphasized in the MonthCalendar }
  boldDates[0]:=$5a5a5a;
  boldDates[1]:=$5a5a5a;
  boldDates[2]:=$5a5a5a;
  SendMessage(monthCalHandle, MCM_SETDAYSTATE, 3, integer(@boldDates));
 end;