Drag the file onto the form and get its full path "implementation under C + + Builder" goes

Source: Internet
Author: User

1. Declare the handler function and the message map in the form's header file. h, for example:

[CPP]View PlainCopy
    1. Class TForm1: Public tform
    2. {
    3. ...
    4. void __fastcall handledropfiles (tmessage &Owner;
    5. ...
    6. Begin_message_map
    7. Message_handler (Wm_dropfiles,tmessage,handledropfiles)
    8. End_message_map (Tform)
    9. };

2. In the form's implementation file. CPP, add the code

In the Formcreate event response:

[CPP]View PlainCopy
    1. void __fastcall tform1::formcreate (tobject *sender)
    2. {
    3. ...
    4. DragAcceptFiles (Handle,true);
    5. ...
    6. }

The most important processing function is handledropfiles:

[CPP]View PlainCopy
  1. void __fastcall tform1::handledropfiles (tmessage &msg)
  2. {
  3. Char Filename[_max_path];
  4. int i, Sum;
  5. //Get the number of dragged files, this function is determined by the second parameter
  6. Sum = Dragqueryfile (hdrop (msg).  WParam), 0xFFFFFFFF, NULL, 0);
  7. if (Sum > 0)
  8. {
  9. //Here as long as the first file
  10. Dragqueryfile (hdrop (msg.  WParam), 0, FileName, _max_path);
  11. //Display the file path to the text control on the form
  12. Txtpath->text = ansistring (FileName);
  13. }
  14. //Releases the memory space that the application opens up to pass the file name
  15. Dragfinish ( hdrop (msg.  WParam));
  16. }

Drag the file onto the form and get its full path "implementation under C + + Builder" goes

Related Article

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.