ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Drag n Drop files on ImageEnMView

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
yogiyang Posted - Dec 05 2015 : 01:18:23
Hello,

I want to give facility to users to drag n drop files from windows explorer on ImageEnM View and add them to it.

Any ideas as to how we can achieve this?

Please guide me.

TIA

Yogi Yang


Yogi Yang
14   L A T E S T    R E P L I E S    (Newest First)
yogiyang Posted - Mar 26 2016 : 06:44:35
Bill,
Thanks for the demo.

Nigel,
I never knew such a class (TIEFileDragDrop) ever existed in ImageEn!




Yogi Yang
xequte Posted - Mar 21 2016 : 14:02:45
Nice one, Bill

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
w2m Posted - Mar 21 2016 : 11:04:54
Thanks Nigel,

I have made the appropriate changes to the demo and uploaded a demo here: http://www.imageen.com/ieforum/topic.asp?whichpage=3.8&TOPIC_ID=1446#9202

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
xequte Posted - Mar 20 2016 : 20:30:34
Hi Bill

Nice demo, it worked well.

You might want to add a check to:

  iFrameCount := IEGetFileFramesCount(iDroppedFileName);

To handle iFrameCount = 0.

It is best to the let the application handle the freeing of TIEFileDragDrop. Of course then you will get a warning from your memory management tool so you need to register the expected leak (not that it is actually a leak. The object exists for the time of the application and is destroyed when the owner is destroyed).

  RegisterExpectedMemoryLeak( fDragDrop );  // we will not explicity free




Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
w2m Posted - Mar 20 2016 : 12:00:12
Nigel, I have developed a small demo for TIEFileDragDrop because it is not documented well. Drag and drop from the shell to TImageEnMView works very well and is easy to use except when I try to free the class I get an exception, so I assume that the class is freed when the ImageEnMView is destroyed. Unfortunately EurekaLog shows a memory leak as a result of not freeing the class when the form is closed.

This is unusual, so how do you handle the memory leak?
var
 AFileDrop: TIEFileDragDrop;

procedure TForm1.FormCreate(Sender: TObject);
begin
  { Create a TIEFileDragDrop class }
  AFileDrop := TIEFileDragDrop.Create(ImageEnMView1, DropFiles);
  { Activate dropping }
  AFileDrop.ActivateDropping := True;
  ImageEnMView1.SetModernStyling(False, 200, 150);
  ImageEnView1.Blank;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  AFileDrop.Free;  // Exception 
end;

I have uploaded the demo for your review.
Notes: TIEFileDragDrop can not be freed so there is a memory leak. This demo is not ready for general use because of the leak.
attach/w2m/201632012154_ShellDrop.zip
52.02 KB
Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
xequte Posted - Mar 20 2016 : 00:59:49
Hi

Why not just use TImageEnFolderMView which already supports drag/drop (and works in exactly the same way as TImageEnMView)?

Failing that, see use of the TIEFileDragDrop class in iexFolderMView.pas for example usage.


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
w2m Posted - Mar 19 2016 : 11:26:05
I tried to figure out how to get the drop to only take place if the cursor is over TImageEnMView for several hours but I have not been able to get it to function. If you change 'Handle' to 'ImageEnMView1.Handle' the drop should take place only on the ImageEnMView rather than the Form, but no drop occurs. The WMDROPFILES event is not executed with DragAcceptFiles(ImageEnMView1.Handle, True). I also tried using some message handling to determine if the cursor is over the ImageEnMView or not but, the message handler not called before the WMDROPFILES event so even the message handling does not function either.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
yogiyang Posted - Mar 19 2016 : 00:54:14
Hello Bill,

Your code is work properly. But my needs have changed a bit!
When I use your code to accept drag and drop files from Windows Explorer the whole Form start working as a drag and drop area. Instead of this I just drag and drop to work only if the user drags and drops on ImageEnM control on the form. Any hints as to how I can achieve this?

TIA



Yogi Yang
yogiyang Posted - Dec 09 2015 : 21:54:56
Hello Nigel,

Thanks for the suggestion to use TImageEnFolderMView. I will try that.

Thank you,


Yogi Yang
xequte Posted - Dec 09 2015 : 21:17:52
For Drag and Drop support, you can also use a TImageEnFolderMView instead of a TImageEnMView. It has drag and drop support built in.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
xequte Posted - Dec 09 2015 : 21:16:51
Hi Yogi

To add the filename below the image, set DefaultBottomText to iedtFilename.

http://www.imageen.com/help/TImageEnMView.DefaultBottomText.html

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
yogiyang Posted - Dec 09 2015 : 00:01:03
When I use this code:
iemAddPhotos.MIO.LoadFromFile(PhotoFileName);

The image is added but the file name does not show up under it. The same applies with the Drag-n-Drop code also.

But if I use this code to load images from a folder:
iemAddPhotos.FillFromDirectory(PhotoFolderPath, -1, false);

All images loaded have their file name showing under each thumbnail.

As per my understanding ImageEnM should automatically retrieve the file names and show them under each thumbnail.

Why?

TIA


Yogi Yang
yogiyang Posted - Dec 08 2015 : 03:54:35
Bill,

Thanks for your help.

It works like a charm.

Regards,




Yogi Yang
w2m Posted - Dec 05 2015 : 09:00:21
Do you want to drag from Windows File Explorer or Windows Internet Explorer? For the latter you need a third-party drag and drop component such as Raize Drag and Drop. For the former you need to Set DragAcceptFiles to true and then handle the WMDROPFILES event to obtain the dropped filenames.

Drag From Windows File Explorer
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.ExtCtrls, hyieutils, iexBitmaps, hyiedefs, iesettings, imageenview,
  ieview, iemview, Vcl.ComCtrls;

type
  TForm1 = class(TForm)
    ImageEnMView1: TImageEnMView;
    ImageEnView1: TImageEnView;
    Splitter1: TSplitter;
    StatusBar1: TStatusBar;
    procedure FormCreate(Sender: TObject);
    procedure ImageEnMView1ImageSelect(Sender: TObject; idx: Integer);
  private
    { Private declarations }
    AFilePath: string;
    AFilename: string;
    procedure WMDROPFILES(var Message: TWMDropFiles); message WM_DROPFILES;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Winapi.ShlObj, Winapi.ShellAPI;

procedure TForm1.FormCreate(Sender: TObject);
begin
  { Accept dragged files - this is important }
  DragAcceptFiles(Handle, True);
  ImageEnMView1.SetModernStyling(False, 200, 150);
  ImageEnView1.Blank;
end;

procedure TForm1.ImageEnMView1ImageSelect(Sender: TObject; idx: Integer);
var
  iBitDepth: Integer;
  iColors: string;
begin
  ImageEnMView1.CopyToIEBitmap(idx, ImageEnView1.IEBitmap);
  ImageEnView1.IO.Params.Assign(ImageEnMView1.MIO.Params[idx]);
  ImageEnView1.Update;
  StatusBar1.Panels[0].Text :=
    ExtractFileDir(ImageEnMView1.MIO.Params[idx].FileName);
  StatusBar1.Panels[1].Text :=
    ExtractFileName(ImageEnMView1.MIO.Params[idx].FileName);
  StatusBar1.Panels[3].Text := 'Frame: ' + IntToStr(idx + 1);
  StatusBar1.Panels[4].Text := IntToStr(ImageEnMView1.MIO.Params[idx].Width) +
    ' x ' + IntToStr(ImageEnMView1.MIO.Params[idx].Height);
  iBitDepth := ImageEnMView1.MIO.Params[idx].BitsPerSample *
    ImageEnMView1.MIO.Params[idx].SamplesPerPixel;
  if iBitDepth = 32 then
    iColors := 'RGBA' + IntToStr(iBitDepth) + '-Bit'
  else
    iColors := 'RGB' + IntToStr(iBitDepth) + '-Bit';
  StatusBar1.Panels[5].Text := iColors;
end;

procedure TForm1.WMDROPFILES(var Message: TWMDropFiles);
{ Handle opening files from Windows File Explorer Drag & Drop. }
const
  iMaxLength = 255;
var
  i: Integer;
  iFileCount: Integer;
  iDroppedFileName: array [0 .. MAX_PATH] of Char;
  iDroppedFilePath: string;
  iFileName: string;
  iFrameCount: Integer;
  iIndex: Integer;
  iBitDepth: Integer;
  iColors: string;
begin
  inherited;
  iFileCount := DragQueryFile(message.Drop, $FFFFFFFF, nil, 0);
  if iFileCount = 1 then
  begin { Single file dropped }
    DragQueryFile(Message.Drop, 0, iDroppedFileName, MAX_PATH);
    iDroppedFilePath := iDroppedFileName;
    if FileExists(iDroppedFilePath) then
    begin
      iFrameCount := IEGetFileFramesCount(iDroppedFilePath);
      if iFrameCount = 1 then
      begin
        { Single frame file }
        AFilePath := iDroppedFilePath;
        AFilename := ExtractFileName(iDroppedFilePath);
        iIndex := ImageEnMView1.AppendImage(AFilePath);
        ImageEnMView1.ImageBottomText[iIndex] := AFilename;
        ImageEnMView1.ImageInfoText[iIndex] :=
          IntToStr(ImageEnMView1.MIO.Params[iIndex].Width) + ' x ' +
          IntToStr(ImageEnMView1.MIO.Params[iIndex].Height);
        ImageEnMView1.SelectedImage := iIndex;
        StatusBar1.Panels[0].Text :=
          ExtractFileDir(ImageEnMView1.MIO.Params[iIndex].FileName);
        StatusBar1.Panels[1].Text := AFilename;
        StatusBar1.Panels[2].Text := 'Frames: ' + IntToStr(iFrameCount);
        StatusBar1.Panels[3].Text := 'Frame: ' + IntToStr(iIndex + 1);
        StatusBar1.Panels[4].Text :=
          IntToStr(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].Width) + ' x ' +
          IntToStr(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].Height);
        iBitDepth := ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].BitsPerSample *
          ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].SamplesPerPixel;
        if iBitDepth = 32 then
          iColors := 'RGBA' + IntToStr(iBitDepth) + '-Bit'
        else
          iColors := 'RGB' + IntToStr(iBitDepth) + '-Bit';
        StatusBar1.Panels[5].Text := iColors;
      end
      else
      begin
        { Multiple frame file }
        ImageEnMView1.Clear;
        iFileName := iDroppedFilePath;
        for i := 0 to iFrameCount - 1 do
        begin
          ImageEnMView1.AppendImage(iFileName + IEM_Path_Index_Delimiter +
            IntToStr(i));
          ImageEnMView1.ImageBottomText[i] := ExtractFileName(iFileName);
          ImageEnMView1.ImageInfoText[i] := 'Frame: ' + IntToStr(i + 1);
        end;
        ImageEnMView1.SelectedImage := 0;
        StatusBar1.Panels[0].Text :=
          ExtractFileDir(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage]
          .FileName);
        StatusBar1.Panels[1].Text := ExtractFileName(iFileName);
        StatusBar1.Panels[2].Text := 'Frames: ' + IntToStr(iFrameCount);
        StatusBar1.Panels[3].Text := 'Frame: ' + IntToStr(ImageEnMView1.SelectedImage + 1);
        StatusBar1.Panels[4].Text :=
          IntToStr(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].Width) + ' x ' +
          IntToStr(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].Height);
        iBitDepth := ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].BitsPerSample *
          ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].SamplesPerPixel;
        if iBitDepth = 32 then
          iColors := 'RGBA' + IntToStr(iBitDepth) + '-Bit'
        else
          iColors := 'RGB' + IntToStr(iBitDepth) + '-Bit';
        StatusBar1.Panels[5].Text := iColors;
      end;
    end;
  end
  else { Multiple files dropped }
  begin
    for i := 0 to iFileCount - 1 do
    begin
      { Get filenames dropped }
      DragQueryFile(Message.Drop, i, iDroppedFileName, iMaxLength);
      iFileName := iDroppedFileName;
      ImageEnMView1.InsertImage(i, iFileName);
      ImageEnMView1.ImageBottomText[i] := ExtractFileName(iFileName);
      ImageEnMView1.ImageInfoText[i] :=
        IntToStr(ImageEnMView1.MIO.Params[i].Width) + ' x ' +
        IntToStr(ImageEnMView1.MIO.Params[i].Height);
    end;
    ImageEnMView1.SelectedImage := 0;
    StatusBar1.Panels[0].Text :=
      ExtractFileDir(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage]
      .FileName);
    StatusBar1.Panels[1].Text :=
      ExtractFileName(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage]
      .FileName);
    StatusBar1.Panels[2].Text := 'Frames: ' + IntToStr(ImageEnMView1.ImageCount);
    StatusBar1.Panels[3].Text := 'Frame: ' + IntToStr(ImageEnMView1.SelectedImage + 1);
    StatusBar1.Panels[4].Text := IntToStr(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].Width) +
      ' x ' + IntToStr(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].Height);
    iBitDepth := ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].BitsPerSample *
      ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].SamplesPerPixel;
    if iBitDepth = 32 then
      iColors := 'RGBA' + IntToStr(iBitDepth) + '-Bit'
    else
      iColors := 'RGB' + IntToStr(iBitDepth) + '-Bit';
    StatusBar1.Panels[5].Text := iColors;
  end;
end;
end.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development