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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Drag and Drop from explorer Win7
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

klausdoege

Germany
389 Posts

Posted - Feb 04 2014 :  09:24:21  Show Profile  Reply
Hello,
how can i with drag and drop, a imagefile from windows explorer
insert into a imageenview ?
Have everybody a example ?

Klaus
www.klausdoege.de

w2m

USA
1990 Posts

Posted - Feb 04 2014 :  10:16:01  Show Profile  Reply
Here is one way to do it.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, imageenview, ieview, ComCtrls;

type
  TForm1 = class(TForm)
    ImageEnView1: TImageEnView;
    StatusBar1: TStatusBar;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  protected
    { Protected declarations }
    procedure WMDropFiles(var Message: TWMDropFiles); message WM_DROPFILES;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses ShellAPI, hyieutils, imageenio;

procedure TForm1.FormCreate(Sender: TObject);
begin
  { Activate accepting files from the Windows shell }
  DragAcceptFiles(Self.Handle, True);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  { Deactivate accepting files from the Windows shell }
  DragAcceptFiles(Self.Handle, False);
end;

procedure TForm1.WMDropFiles(var Message: TWMDropFiles);
{ Handle dropping files to the form from Windows Explorer }
var
  i: Integer;
  iFilename: array [0 .. 256] of char;
  iNumberOfFiles: Integer;
  DropInfo: HDROP;
begin
  Screen.Cursor := crHourGlass;
  try
    try
      iNumberOfFiles := DragQueryFile(message.Drop, $FFFFFFFF, nil, 0);
      if iNumberOfFiles = 1 then
      begin
        DragQueryFile(message.Drop, 0, iFilename, SizeOf(iFilename));
        if (FileExists(iFilename)) and (IsKnownFormat(iFilename)) then
        begin
          ImageEnView1.IO.LoadFromFile(iFilename);
          ImageEnView1.Proc.ClearAllUndo;
          ImageEnView1.Proc.ClearAllRedo;
          ImageEnView1.MouseInteract := [];
          StatusBar1.Panels[0].Text := ExtractFileDir(iFilename);
          StatusBar1.Panels[1].Text := ExtractFileName(iFilename);
        end
        else
        begin
          MessageBox(0, 'The file is not supported.', 'Warning',
            MB_ICONWARNING or MB_OK);
        end;
      end
      else
        MessageBox(0,
          'This application only allows dropping one file at a time.',
          'Warning', MB_ICONWARNING or MB_OK);
    finally
      DragFinish(message.Drop);
    end;
    inherited;
  finally
    Screen.Cursor := crDefault;
  end;
end;

end.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

klausdoege

Germany
389 Posts

Posted - Feb 04 2014 :  14:08:06  Show Profile  Reply
Hello William,

thank you, I have looked exactly for that.
I will immediately try it.

greet
Klaus

Klaus
www.klausdoege.de
Go to Top of Page

klausdoege

Germany
389 Posts

Posted - Feb 05 2014 :  05:11:54  Show Profile  Reply
Hello William,
it not works ?
Must i set every property by TForm or Imageenview ?
The Procedure WMDropFiles(var Message: TWMDropFiles);
not work.
regards
Klaus


Klaus
www.klausdoege.de
Go to Top of Page

w2m

USA
1990 Posts

Posted - Feb 05 2014 :  05:34:54  Show Profile  Reply
The code I posted was tested and it works here. How many forms are you dragging and dropping to? This code just allows dropping to the main form as I have not tested dropping to secondary forms.

William Miller
Go to Top of Page

klausdoege

Germany
389 Posts

Posted - Feb 05 2014 :  06:19:27  Show Profile  Reply
It's only one form.
When i start with f4 in the wmdropfile procedure, i can
see nothing by drag and drop?

klaus


Klaus
www.klausdoege.de
Go to Top of Page

w2m

USA
1990 Posts

Posted - Feb 05 2014 :  06:47:35  Show Profile  Reply
What version of Windows?
What version of ImageEn?

I am using Windows 8.1 and DelphiXE4 now, but previously the code also worked with Windows 7 and previous versions of ImageEn.

I have no problems here.

William Miller
Go to Top of Page

w2m

USA
1990 Posts

Posted - Feb 05 2014 :  08:59:23  Show Profile  Reply
Did you get the demo I emailed you?

William Miller
Go to Top of Page

klausdoege

Germany
389 Posts

Posted - Feb 07 2014 :  07:14:56  Show Profile  Reply
Hi Bill,
the Demeo works with XP fine, but not with Windows 7.
Tank you for your Help.


Klaus
www.klausdoege.de
Go to Top of Page

w2m

USA
1990 Posts

Posted - Feb 09 2014 :  11:03:14  Show Profile  Reply
In case others are following this thread I suggest the following:

On Vista and Windows 7 you can't send messages to a process with a higher integrity level. If your process is being run as administrator then it will have a higher integrity level than explorer and so won't accept the dropped files. If you are running Windows as administrator with UAC turned off, turn UAC back on and then recompile the demo.

All Delphi developers are encouraged to always run Delphi with UAC (User Account control) turned on.

This solved Klaus's problem.

Here is a link that shows how to turn UAC on/off with Windows 7.
http://windows.microsoft.com/en-us/windows/turn-user-account-control-on-off#1TC=windows-7

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

Vitaly

Ukraine
4 Posts

Posted - Sep 14 2016 :  12:26:00  Show Profile  Reply
procedure CreateParams(var Params: TCreateParams); override;

procedure TUFormOrImEnView.CreateParams(var Params: TCreateParams);
begin
inherited

CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_ACCEPTFILES;
end;


465124
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: