Problem Source: http://www.cnblogs.com/del/archive/2009/01/20/1353117.html#1435746
Principle Analysis:
Two shellapi functions are required: dragacceptfiles and dragqueryfile;
Use dragacceptfiles (window handle, true); to allow the window to accept drag and drop;
Then, wait for the wm_dropfiles message and use the dragqueryfile function to process the message parameters to obtain information.
Code File:
Unit unit1; interfaceuses windows, messages, extensions, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) memo1: tmemo; Procedure formcreate (Sender: tobject); protected procedure wmdropfiles (VAR message: twmdropfiles); message wm_dropfiles; end; var form1: tform1; implementation {$ R *. DFM} uses shellapi; Procedure tform1.formcreate (Sender: tobject); begin dragacceptfiles (handle, true); end; Procedure messages (VAR message: twmdropfiles); var P: array [0 .. 255] of char; I, Count: integer; begin {obtain the total number of dragged files first} count: = dragqueryfile (message. drop, $ ffffffff, nil, 0); {Get file names respectively} For I: = 0 to count-1 do begin dragqueryfile (message. drop, I, P, sizeof (p); memo1.lines. add (p); {now that you know the file name, you can also open it} end; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1 'clientheight = 154 clientwidth = 261 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false oncreate = formcreate pixelsperinch = 96 textheight = 13 object memo1: tmemo left = 0 Top = 0 width = 261 Height = 129 align = altop lines. strings = ('memo1') scrollbars = ssboth taborder = 0 endend