| 首页 | 电脑常识 | 程序设计 | 操作系统 | 语法 | 病毒安全 | 软件教程 | 硬件 | 数据库 | 多媒体 | 认证 | 下载 | 
首页>>程序设计 >>综合
判断MonthCalander中鼠标点中了日期还是翻页按钮!

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

电脑学习网,xuef.com,最全最新最权威的电脑知识网站.
免费计算机学习教程,电脑入门指南.

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的源碼, 應該可以! 不過, 點了翻页按鈕也會觸發日期選中的消息的, 相反則不會!

同時還看到一個:

delphibbs.com/delphibbs/dispq.asp?lid=799967" target=_blank>发布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自己的產品定位還不清, 還是只不過傳言有誤??

相 关 文 章
  • Delphi部分函数、命令、属性中文说明

  • 用Delphi实现整个网站图片的极速下载

  • Delphi控制Excel2000

  • 用DELPHI实现文件加密压缩

  • Delphi控制Excel的重要属性和方法

  • Windows的DDE原理

  • 在Delphi中获取和修改文件的时间

  • 校验码辅导讲座

  • 在Delphi 7中用dbexpress连接MySQL

  • Delphi:Daily build实践

  • 学府网电脑学习的乐园
    中国电脑教学网,电脑爱好者的乐园,做最好最全的计算机学习网站.