如何让程序接受拖过来的文件(可能多个) 包括两点:1,拖文件到程序Exe文件上时打开文件2,程序已经运行,拖文件到程序窗体中时打开文件 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls,shellapi;type TForm1 = class(TForm) ListView1: TListView; 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}procedure TForm1.FormCreate(Sender: TObject);begin//file://设置需要处理文件WM_DROPFILES拖放消息DragAcceptFiles(ListView1.Handle, TRUE);//file://设置AppMessage过程来捕获所有消息Application.OnMessage := AppMessage;end;procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean); varnFiles, I: Integer;Filename: string;ListItem: TListItem;begin//// 注意!所有消息都将通过这里!// 不要在此过程中编写过多的或者需要长时间操作的代码,否则将影响程序的性能 // // 判断是否是发送到ListView1的WM_DROPFILES消息 if (Msg.message = WM_DROPFILES) and (msg.hwnd = ListView1.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://将全文件名分解程文件名和路径ListItem := ListView1.Items.Add; ListItem.Caption := ExtractFileName(FileName); ListItem.SubItems.Add(ExtractFilePath(FileName)); end; finally //file://结束这次拖放操作DragFinish (Msg.wParam); end; //file://标识已处理了这条消息Handled := True; end;end;////////////////////////////////////////////////////////////////// 这样的例子网上太多了http://lysoft.7u7.net 为何dxBarManager 中字体颜色设置无效? 问:当点击Dbgrid右边的垂直的滚动条和下面的横向滚动条时候能触发哪个事件? 菜鸟提问?(在线等) 大家好。我是网络新手,请指教,在线等 谁有胆量接受挑战?如何更改文本数据库的内容? 【求助】如何生成RTF格式的文件? Show与ShowModal的问题 急,在线求教二个简单DELPHI编程问题,回应给分,是关于数据库存取变量及文本框显示问题. 高分求访问SqlServer的方法!!! TpageControl的问题 换行 有关教育软件合作,大家来看看。帮忙顶顶
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls,shellapi;type
TForm1 = class(TForm)
ListView1: TListView;
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}procedure TForm1.FormCreate(Sender: TObject);
begin
//file://设置需要处理文件WM_DROPFILES拖放消息
DragAcceptFiles(ListView1.Handle, TRUE);
//file://设置AppMessage过程来捕获所有消息
Application.OnMessage := AppMessage;end;
procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
var
nFiles, I: Integer;
Filename: string;
ListItem: TListItem;
begin
//
// 注意!所有消息都将通过这里!
// 不要在此过程中编写过多的或者需要长时间操作的代码,否则将影响程序的性能
//
// 判断是否是发送到ListView1的WM_DROPFILES消息
if (Msg.message = WM_DROPFILES) and (msg.hwnd = ListView1.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://将全文件名分解程文件名和路径
ListItem := ListView1.Items.Add;
ListItem.Caption := ExtractFileName(FileName);
ListItem.SubItems.Add(ExtractFilePath(FileName));
end;
finally
//file://结束这次拖放操作
DragFinish (Msg.wParam);
end;
//file://标识已处理了这条消息
Handled := True;
end;
end;
///////////////////////////////
//
//
///////////////////////////////