На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
Модераторы: jack128, Rouse_, Krid
  
    > Перетаскивание файлов в приложение
      ExpandedWrap disabled
        unit Unit1;
         
        interface
         
        uses
          Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
          Dialogs, ShellAPI;
         
        type
          TForm1 = class(TForm)
            procedure FormCreate(Sender: TObject);
          private
            procedure GetFile(var Message: TMessage); message WM_DROPFILES;
          end;
         
        var
          Form1: TForm1;
         
        implementation
         
        {$R *.dfm}
         
        { TForm1 }
         
        procedure TForm1.FormCreate(Sender: TObject);
        begin
          DragAcceptFiles(Handle, True);
        end;
         
        procedure TForm1.GetFile(var Message: TMessage);
        var
          FileNames: String;
          FileName: PChar;
          FileCount, I: Integer;
        begin
          GetMem(FileName, MAX_PATH);
          try
            FileCount := DragQueryFile(Message.WParam, DWORD(-1), nil, 0);
            for I := 0 to FileCount - 1 do
            begin
              if FileNames <> '' then FileNames := FileNames + #13#10;
              DragQueryFile(Message.WParam, I, FileName, MAX_PATH);
              FileNames := FileNames + FileName;
            end;
            ShowMessage(FileNames);
          finally
            FreeMem(FileName);
          end;
        end;
         
        end.


      Эта тема была разделена из темы "Перетаскивание файлов в приложение"
        Аналог, но в качестве приемника будет выступать ListView:

        ExpandedWrap disabled
          unit Unit1;
           
          interface
           
          uses
            Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
            Dialogs, ComCtrls, ShellAPI, AppEvnts;
           
          type
            TForm1 = class(TForm)
              ListView1: TListView;
              ApplicationEvents1: TApplicationEvents;
              procedure FormCreate(Sender: TObject);
              procedure ApplicationEvents1Message(var Msg: tagMSG;
                var Handled: Boolean);
            end;
           
          var
            Form1: TForm1;
           
          implementation
           
          {$R *.dfm}
           
          procedure TForm1.FormCreate(Sender: TObject);
          begin
            DragAcceptFiles( ListView1.Handle, True);
          end;
           
          procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
            var Handled: Boolean);
          var
            FileName: PChar;
            FileCount, I: Integer;
          begin
            if Msg.message = WM_DROPFILES then
            begin
              GetMem(FileName, MAX_PATH);
              try
                FileCount := DragQueryFile(Msg.WParam, DWORD(-1), nil, 0);
                for I := 0 to FileCount - 1 do
                begin
                  DragQueryFile(Msg.WParam, I, FileName, MAX_PATH);
                  with ListView1.Items.Add do Caption := FileName;
                end;
              finally
                FreeMem(FileName);
              end;
            end;
          end;
           
          end.
        0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
        0 пользователей:


        Рейтинг@Mail.ru
        [ Script execution time: 0,0180 ]   [ 16 queries used ]   [ Generated: 27.04.24, 09:08 GMT ]