Let the form accept drag and drop, and get the information of the dragged file-reply to the question "wave question"

Source: Internet
Author: User
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

   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.