Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | unit DropHandler; |
2 | |||
3 | // ----------------------------------------------------------------------------- |
||
4 | // Project: Drag and Drop Component Suite. |
||
5 | // Module: DropHandler |
||
6 | // Description: Implements Drop Handler Shell Extensions. |
||
7 | // Version: 4.0 |
||
8 | // Date: 18-MAY-2001 |
||
9 | // Target: Win32, Delphi 5-6 |
||
10 | // Authors: Anders Melander, anders@melander.dk, http://www.melander.dk |
||
11 | // Copyright © 1997-2001 Angus Johnson & Anders Melander |
||
12 | // ----------------------------------------------------------------------------- |
||
13 | interface |
||
14 | |||
15 | uses |
||
16 | DragDrop, |
||
17 | DropTarget, |
||
18 | DragDropFile, |
||
19 | DragDropComObj, |
||
20 | ActiveX, |
||
21 | Windows, |
||
22 | Classes; |
||
23 | |||
24 | type |
||
25 | //////////////////////////////////////////////////////////////////////////////// |
||
26 | // |
||
27 | // TDropHandler |
||
28 | // |
||
29 | //////////////////////////////////////////////////////////////////////////////// |
||
30 | // Based on Angus Johnson's DropHandler demo. |
||
31 | //////////////////////////////////////////////////////////////////////////////// |
||
32 | // A typical drop handler session goes like this: |
||
33 | // 1. User drags one or more source files over a target file which has a |
||
34 | // registered drop handler. |
||
35 | // 2. The shell loads the drop handler module. |
||
36 | // 3. The shell instantiates the registered drop handler object as an in-process |
||
37 | // COM server. |
||
38 | // 4. The IPersistFile.Load method is called with the name of the target file. |
||
39 | // The target file name is stored in the TDropHandler.TargetFile property. |
||
40 | // 5. The IDropTarget.Enter method is called. This causes a TDropHandler.OnEnter |
||
41 | // event to be fired. |
||
42 | // 6. One of two things can happen next: |
||
43 | // a) The user drops the source files on the target file. |
||
44 | // The IDropTarget.Drop method is called. This causes a |
||
45 | // TDropHandler.OnDrop event to be fired. |
||
46 | // The names of the dropped files are stored in the TDropHandler.Files |
||
47 | // string list property. |
||
48 | // b) The user drags the source files away from the target file. |
||
49 | // The IDropTarget.Leave method is called. This causes a |
||
50 | // TDropHandler.OnLeave event to be fired. |
||
51 | // 7. The shell unloads the drop handler module (usually after a few seconds). |
||
52 | //////////////////////////////////////////////////////////////////////////////// |
||
53 | TDropHandler = class(TDropFileTarget, IPersistFile) |
||
54 | private |
||
55 | FTargetFile: string; |
||
56 | protected |
||
57 | // IPersistFile implementation |
||
58 | function GetClassID(out classID: TCLSID): HResult; stdcall; |
||
59 | function IsDirty: HResult; stdcall; |
||
60 | function Load(pszFileName: POleStr; dwMode: Longint): HResult; stdcall; |
||
61 | function Save(pszFileName: POleStr; fRemember: BOOL): HResult; stdcall; |
||
62 | function SaveCompleted(pszFileName: POleStr): HResult; stdcall; |
||
63 | function GetCurFile(out pszFileName: POleStr): HResult; stdcall; |
||
64 | public |
||
65 | property TargetFile: string read FTargetFile; |
||
66 | end; |
||
67 | |||
68 | //////////////////////////////////////////////////////////////////////////////// |
||
69 | // |
||
70 | // TDropHandlerFactory |
||
71 | // |
||
72 | //////////////////////////////////////////////////////////////////////////////// |
||
73 | // COM Class factory for TDropHandler. |
||
74 | //////////////////////////////////////////////////////////////////////////////// |
||
75 | TDropHandlerFactory = class(TShellExtFactory) |
||
76 | protected |
||
77 | public |
||
78 | procedure UpdateRegistry(Register: Boolean); override; |
||
79 | end; |
||
80 | |||
81 | //////////////////////////////////////////////////////////////////////////////// |
||
82 | // |
||
83 | // Component registration |
||
84 | // |
||
85 | //////////////////////////////////////////////////////////////////////////////// |
||
86 | procedure Register; |
||
87 | |||
88 | |||
89 | //////////////////////////////////////////////////////////////////////////////// |
||
90 | // |
||
91 | // Misc. |
||
92 | // |
||
93 | //////////////////////////////////////////////////////////////////////////////// |
||
94 | |||
95 | |||
96 | //////////////////////////////////////////////////////////////////////////////// |
||
97 | //////////////////////////////////////////////////////////////////////////////// |
||
98 | // |
||
99 | // IMPLEMENTATION |
||
100 | // |
||
101 | //////////////////////////////////////////////////////////////////////////////// |
||
102 | //////////////////////////////////////////////////////////////////////////////// |
||
103 | implementation |
||
104 | |||
105 | uses |
||
106 | ComObj; |
||
107 | |||
108 | //////////////////////////////////////////////////////////////////////////////// |
||
109 | // |
||
110 | // Component registration |
||
111 | // |
||
112 | //////////////////////////////////////////////////////////////////////////////// |
||
113 | |||
114 | procedure Register; |
||
115 | begin |
||
116 | RegisterComponents(DragDropComponentPalettePage, [TDropHandler]); |
||
117 | end; |
||
118 | |||
119 | |||
120 | //////////////////////////////////////////////////////////////////////////////// |
||
121 | // |
||
122 | // Utilities |
||
123 | // |
||
124 | //////////////////////////////////////////////////////////////////////////////// |
||
125 | |||
126 | |||
127 | //////////////////////////////////////////////////////////////////////////////// |
||
128 | // |
||
129 | // TDropHandler |
||
130 | // |
||
131 | //////////////////////////////////////////////////////////////////////////////// |
||
132 | function TDropHandler.GetClassID(out classID: TCLSID): HResult; |
||
133 | begin |
||
134 | result := E_NOTIMPL; |
||
135 | end; |
||
136 | |||
137 | function TDropHandler.GetCurFile(out pszFileName: POleStr): HResult; |
||
138 | begin |
||
139 | result := E_NOTIMPL; |
||
140 | end; |
||
141 | |||
142 | function TDropHandler.IsDirty: HResult; |
||
143 | begin |
||
144 | result := S_FALSE; |
||
145 | end; |
||
146 | |||
147 | function TDropHandler.Load(pszFileName: POleStr; dwMode: Integer): HResult; |
||
148 | begin |
||
149 | FTargetFile := WideCharToString(pszFileName); |
||
150 | result := S_OK; |
||
151 | end; |
||
152 | |||
153 | function TDropHandler.Save(pszFileName: POleStr; fRemember: BOOL): HResult; |
||
154 | begin |
||
155 | result := E_NOTIMPL; |
||
156 | end; |
||
157 | |||
158 | function TDropHandler.SaveCompleted(pszFileName: POleStr): HResult; |
||
159 | begin |
||
160 | result := E_NOTIMPL; |
||
161 | end; |
||
162 | |||
163 | |||
164 | //////////////////////////////////////////////////////////////////////////////// |
||
165 | // |
||
166 | // TDropHandlerFactory |
||
167 | // |
||
168 | //////////////////////////////////////////////////////////////////////////////// |
||
169 | procedure TDropHandlerFactory.UpdateRegistry(Register: Boolean); |
||
170 | begin |
||
171 | if Register then |
||
172 | begin |
||
173 | inherited UpdateRegistry(Register); |
||
174 | CreateRegKey(FileClass+'\shellex\DropHandler', '', GUIDToString(ClassID)); |
||
175 | end else |
||
176 | begin |
||
177 | RegDeleteKey(HKEY_CLASSES_ROOT, PChar(FileClass)); |
||
178 | inherited UpdateRegistry(Register); |
||
179 | end; |
||
180 | end; |
||
181 | |||
182 | end. |