【发布时间】:2012-07-12 13:26:47
【问题描述】:
我有一个接受拖放文件的表单,以及放置在同一表单上的 TPanel 控件上的 TWebBrowser 控件。
主要的是,当我在窗体上放置一个文件时,它的路径被添加到一个 TEdit 控件中。但是,当用户将文件拖放到表单上时,有时他们实际上可能会将其拖放到 TWebBrowser 上,该浏览器根据文件类型为用户提供保存或运行文件。这实际上是我不想发生的事情,我只想让 TWebBrowser 要么忽略删除的文件,要么像表单一样处理它。
这是我用来处理 WM_DROPFILES 消息的代码:
procedure TMainForm.AcceptFiles( var msg : TMessage );
const
cnMaxFileNameLen = 255;
var
i,
nCount : integer;
acFileName : array [0..cnMaxFileNameLen] of char;
begin
// find out how many files we're accepting
nCount := DragQueryFile( msg.WParam,
$FFFFFFFF,
acFileName,
cnMaxFileNameLen );
// query Windows one at a time for the file name
for i := 0 to nCount-1 do
begin
DragQueryFile( msg.WParam, i,
acFileName, cnMaxFileNameLen );
// do your thing with the acFileName
//MessageBox( Handle, acFileName, '', MB_OK );
Edit1.Text := acFileName;
end;
// let Windows know that you're done
DragFinish( msg.WParam );
end;
提前谢谢你。任何线索将不胜感激。
【问题讨论】:
标签: delphi file droppable twebbrowser