How to open a document that was dragged and dropped on the application icon?
Asked
Active
Viewed 924 times
1 Answers
16
The filename of the document dropped on your EXE is found in ParamStr(1)
.

Andreas Rejbrand
- 105,602
- 8
- 282
- 384
-
Thank you Andreas. I had old code from early Delphi that used DragAcceptFiles and AppMessageHandler with Msg.Message = WMDropFiles. (From the book "Delphi 3 - User Interface Design" listing 7-10 Method to get files dropped on icon). Maybe that was or was not needed then, but now I can now remove whatever that was doing. – lkessler Oct 26 '11 at 23:56
-
1@lkessler, that is for files dropped on one of the application's windows / controls, not files dragged onto the application icon (that is, a shortcut or the EXE file itself) which starts the program. You might be confusing two different techniques for passing a file to a program. – David Oct 27 '11 at 00:01
-
@DavidM - well, that book was clearly using this technique for the icon. Part of the test was "if IsIconic(Application.Handle)". That was one of the best books at the time for practical Delphi development. The author was Warren Kovach. I used a lot out it. I wonder if there are other dinosaurs in my code such as that. – lkessler Oct 27 '11 at 00:39
-
1@lkessler, `IsIconic` is the windows state where a **running** application is minimized. Since windows '95 those apps are shown on the taskbar, but before that they were shown as a icon. If you drag a file on a application's icon, the program is not running yet and does not have any state whatsoever. – Johan Oct 27 '11 at 07:44
-
Yeah, i remember how it was annoying to receive MessageBox('You cannot drag an item to toolbar. Your drag operation has been aborted') every time when LMB was relesed too early. – Premature Optimization Oct 27 '11 at 11:45
-
Thank you Andreas, I didn't know about ParamStr(i), works fine. I have one more question that is relatad with this. How to prevent opening more instances of app? For example, one document is already opened and modified and let's say another doc is dropped on icon. How to open it in already runnig app? – Srdjan Vukmirica Oct 27 '11 at 19:03
-
@Srdjan: That you need to ask a new question about, if there isn't already such a question (which I think there is). – Andreas Rejbrand Oct 27 '11 at 19:08
-
@Srdjan - A primitive approach involves each new instance searching for a previous instance and if it is found sending the document name to that instance for it to handle and then exit. Search for WM_COPYDATA. The elegant solution that actually prevented new instances was to use DDE, but I'm not sure if DDE is deprecated and what replaced it if it is. – Sertac Akyuz Oct 27 '11 at 20:41
-
(Mutexes are probably usable.) – Andreas Rejbrand Oct 27 '11 at 20:43
-
@Sertac: DDE is deprecated but still exists. The preferred way to handle this would be to implement the `IDropTarget` interface. Not only does it provide a replacement for `DragAcceptFiles()`, but it can also be registered with a file extension in such a way that the OS itself handles passing new file names to an existing app instance without having to start a new instance at all. – Remy Lebeau Oct 27 '11 at 21:24