本文介绍了如何检查是否已从剪贴板成功获取文件名列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚找到了这段代码,可以从剪贴板中获取文件,并且可以正常工作,但是我想将其设置为布尔函数,这样我就知道它成功了。我需要测试什么才能查看剪贴板上是否有文件并且一切正常?
I have just found this code to get files from the clipboard and it works fine, but I would like to make it a Boolean function so that I know it succeeded. What do I need to test to see if it has the file(s) on the clipboard and that all is OK?
USES Clipbrd, shellapi;
// procedure GetFileNameFromClipboard(oSL : TStringlist);
function GetFileNameFromClipboard(oSL : TStringlist) : Boolean;
var
f: THandle;
buffer: array [0..MAX_PATH] of Char;
i, c: Integer;
begin
Result:=False;
if NOT Clipboard.HasFormat(CF_HDROP) then exit;
Clipboard.Open;
f := Clipboard.GetAsHandle(CF_HDROP);
if f <> 0 then
begin
c := DragQueryFile(f, $FFFFFFFF, nil, 0);
for i:=0 to c-1 do
begin
buffer[0] := #0;
DragQueryFile(f, i, buffer, SizeOf(buffer));
oSL.Add(buffer);
end;
end;
Clipboard.Close;
Result:=???????
end;
推荐答案
尝试如下操作:
function GetFileNameFromClipboard(oSL : TStrings) : Boolean;
var
f: THandle;
buffer: array [0..MAX_PATH] of Char;
S: string;
i, c: UINT;
begin
Result := False;
Clipboard.Open;
try
f := Clipboard.GetAsHandle(CF_HDROP);
if f = 0 then Exit;
c := DragQueryFile(f, $FFFFFFFF, nil, 0);
if c = 0 then Exit;
for i := 0 to c-1 do
begin
c := DragQueryFile(f, i, buffer, Length(buffer));
if c <> 0 then begin
SetString(s, buffer, c);
oSL.Add(s);
Result := True;
end;
end;
finally
Clipboard.Close;
end;
end;
这篇关于如何检查是否已从剪贴板成功获取文件名列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!