Author: Erwin Molendijk This demo shows how to perform a drag drop wich does not block the user interface during the copying of large files. Answer: 1 { Drag & Drop Thread 2 Copyright (c) 2000, 2001 by E.J.Molendijk 3 4 This class is a part of: 5 "Drag and Drop Component Suite" (http://www.melander.dk). 6 7 Explained: 8 When you create the thread, it will copy the filenames of the specified 9 DropFileSource. These filenames will be used by thread to perform a 10 drag&drop operation. The calling thread continues uninterupted. 11 12 Usage is very simple: 13 TDragDropThread.Create(DropFileSource1); 14 15 Drag&Drop Thread info Q139408: 16 http://support.microsoft.com/support/kb/articles/Q139/4/08.asp 17 } 18 19 unit DragDropThread; 20 21 interface 22 23 uses 24 Classes, DropSource, ActiveX, Windows; 25 26 type 27 TDragDropThread = class(TThread) 28 private 29 { Private declarations } 30 FFiles: string; 31 protected 32 procedure Execute; override; 33 public 34 constructor Create(DropFileSource: TDropFileSource); 35 end; 36 37 implementation 38 39 { TDragDropThread } 40 41 constructor TDragDropThread.Create(DropFileSource: TDropFileSource); 42 begin 43 // Thread will start immediately after creation 44 inherited Create(False); 45 46 // Copy filenames from supplied DropFileSource 47 FFiles := DropFileSource.Files.Text; 48 49 // This thread disappeard when it finishes 50 FreeOnTerminate := True; 51 end; 52 53 procedure TDragDropThread.Execute; 54 var 55 DropFileSource: TDropFileSource; 56 pt: TPoint; 57 hwndAttach: HWND; 58 dwAttachThreadID, dwCurrentThreadID: DWORD; 59 60 begin 61 // Get handle of window under mouse-cursor 62 GetCursorPos(pt); 63 hwndAttach := WindowFromPoint(pt); 64 Assert(hwndAttach <> 0, 'Unable to find window with drag-object'); 65 66 // Get thread ID's 67 dwAttachThreadID := GetWindowThreadProcessId(hwndAttach, nil); 68 dwCurrentThreadID := GetCurrentThreadId(); 69 70 // Attach input queues if necessary 71 if (dwAttachThreadID <> dwCurrentThreadID) then 72 AttachThreadInput(dwAttachThreadID, dwCurrentThreadID, True); 73 74 // Initialize Ole for this thread 75 OleInitialize(nil); 76 try 77 // create dropsource 78 DropFileSource := TDropFileSource.Create(nil); 79 try 80 DropFileSource.Files.Text := FFiles; 81 // start drag&drop 82 DropFileSource.Execute; 83 finally 84 // cleanup dropsource 85 DropFilesource.Free; 86 end; 87 finally 88 // cleanup Ole 89 OleUninitialize; 90 end; 91 // Restore input queues settings 92 if (dwAttachThreadID <> dwCurrentThreadID) then 93 AttachThreadInput(dwAttachThreadID, dwCurrentThreadID, False); 94 end; 95 96 end.