以下的代码是拖到窗口form中,我想改为拖到memo中,可是
procedure Tform1.DropFiles(var Message:TMessage);
改为 procedure Tmemo1.DropFiles(var Message:TMessage); 并不能实现
请问如何修改。我delphi不是很熟,希望能给出本题的答案,而不是一大段代码。谢谢!
我没多少分了。见谅!unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellApi, StdCtrls;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure DropFiles(var Message:TMessage);message WM_DropFiles;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm} procedure Tform1.DropFiles(var Message:TMessage);
var
bufsize,num:Cardinal;
FilePath:array of Char;
begin
num:=DragQueryFile(Message.wParam,$FFFFFFFF,nil,0); //取得文件个数
for num:=0 to num-1 do begin
bufsize:=DragQueryFile(Message.wParam,num,nil,0);
setlength(FilePath,bufsize+1);
DragQueryFile(Message.wParam,num,pchar(FilePath),bufsize+1);
showmessage(pchar(FilePath)); //显示拖入来的文件完整路径
end;
dragfinish(Message.wParam);
end; procedure Tform1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle,True);
end;end.
procedure Tform1.DropFiles(var Message:TMessage);
改为 procedure Tmemo1.DropFiles(var Message:TMessage); 并不能实现
请问如何修改。我delphi不是很熟,希望能给出本题的答案,而不是一大段代码。谢谢!
我没多少分了。见谅!unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellApi, StdCtrls;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure DropFiles(var Message:TMessage);message WM_DropFiles;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm} procedure Tform1.DropFiles(var Message:TMessage);
var
bufsize,num:Cardinal;
FilePath:array of Char;
begin
num:=DragQueryFile(Message.wParam,$FFFFFFFF,nil,0); //取得文件个数
for num:=0 to num-1 do begin
bufsize:=DragQueryFile(Message.wParam,num,nil,0);
setlength(FilePath,bufsize+1);
DragQueryFile(Message.wParam,num,pchar(FilePath),bufsize+1);
showmessage(pchar(FilePath)); //显示拖入来的文件完整路径
end;
dragfinish(Message.wParam);
end; procedure Tform1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle,True);
end;end.
解决方案 »
- 如果你手上有个程序代码,要你修改,你会如何着手?
- idhttp 提交数据的地址为UTF-8编码时是不是需要转换???
- 有i个相同控件,如何指定到第i个???
- 怪事,提示没有找到类?帮我看看。
- 一个缩小图片的问题
- 请教怎么样用BDE实现与SQL SERVER2000数据库的连接...? SOS
- 关于dbgrid的简单问题
- 菜鸟问题:关于字符串
- 如何将几个文件(*.db),全并成一个文件(数据.rr),扩展名随便取。然后调用时,又怎么将期解开呢。
- 给我介绍一下DELPHI5内置的函数吧
- 在DBGrid中,我滚动鼠标滑轮时,只能在当前屏幕所能看到的数据行中上下滚动,而垂直滚动条就压根不动。
- QQ会员闹新春活动刷礼物外挂
->
Memo1.Lines.Append(StrPas(FilePath)); 不行吗?
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, activeX, shellapi, shlobj;
type
TForm1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
end;var
Form1: TForm1;implementation{$R *.dfm}type
LINK_FILE_INFO = record ///快捷方式文件信息数据结构
FileName: array[0..MAX_PATH] of char; ///目标文件名
WorkDirectory: array[0..MAX_PATH] of char; ///工作目录
IconLocation: array[0..MAX_PATH] of char; ///图标文件
IconIndex: integer; ///图标索引
Arguments: array[0..MAX_PATH] of char; ///运行参数
Description: array[0..255] of char; ///文件描述
ItemIDList: PItemIDList; ///系统IDList,未使用
RelativePath: array[0..255] of char; ///相对路径
ShowState: integer; ///运行时的现实状态
HotKey: word; ///热键
end;function linkfileinfo(const lnkfilename: string; var info: link_file_info; const bset: boolean): boolean;
var
hr: hresult;
psl: ishelllink;
wfd: win32_find_data;
ppf: ipersistfile;
lpw: pwidechar;
buf: pwidechar;
begin
result := false;
getmem(buf, max_path);
try
if succeeded(coinitialize(nil)) then
if (succeeded(cocreateinstance(clsid_shelllink, nil, clsctx_inproc_server, iid_ishelllinka, psl))) then
begin
hr := psl.queryinterface(ipersistfile, ppf);
if succeeded(hr) then
begin
lpw := stringtowidechar(lnkfilename, buf, max_path);
hr := ppf.load(lpw, stgm_read);
if succeeded(hr) then
begin
hr := psl.resolve(0, slr_no_ui);
if succeeded(hr) then
begin
if bset then
begin
psl.setarguments(info.arguments);
psl.setdescription(info.description);
psl.sethotkey(info.hotkey);
psl.seticonlocation(info.iconlocation, info.iconindex);
psl.setidlist(info.itemidlist);
psl.setpath(info.filename);
psl.setshowcmd(info.showstate);
psl.setrelativepath(info.relativepath, 0);
psl.setworkingdirectory(info.workdirectory);
result := succeeded(psl.resolve(0, slr_update));
end
else
begin
psl.getpath(info.filename, max_path, wfd, slgp_shortpath);
psl.geticonlocation(info.iconlocation, max_path, info.iconindex);
psl.getworkingdirectory(info.workdirectory, max_path);
psl.getdescription(info.description, 255);
psl.getarguments(info.arguments, max_path);
psl.gethotkey(info.hotkey);
psl.getidlist(info.itemidlist);
psl.getshowcmd(info.showstate);
result := true;
end;
end;
end;
end;
end;
finally
freemem(buf);
end;
end;function GetLinkFile_ExeName(LinkFile: string): string;
var
info: link_file_info;
begin
Result := '';
if linkfileinfo(LinkFile, info, False) then
begin
Result := info.FileName;
end;
end;procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
var
nFiles, I: Integer;
Filename: string;
begin
//
// 注意!所有消息都将通过这里!
// 不要在此过程中编写过多的或者需要长时间操作的代码,否则将影响程序的性能
//
// 判断是否是发送到ListView1的WM_DROPFILES消息
if (Msg.message = WM_DROPFILES) and (msg.hwnd = Memo1.Handle) then
begin
// 取dropped files的数量
nFiles := DragQueryFile(Msg.wParam, $FFFFFFFF, nil, 0);
// 循环取每个拖下文件的全文件名
try
for I := 0 to nFiles - 1 do
begin
// 为文件名分配缓冲 allocate memory
SetLength(Filename, 80);
// 取文件名 read the file name
DragQueryFile(Msg.wParam, I, PChar(Filename), 80);
Filename := PChar(Filename);
//file://将全文件名分解程文件名和路径
if UpperCase(ExtractFileExt(FileName)) = '.LNK' then
Memo1.Line.Add( GetLinkFile_ExeName(FileName))
else
Memo1.Line.Add(FileName); end;
finally
//file://结束这次拖放操作
DragFinish(Msg.wParam);
end;
//file://标识已处理了这条消息
Handled := True;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
//file://设置需要处理文件WM_DROPFILES拖放消息
DragAcceptFiles(Memo1.Handle, TRUE);
//file://设置AppMessage过程来捕获所有消息
Application.OnMessage := AppMessage;end;end.
例如DropMaster