Solved

drag and drop on a desktop icon

Posted on 1998-04-30
7
347 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month3 days, 17 hours left to enroll

630 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