请问该如何实现“一拖即存”的功能,100分 如题,就是可以将拖拽的文本或图片拖到一个窗体上可以得到这些信息! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 实现拖入外部文件。声明消息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;//拖入文件beginFFL:=Tstringlist.create;tryNumFiles:= DragQueryFile(Message.Drop,$FFFFFFFF, nil, 0);//WinShellAPI调用,返回拖入文件总数。for i := 0 to (NumFiles - 1) do//遍历文件beginDragQueryFile(Message.Drop, i, @buffer, sizeof(buffer));//WinShellAPI调用,获得文件名。FFl.LoadFromFile(buffer);//读拖进的文件文件。//处理拖进的文件end;finallyDragFinish( Message.Drop );//完成拖放。ffl.free;end;end; hehe,应该不用这么麻烦的楼主能不能说的详细一点 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. memo1.Lines.Add('c:/123.txt'); //保存自己的目录写错了,应该是memo1.Lines.SaveToFile('c:/123.txt'); 我只知道用VB我做过一个,但是用delphi做的话,我是用了一个richedit来做的。不过其实也可以用webbrowser来做啊。 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;implementationuses 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 eventsend;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin RevokeDragDrop(Handle); //Finished accepting drops OleUninitialize;end;end.(注:拖动浏览网页的文字到窗体上的Memo1中) ShockwaveFlash调用flash函数返回值的问题`` select语句的唯一值怎么赋给labe1.caption或edit1.text?? CxGrid能实现吗? QuickReport组件预览、打印数据不完整,只能打前几页数据,后面的数据似乎丢了 JVCL3.0正式出来啦! 4个活动窗体,怎么处理? 动态创建控件 请问如何将一个实数去它的上界,比如 21.2 取成 22呢? CoreSoapCtrl源代码 存储过程请教 在DELPHI里可不可以不用裝打印機,直接將數據送到LPT端口? clientdataset 數據更新出現key violation 錯誤信息!
实现拖入外部文件。声明消息
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;
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.
写错了,应该是memo1.Lines.SaveToFile('c:/123.txt');
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中)