Solved

drag and drop on a desktop icon

Posted on 1998-04-30
7
343 Views
Last Modified: 2010-04-06
Using Delphi 1 and 3 I have found that I cannot drop a file onto a desktop icon in Win95 or on a minimized icon in Windows 3.1. and have it load as expected. The program will pop up, but without loading the file. However, once the program is running dropping works fine. What's the trick?
0
Comment
Question by:swright243
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1339634
In your app, are you using DDE to detect each file the user drops or clicks, or are you checking the command-line params (ParamCount and ParamStr)?

JB
0
 

Author Comment

by:swright243
ID: 1339635
I don't exactly understand your question, it is not possible to drop a ParamStr on a desktop icon. Here's how I have enabled drag and drop which works fine if the app is not iconized:

procedure TForm1.FormCreate(Sender: TObject);
begin
   DragAcceptFiles(Handle, True);
end;

procedure TForm1.WMDropFiles(var Msg: TMessage);
var
   buff : array[0..255] of char;
   FName: string;
   canDiscard: Boolean;
begin
   Msg.Result := 0;                 {note the 32 bit value}
   DragQueryFile(Msg.wParam, 0, {@}buff, pred(sizeof(buff)));
   FName := strpas(buff);
   FormCloseQuery(Open1, canDiscard);
   if canDiscard then
        PlusMemo1.Lines.LoadFromFile(FName);
   PlusMemo1.Modified := False;
   DragFinish(Msg.wParam);
   BringToFront;
end;

0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1339636
Hi

When your program is an icon on the desktop it is not running, so it doesn't process any messages (including WM_DROPFILES).  So, to get around this, Windows passes in the dropped file(s) as command-line parameters when the program runs for the first time.

You thus need 2 methods of trapping the files (without going the whole OLE DropTarget route).

The 1st method is for when the program is already running.  This is your existing method, which you must keep.

The 2nd method is for when the program isn't running.  For this you need to do the following in your FormCreate:

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  for i := 1 to ParamCount do
    PlusMemo1.Lines.Add(ParamStr(i));

  DragAcceptFiles(Handle, True);
end;

That should do the trick.

Cheers,
JB
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:swright243
ID: 1339637
Your reply was exactly what I needed for Delphi 3 and Win95. But it does not work with the second part of this problem, i.e., Windows 3.1 and Delphi 1. Dropping a file on a minimized applications icon does not load the new file with this technique. I have to have both solutions since my clients are using both at least for the next year.

Thanks

0
 

Author Comment

by:swright243
ID: 1339638
I am going to award a B for this answer since it is only a partial answer though very good nonetheless. But I really need the answer for Win3.1 and Delphi 1.

0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1339639
Ok.  I don't have Delphi 1 here, but I will look on Monday at work.

Regards,
JimBob
0
 

Author Comment

by:swright243
ID: 1339640
I have posted this question again just for Win 3.1 and Delphi 1 since it is very important to me. We can pick this discussion up again there (for another 100!)
Thanks again.

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question