How to Use wm_dropfiles messages? On the same interface, how can multiple components support Windows external file drag and drop at the same time. Dragacceptfiles.

Source: Internet
Author: User
How to Use wm_dropfiles messages? On the same interface, how can multiple components support Windows external file drag and drop at the same time. Dragacceptfiles. Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiAPI/html/delphi_20061114152826236.html
Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, extctrls, shellapi;
Type
Tform1 = Class (tform)
Panel1: tpanel;
Procedure formcreate (Sender: tobject );
Private
Oldwndproc: twndmethod;
Procedure dragfileproc (var msg: tmessage); message wm_dropfiles;
Public
{Public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
{Tform1}

Procedure tform1.dragfileproc (var msg: tmessage );
VaR
Filename: array [0 .. MAX_PATH-1] of char;
Sfilename: string;
Count: integer;
Begin
If msg. MSG = wm_dropfiles then
Begin
Count: = dragqueryfile (msg. wparam, $ ffffffff, @ filename [0], max_path); // get the number of Drag and Drop files
If count> 0 then
Begin
Fillchar (filename, sizeof (filename), #0 );
Dragqueryfile (msg. wparam, 0, @ filename [0], max_path); // query the file name
Sfilename: = string (filename );

End;
Dragfinish (msg. wparam); // release the resources used
End else
Oldwndproc (MSG );
End;

Procedure tform1.formcreate (Sender: tobject );
Begin
Dragacceptfiles (panel1.handle, enabled );
Oldwndproc: = panel1.windowproc; // Save the original windowproc
Panel1.windowproc: = dragfileproc; // set the new windowproce
End;

End.

I would like to ask, if I have multiple wincontrol components on one interface at the same time and need to support Windows external file drag and drop, what should I do?

Through (var msg: tmessage); message wm_dropfiles; can you determine which component is returned?

Can I add a method for tpanel to receive wm_dropfiles.
The premise is that you do not need to re-compile the tpanel control. Writing an inheritance class cannot be placed on the interface. Unless compiled into a visual control.

Uses
Stdctrls, shellapi;


Type

Tdragmemo = Class (tmemo)
Procedure dragfileproc (var msg: tmessage); message wm_dropfiles;
End;

Tform1 = Class (tform)
Procedure formcreate (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;

Implementation

{$ R *. DFM}

Procedure tform1.formcreate (Sender: tobject );
VaR
Memo: tdragmemo;
Begin
Memo: = tdragmemo. Create (NiL );
Memo. Parent: = self;
End;

Procedure tdragmemo. dragfileproc (var msg: tmessage );
Begin
// Your code
End;

End.

The above is just to define a class. You can make it a control, inherit the Windows Control directly, and then modify dragfileproc.

Woshihaoge (fragmented) I know.
But in this case, if you want to directly put it on the interface, you need to make the control.

I want edit, panel, listview... and other controls to support the drag and drop of EXPLORER. It feels a bit like this ....

Are there other methods?

There is no way. It can only be subclass like this, or it can be made into a control. I have studied similar issues before. It seems that this method is described in the book.

Can someone answer this question?

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.