判断MonthCalander中鼠标点中了日期还是翻页按钮…

2008-04-09 04:31:47来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

uses CommCtrl;

var OldWindowProc: TWndMethod;

procedure TForm1.MyWindowProc(var Msg: TMessage);
begin
if Msg.Msg = CN_NOTIFY then
begin
case TWMNotify(msg).NMHdr.code of
MCN_GETDAYSTATE: Memo1.Lines.Add(''''MCN_GETDAYSTATE'''');//點了翻页
MCN_SELECT, MCN_SELCHANGE: Memo1.Lines.Add(''''MCN_SELECT, MCN_SELCHANGE'''');//選中日期
end;
end;

OldWindowProc(Msg);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
OldWindowProc := MonthCalendar1.WindowProc;
MonthCalendar1.WindowProc := MyWindowProc;
end;

549的問題, 吃完飯看了下VCL的源碼, 應該可以! 不過, 點了翻页按鈕也會觸發日期選中的消息的, 相反則不會!

同時還看到一個:

发布TDateTimePicker同时修改日期和时间的解决方案

type
TCDateTimePicker = class(TDateTimePicker)
private
procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
end;

function IsBlankSysTime(const ST: TSystemTime): Boolean;
type
TFast = array[0..3] of DWORD;
begin
Result := (TFast(ST)[0] or TFast(ST)[1] or TFast(ST)[2] or TFast(ST)[3]) = 0;
end;

procedure TCDateTimePicker.CNNotify(var Message: TWMNotify);
begin
with Message, NMHdr^ do
begin
Result := 0;
if (code = DTN_DATETIMECHANGE) and
(PNMDateTimeChange(NMHdr)^.dwFlags = GDT_VALID) and (not DroppedDown) and
(not (ShowCheckBox and IsBlankSysTime(PNMDateTimeChange(NMHdr)^.st))) then
DateTime := SystemTimeToDateTime(PNMDateTimeChange(NMHdr)^.st);
end;
inherited;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
with TCDateTimePicker.Create(self) do
begin
Left := 100;
Top := 100;
Parent := Self;
Format := ''''yyyy-MM-dd hh:mm:ss'''';
Visible := true;
end;
end;

可以按上下鍵直接修改, 不錯! 不過要改到可以下拉面板也有時間選擇, 可能難一點!

btw: kylix 又說有新的clx要發布, 有點亂, 不是說停止開發了嗎?? 還有BCB, BCBX的新聞也有點亂, 是borland自己的產品定位還不清, 還是只不過傳言有誤??

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Delphi 程序员代码编写标准指南

下一篇:性能vs结构