2
0

DropListBox.pas 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. unit DropListBox;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2019 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. This unit provides a listbox with drop files support.
  8. }
  9. interface
  10. uses
  11. StdCtrls,
  12. Messages;
  13. type
  14. TDropListBox = class;
  15. TDropFileEvent = procedure(Sender: TDropListBox; const FileName: String) of object;
  16. TDropListBox = class(TCustomListBox)
  17. private
  18. FOnDropFile: TDropFileEvent;
  19. protected
  20. procedure CreateWnd; override;
  21. procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
  22. published
  23. property Align;
  24. property Anchors;
  25. property BorderStyle;
  26. property Color;
  27. property Columns;
  28. property Ctl3D;
  29. property DragCursor;
  30. property DragMode;
  31. property Enabled;
  32. property ExtendedSelect;
  33. property Font;
  34. property ImeMode;
  35. property ImeName;
  36. property IntegralHeight;
  37. property ItemHeight;
  38. property Items;
  39. property MultiSelect;
  40. property ParentColor;
  41. property ParentCtl3D;
  42. property ParentFont;
  43. property ParentShowHint;
  44. property PopupMenu;
  45. property ShowHint;
  46. property Sorted;
  47. property Style;
  48. property TabOrder;
  49. property TabStop;
  50. property TabWidth;
  51. property Visible;
  52. property OnClick;
  53. property OnDblClick;
  54. property OnDragDrop;
  55. property OnDragOver;
  56. property OnDrawItem;
  57. property OnDropFile: TDropFileEvent read FOnDropFile write FOnDropFile;
  58. property OnEndDrag;
  59. property OnEnter;
  60. property OnExit;
  61. property OnKeyDown;
  62. property OnKeyPress;
  63. property OnKeyUp;
  64. property OnMeasureItem;
  65. property OnMouseDown;
  66. property OnMouseMove;
  67. property OnMouseUp;
  68. property OnStartDrag;
  69. end;
  70. procedure Register;
  71. implementation
  72. uses
  73. Classes,
  74. Windows, ShellAPI;
  75. procedure TDropListBox.CreateWnd;
  76. begin
  77. inherited;
  78. if csDesigning in ComponentState then
  79. Exit;
  80. DragAcceptFiles(Handle, True);
  81. end;
  82. procedure TDropListBox.WMDropFiles(var Msg: TWMDropFiles);
  83. var
  84. FileName: array[0..MAX_PATH] of Char;
  85. I, FileCount: Integer;
  86. begin
  87. try
  88. if Assigned(FOnDropFile) then begin
  89. FileCount := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0);
  90. for I := 0 to FileCount-1 do
  91. if DragQueryFile(Msg.Drop, I, FileName, SizeOf(FileName)) > 0 then
  92. FOnDropFile(Self, FileName);
  93. end;
  94. Msg.Result := 0;
  95. finally
  96. DragFinish(Msg.Drop);
  97. end;
  98. end;
  99. procedure Register;
  100. begin
  101. RegisterComponents('JR', [TDropListBox]);
  102. end;
  103. end.