Author: Damir Kojevod FileDrop property to add visual controls [visual control] in
1. First inherit a new control from the visual control (Visual Control). 2. Increase the properties of the received file drag message. 3. Increase the message to be responed to the event when the message is triggered. 4. Test this newly created control.
Detailed description: 1. In Delphi, Component | Newcomponent selects a ancestor. Here, use TEDIT, name TFiledRoped, you can set other parameters, and select OK or Installation (this means auto-installation controls to control templates). 2. Add the properties of the received file drag. Add a message process in the Private section, declare as follows: Procedure WMDropfiles; Message WM_Dropfiles; this message process completes the WM_DropFiles message from Windows and can perform 'primary processing'. This process completes a range of usual processing, the recipient extracts message parameters from the message. At the same time, we also allow users to define her own actions (hand over the extracted information to the user), so we must define an event pointer to complete this feature. If the user defines the process, the message processing will call the user-defined process. Alternatively, the control must declare itself to the Windows to receive the control of the file drag. Whether to register if you want to call the Windows function DragAcceptFiles. The handle of the control is required, so the registration cannot be completed in the controls of the control, where the properties are added in the public part. Here you will register and log out of the file drag function with the AcceptFiles property.
3. Define the message trigger event (providing event pointer) so that the user defines the process event. First define a process event: the parameter is TStringList. As follows: TFileDropEvent = procedure (File: TStringList) of object; published in another part of the definition attributes are as follows property OnFileDrop: TFileDropEvent Read FFileDrop write FFileDrop; while the private portion of pointer variable definition process: FFileDrop: TFileDropEvent;
The source code below is all code for TDROPEDIT control. Note: The start control is not accepted by the file drag, if the user sets the AcceptFile property to be trusted to be a file to be dragged.
Unit fasdropedit;
Interface
Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Shellapi;
TYPE TFILEDROPEVENT = Procedure (Files: Tstringlist) OF Object
TFileDropEdit = class (TEdit) private {Private declarations} FFileDrop: TFileDropEvent; FAcceptFiles: Boolean; procedure WMDROPFILES (var Message: TWMDROPFILES); message WM_DROPFILES; procedure SetAcceptFiles (const Value: Boolean); protected {Protected declarations} public {Public declarations} Constructor Create (Aowner: Tcomponent); OVERRIDE;
property AcceptFiles: Boolean read FAcceptFiles write SetAcceptFiles; published {Published declarations} property OnFileDrop: TFileDropEvent read FFileDrop write FFileDrop; end; procedure Register;
IMPLEMentation
Procedure Register; Begin RegisterComponents ('Samples', [TFiledRopedit]);
Constructor tfiledropedit.create (Aowner: tComponent); begin inherited create (Aowner: tComponent); ffiledrop: = nil; FacceptFiles: = false;
procedure TFileDropEdit.WMDROPFILES (var Message: TWMDROPFILES); var NumFiles: integer; buffer: array [0..255] of char; i: integer; l: TStringList; begin if Assigned (FFiledrop) then begin l: = TStringList.Create ; NumFiles: = DragQueryFile (Message.Drop, $ FFFFFFFF, nil, 0); {thanks to Mike Heydon for D5 adjustment of parameters} for i: = 0 to NumFiles - 1 do {Accept the dropped file} begin DragQueryFile (Message. DROP, I, BUFFER, SIZEOF (Buffer); L.Append (strPas (buffer) end; ffiledrop (l); L.Free End End;
Procedure tfiledropedit.setAcceptfiles (const value: boolean); begin if facceptfiles <> value dam facceptfiles: = value; DragacceptFiles (Handle, Value);
End.