delphi 精要
来源:互联网 发布:mac电源以连接,未充电 编辑:程序博客网 时间:2024/05/16 17:39
typeTDropFilesEvent = procedure(Receiver: TWinControl;const FileNames: TStrings;const FilesCount: Integer;const DropPoint: TPoint) of object;TlxpDraggingFilesMonitor = class(TComponent){由于组件在运行时不需要可见,所以从TComponent派生}privateFAcceptFilesControl: TWinControl; {指定接收者}OldWindowProc: TWndMethod; {保存FAcceptFilesControl原来的窗口过程}FFilesName: TStrings; {拖放的文件名列表}FOnDropFiles: TDropFilesEvent; {拖放事件}procedure SetAcceptFilesControl(const Value: TWinControl);protected{FAcceptFilesControl新的窗口过程}procedure NewWindowProc(var Message: TMessage);procedure Notification(AComponent: TComponent; Operation: TOperation); override;publicconstructor Create(AOwner: TComponent); override;destructor Destroy; override;publishedproperty AcceptFilesControl: TWinControl read FAcceptFilesControlwrite SetAcceptFilesControl;property OnDropFiles: TDropFilesEvent read FOnDropFiles writeFOnDropFiles;end;constructor TlxpDraggingFilesMonitor.Create(AOwner: TComponent);begininherited;FFilesName := TStringList.Create;end;destructor TlxpDraggingFilesMonitor.Destroy;beginif Assigned(FAcceptFilesControl) thenDragAcceptFiles(FAcceptFilesControl.Handle, False);{注销文件拖放监视器}FreeAndNil(FFilesName);inherited;end;procedure TlxpDraggingFilesMonitor.SetAcceptFilesControl(const Value: TWinControl);beginif FAcceptFilesControl <> Value thenbeginif Assigned(Value) and (not (csDesigning in ComponentState)) then{设计时不执行下列代码}beginDragAcceptFiles(Value.Handle, True); {注册文件拖放监视器}OldWindowProc := Value.WindowProc; {首先保存过程WindowProc 的指针}Value.WindowProc := NewWindowProc; {给WindowProc 赋予新过程的地址}end;FAcceptFilesControl := Value;FAcceptFilesControl.FreeNotification(Self);{注册AcceptFilesControl,确保它被销毁时通知这个组件}end;end;{在这个过程里处理文件拖放消息}procedure TlxpDraggingFilesMonitor.NewWindowProc(var Message: TMessage);varCount, Index, hDrop: Integer;PFileName: PChar;P: TPoint;beginif Message.Msg = WM_DROPFILES then {如果是文件拖放消息}beginhDrop := Message.WParam;FFilesName.Clear;GetMem(PFileName, MAX_PATH); {给缓冲区PFileName 分配空间}Count := DragQueryFile(hDrop, MAXDWORD, PFileName, MAX_PATH-1);{取得文件总个数}for Index := 0 to Count-1 dobeginDragQueryFile(hDrop, Index, PFileName, MAXBYTE);{得到每个文件的名字}FFilesName.Add(PFileName);end;DragQueryPoint(hDrop, P); {取得鼠标松开时的位置,保存到P}if Assigned(FOnDropFiles) then {如果用户书写了事件代码,则触发事件}FOnDropFiles(FAcceptFilesControl, FFilesName, Count, P);FreeMem(PFileName); {释放缓冲区空间}DragFinish(hDrop); {完成本次拖放}end elseOldWindowProc(Message); {调用原来的WindowProc 过程处理别的消息}end;procedure TlxpDraggingFilesMonitor.Notification(AComponent:TComponent; Operation: TOperation);begininherited;if (AComponent = FAcceptFilesControl) and (Operation = opRemove)thenFAcceptFilesControl := nil;end;
0 0
- Delphi精要
- 《Delphi精要》
- 《Delphi精要》
- 《Delphi精要》
- 《Delphi精要》
- 《Delphi精要》
- 《Delphi精要》
- Delphi精要
- delphi 精要
- 015_《Delphi精要》
- delphi 精要3
- delphi精要学习3
- delphi精要之(二)
- delphi 精要-读书笔记(过程类型,方法类型)
- delphi 精要-读书笔记(内存分配释放)
- delphi 精要-读书笔记(内存分配释放)
- DELPHI OBJECT PASCAL 语法精要样例
- delphi 精要-读书笔记(内存分配释放)
- iOS开发有哪些难点
- keybd_event使用方法
- php Laravel框架学习(一) 之 建立数据库并填充测试数据
- LO抽取更新方式和V1/V2/V3
- 行号是按指定的逻辑顺序为查询结果集中的行分配的连续整数
- delphi 精要
- 【Hive】 cli 的基本用法
- mysql 修改字段的属性
- Cocos2d-x教程(9)-简单的数据存储,CCUserDefault
- JDBC经典版
- orapwd的学习
- 分布式搜索Elasticsearch——创建客户端(六)
- pycharm是一个很棒的python语言ide
- socket的内核和上层通信机制(netlink) -- linux内核