如题,就是可以将拖拽的文本或图片拖到一个窗体上可以得到这些信息!

解决方案 »

  1.   


    实现拖入外部文件。声明消息
    procedure WMDROPFILES(var Message: TWMDROPFILES); message WM_DROPFILES;procedure TForm1.WMDROPFILES(var Message: TWMDROPFILES);
    var NumFiles : longint;
    i : longint;
    i2:integer;
    buffer : array[0..255] of char;
    FFL:Tstringlist;//拖入文件
    begin
    FFL:=Tstringlist.create;
    try
    NumFiles:= DragQueryFile(Message.Drop,$FFFFFFFF, nil, 0);//WinShellAPI调用,返回拖入文件总数。
    for i := 0 to (NumFiles - 1) do//遍历文件
    begin
    DragQueryFile(Message.Drop, i, @buffer, sizeof(buffer));//WinShellAPI调用,获得文件名。
    FFl.LoadFromFile(buffer);//读拖进的文件文件。
    //处理拖进的文件
    end;
    finally
    DragFinish( Message.Drop );//完成拖放。
    ffl.free;
    end;
    end;
      

  2.   

    hehe,应该不用这么麻烦的楼主能不能说的详细一点
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,shellapi, StdCtrls;type
      TForm1 = class(TForm)
        Memo1: TMemo;
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        procedure WMDROPFILES(var Message: TWMDROPFILES); message WM_DROPFILES;
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.WMDROPFILES(var Message: TWMDROPFILES);
    var
      NumFiles : longint;
      i : longint;
      i2:integer;
      buffer : array[0..255] of char;
      FFL:Tstringlist;//拖入文件
    begin
      FFL:=Tstringlist.create;
      try
        NumFiles:= DragQueryFile(Message.Drop,$FFFFFFFF, nil, 0);//WinShellAPI调用,返回拖入文件总数。
        for i := 0 to (NumFiles - 1) do//遍历文件
        begin
          DragQueryFile(Message.Drop, i, @buffer, sizeof(buffer));//WinShellAPI调用,获得文件名。
          FFl.LoadFromFile(buffer);//读拖进的文件文件。
          Memo1.Lines.Add(FFl.Text);
          //处理拖进的文件
        end;
        memo1.Lines.Add('c:/123.txt');  //保存自己的目录
      finally
        DragFinish( Message.Drop );//完成拖放。
        ffl.free;
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      DragAcceptFiles(Form1.Handle,True);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      memo1.Lines.SaveToFile('c:/123.txt');
    end;end.
      

  4.   

    memo1.Lines.Add('c:/123.txt');  //保存自己的目录
    写错了,应该是memo1.Lines.SaveToFile('c:/123.txt');
      

  5.   

    我只知道用VB我做过一个,但是用delphi做的话,我是用了一个richedit来做的。不过其实也可以用webbrowser来做啊。
      

  6.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Mask, ExtCtrls,
      ActiveX, ComObj, ClipBrd;type
      TForm1 = class(TForm, IDropTarget) //ActiveX
        Panel1: TPanel;
        Memo1: TMemo;
        Panel2: TPanel;
        MaskEdit1: TMaskEdit;
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormCreate(Sender: TObject);
      private
        // IDropTarget
        function DragEnter(const dataObj: IDataObject; grfKeyState: Longint;
                           pt: TPoint; var dwEffect: Longint): HResult; stdcall;
        function DragOver(grfKeyState: Longint; pt: TPoint;
                          var dwEffect: Longint): HResult; stdcall; 
        function DragLeave: HResult; stdcall; 
        function Drop(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint;
                      var dwEffect: Longint): HResult; stdcall; 
       // Ignore referance counting
       function _AddRef: Integer; stdcall; 
       function _Release: Integer; stdcall; 
      public
      end;var
      Form1: TForm1;implementation
    uses ShellAPI;{$R *.dfm}function TForm1.DragEnter(const dataObj: IDataObject; grfKeyState: Longint;
                              pt: TPoint; var dwEffect: Longint): HResult;
    begin 
      dwEffect := DROPEFFECT_COPY; 
      Result   := S_OK;
    end;function TForm1.DragOver(grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult;
    begin 
      dwEffect := DROPEFFECT_COPY; 
      Result := S_OK; 
    end;function TForm1.DragLeave: HResult;
    begin 
      Result := S_OK; 
    end;function TForm1._AddRef: Integer;
    begin 
       Result := 1; 
    end;function TForm1._Release: Integer;
    begin 
       Result := 1; 
    end;function TForm1.Drop(const dataObj: IDataObject; grfKeyState: Longint;
                         pt: TPoint; var dwEffect: Longint): HResult;
    var
      aFmtEtc: TFORMATETC;
      aStgMed: TSTGMEDIUM;
      pData: PChar;
    begin
      if (dataObj = nil) then   //Make certain the data rendering is available
        raise Exception.Create('IDataObject-Pointer is not valid!');  with aFmtEtc do begin
        cfFormat := CF_TEXT;   //RegisterClipboardFormat('UniformResourceLocator')
        //cfFormat := CF_HDROP;
        //cfFormat := RegisterClipboardFormat('UniformResourceLocator');
        ptd := nil;
        dwAspect := DVASPECT_CONTENT; 
        lindex := -1;
        tymed := TYMED_HGLOBAL;
      end;  OleCheck(dataObj.GetData(aFmtEtc, aStgMed)); //Get the data(uses ComObj)
      try
        pData := GlobalLock(aStgMed.hGlobal); //Lock the global memory handle to get a pointer to the data
        MaskEdit1.Text := pData;              //Replace Text
        Memo1.Text     := pData;
        //Memo1.Text := ClipBoard.AsText;
      finally
        GlobalUnlock(aStgMed.hGlobal);        //Finished with the pointer
        ReleaseStgMedium(aStgMed);            //Free the memory
      end;
      Result := S_OK; 
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      OleInitialize(nil);
      OleCheck(RegisterDragDrop(Handle, Self)); //Allow window to accept drop events
    end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      RevokeDragDrop(Handle); //Finished accepting drops
      OleUninitialize;
    end;end.(注:拖动浏览网页的文字到窗体上的Memo1中)