Board index » delphi » Drag bmp from desktop to my app

Drag bmp from desktop to my app

 Have any of you used Johnson and Melander's Drag and Drop
component? Following their source code, I can drag and drop bmp's
within my own app but can't figure out how to drop desktop icons
into it. I imagine that what I need to know isn't specific to this
component, but this is new territory for me and I'd appreciate some
pointers. Google isn't helping me this time.

==
Brad Blanchard

 

Re:Drag bmp from desktop to my app


On Sun, 09 Mar 2003 12:27:05 +0100, GB Blanchard

Quote
<1...@1122noexiste.net> wrote:
> Have any of you used Johnson and Melander's Drag and Drop
>component? Following their source code, I can drag and drop bmp's
>within my own app but can't figure out how to drop desktop icons
>into it. I imagine that what I need to know isn't specific to this
>component, but this is new territory for me and I'd appreciate some
>pointers. Google isn't helping me this time.

I've not messed around with that control

However from what I can see (and I may be wrong) Delphi's built in
Drag and Drop stuff is for just things within the same Application

However a little poking around in the Win32 Programmer's Reference
Help File revealed this :-

Basically click the button to invoke DragAcceptFiles() then respond to
the WM_DROPFILES message

Dragged file names will show up in the Form's Caption

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure OnDropFiles(var Message: TWMDropFiles); message
WM_DROPFILES;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
Uses ShellAPI;
procedure TForm1.Button1Click(Sender: TObject);
begin
  DragAcceptFiles(Self.Handle, True);
end;

procedure TForm1.OnDropFiles(var Message: TWMDropFiles);
Var
  S :String;
  I :Integer;
begin
  SetLength( S, 255 );
  I := DragQueryFile( Message.Drop, 0, PChar(S), Length(S) );
  SetLength( S, I );
  Self.Caption := S;
  Message.Result := 0;
end;

end.

Re:Drag bmp from desktop to my app


Quote
On Sun, 09 Mar 2003 12:30:52 GMT, J French wrote:
> Basically click the button to invoke DragAcceptFiles() then respond to
> the WM_DROPFILES message

> Dragged file names will show up in the Form's Caption

 Actually, I have found snippets on Google similar to what you've so
generously posted here. But the problem is getting the desktop BMPs or
icons to drop onto a TImage in my app. It's becoming frustrating because
I see lots of applications doing it, by I can't find any information on
how to do it myself. Since this is new territory for me, I probably not
finding any information because I don't know what keywords to use in my
search, though believe me, I've tried.

==
Brad Blanchard

Re:Drag bmp from desktop to my app


On Sun, 09 Mar 2003 14:49:31 +0100, GB Blanchard

Quote
<1...@1122noexiste.net> wrote:
>On Sun, 09 Mar 2003 12:30:52 GMT, J French wrote:

>> Basically click the button to invoke DragAcceptFiles() then respond to
>> the WM_DROPFILES message

>> Dragged file names will show up in the Form's Caption

> Actually, I have found snippets on Google similar to what you've so
>generously posted here. But the problem is getting the desktop BMPs or
>icons to drop onto a TImage in my app. It's becoming frustrating because
>I see lots of applications doing it, by I can't find any information on
>how to do it myself. Since this is new territory for me, I probably not
>finding any information because I don't know what keywords to use in my
>search, though believe me, I've tried.

I am not sure that these Apps are really 'dropping a bitmap' onto an
image.

I suspect that they are getting the name of the bitmap and loading it
(correction - replace 'suspect' with 'am certain')

They can only do things that are 'supported' by the Windows
environment, and that does not seem to offer a great deal outside one
App.

Are you trying to get the Icon of the .LNK file or App
something like ExtractAssociatedIcon() ?
So it looks as if the User has 'added' some file to your App

Try adding this into your code
I am not sure how exactly it works, as I've cobbled it together from
an API Guide in 'another language'

procedure TForm1.OnDropFiles(var Message: TWMDropFiles);
Var
  S :String;
  I :Integer;
  mIcon :THandle;
  P :Word;
begin
  SetLength( S, 255 );
  I := DragQueryFile( Message.Drop, 0, PChar(S), Length(S) );
  SetLength( S, I );
  Self.Caption := S;
  // Grab the Icon
  P := 0;
  mIcon := ExtractAssociatedIcon(Self.Handle, PChar(S), P );
  DrawIconEx( Self.Canvas.Handle, 0, 0, mIcon, 0, 0, 0, 0, DI_NORMAL
);
  // remove the icon from the memory
  DestroyIcon( mIcon );

  Message.Result := 0;
end;

Re:Drag bmp from desktop to my app


Quote
On Sun, 09 Mar 2003 14:53:24 GMT, J French wrote:
> Are you trying to get the Icon of the .LNK file or App
> something like ExtractAssociatedIcon() ?
> So it looks as if the User has 'added' some file to your App

> Try adding this into your code...

 And it does work! I'm not sure how yet, but at least you've given
me a starting point to get in and figure things out. Thank you very
much, J French!

==
Brad Blanchard

Other Threads