I'm a Delphi-programmer and I have a question. I create a form with TStyleManager and I use skins on my application. But I want to use Drag-n-Drop files in my app too. How I can realize this? I have tried many methods, but ... I could not get to do it. Hope on your help
Asked
Active
Viewed 975 times
1
-
For a general drag-n-Drop solution see [Drag/Drop inside an Application AND to another Application](http://stackoverflow.com/q/198488/576719). Please elaborate what your specific problem with styles and drag-n-Drop is. – LU RD Apr 26 '12 at 12:07
-
possible duplicate of [How can I allow a form to accept file dropping without handling Windows messages?](http://stackoverflow.com/questions/4354071/how-can-i-allow-a-form-to-accept-file-dropping-without-handling-windows-messages) – David Heffernan Apr 26 '12 at 12:15
-
How did you try it? What are the symptoms? Did you set the main form's DockSite property to true? What happens in the OnDockOver and OnDockDrop events? – Attila Fulop Apr 26 '12 at 12:03
2 Answers
5
When you change the vcl style the handle of the form is recreated, so if you call the DragAcceptFiles
function before to set the style the handle used will not be the same when the style is applied. To fix that execute the DragAcceptFiles function in this way.
TStyleManager.SetStyle(StyleName);
Application.ProcessMessages;//process the message queue;
DragAcceptFiles( Handle, True );

RRUZ
- 134,889
- 20
- 356
- 483
0
use shellApi unit's method DragAcceptFiles
to achieve what you need . It needs 2 parameter , first is the handle of the Application and second a boolean to specify whether to switch on - off drag feature . to turn on use something like DragAcceptFiles(Self.Handle,True);
To respond to drag and drop of files , use
Procedure TForm1.RespondToMessage(var Msg : TMsg;var handled : Boolean) ;
const
FileIndex : Cardinal = Cardinal(-1); { return a count of dropped files }
BuffLen = 255;
Var
FileNum : Word;
FName : String;
BuffArr : Array[0..MAX_PATH-1] of Char;
Begin
If Msg.message = WM_DROPFILES Then
Begin
For FileNum := 0 To DragQueryFile(Msg.wParam,FileIndex,Nil,BuffLen)-1 Do // first time , FileIndex is 0xFFFFFFFF , so
// the return is the number of files to be dragged
// Here the return in fileIndex is the no of files;
Begin
DragQueryFile(Msg.wParam, FileNum , BuffArr , BuffLen);
FName := StrPas(BuffArr);
//AddButton(FName); -- do whatever operation you want with the fileName
End;
Try
DragFinish(Msg.wParam); // Free the memory given to drag operation
Except
End;
Handled := True;
//AddScrollIfRequired;
End;
End;
Now include Application.OnMessage := RespondToMessage
to trap the drag & drop operations.
Hope that helps

CyprUS
- 4,159
- 9
- 48
- 93
-
Oh, I know it and I do this in a similar way but with skins this way doesn't work! This is a my question) How I can use skins & dragndrop together – Alik Send Apr 26 '12 at 12:48
-
@Александр Цыбух : It does actually , which skin are you using anyway ? I tried it using Alpha lite skins , and it works without any hitch. Post a sample of your code to let us know what is wrong. – CyprUS Apr 26 '12 at 13:03
-
Oh, sorry. I used standart skins (My SDK - Delphi XE2; Vlc.Themes - TStyleManger). – Alik Send Apr 26 '12 at 13:18
-
please post a sample of your code , as i cannot see any relation between skins and drag & drop . btw , i tested it on delphi 7 – CyprUS Apr 26 '12 at 13:20
-
this is not necessarily, because when I turn off the skins are all working well – Alik Send Apr 26 '12 at 13:24
-
I think the point is that the style manager replaces the form handle to his and when I write DragAcceptFiles(handle,true) I define a form as the message recipient. and when the skins are active, ttstylemanager is the recipient of messages: windows messages come to him rather than the form. I think it's because of this – Alik Send Apr 26 '12 at 13:27
-
that is a valid explanation. try handling the message with SkinManager as the receipient . use SkinManager1.OnMessage := respondToMessage. See if that works. – CyprUS Apr 26 '12 at 13:29
-
the fact that tstylemanager no such properties. it would be so easy ... I've tried to do things (with the online help), but - to no avail. therefore written here, as there are people who experienced it and can really help, I hope so – Alik Send Apr 26 '12 at 13:32
-
if you really want to use skins, you may use AlphaLite SkinManager perphaps ( i use it) . – CyprUS Apr 26 '12 at 13:35
-
i know it, I use this in another program...it really cool skin copmponents, but I want use only sstandats comps. If I can not find a solution here, have to use standard – Alik Send Apr 26 '12 at 13:41