gpt4 book ai didi

shell - 从 Explorer Shell 拖放到 Virtual TreeView 时如何更改放置提示(Delphi 应用程序)?

转载 作者:行者123 更新时间:2023-12-04 16:16:35 26 4
gpt4 key购买 nike

以下是从 Windows Shell 接受文件到 Virtual TreeView 的方法:How do you drag and drop a file from Explorer Shell into a VirtualTreeView control in a Delphi application?

这是我在 OnDragOver 中为 Effect 参数设置 DROPEFFECT_LINK 时的样子:

DROPEFFECT_LINK in VTV

问题是:是否有可能更改提示文本 说“链接到某物”?

我认为答案与 IDragSourceHelper2::SetFlags(_DROPDESCRIPTION 记录)有关,但我不确定我是否可以使用它以及在哪里使用它。

最佳答案

很快:
将 IDataObject.SetData 与 FormatEtc.cfFormat=RegisterClipboardFormat(CFSTR_DROPDESCRIPTION) 一起使用和 DROPDESCRIPTION 结构作为 TStgMedium 内容。

拖动源应在 IDragSourceHelper.InitializeFromBitmapIDragSourceHelper.InitializeFromWindow 之前调用 IDragSourceHelper2.SetFlags(DSH_ALLOWDROPDESCRIPTIONTEXT)。 VirtualTreeView 在用作拖动源时自动设置此标志。


首先,注册特殊的剪贴板格式。

constructor TForm12.Create(AOwner: TComponent);
begin
inherited;
FDragDescriptionFormat := RegisterClipboardFormat(PChar(CFSTR_DROPDESCRIPTION));
end;

接下来,创建方法来为 IDataObject 设置提示:

procedure TForm12.SetDragHint(DataObject: IDataObject; const Value: string; Effect: Integer);
var
FormatEtc: TFormatEtc;
Medium: TStgMedium;
Data: Pointer;
Descr: DROPDESCRIPTION;
s: WideString;
begin
ZeroMemory(@Descr, SizeOf(DROPDESCRIPTION));
{Do not set Descr.&type to DROPIMAGE_INVALID - this value ignore any custom hint}
{use same image as dropeffect type}
Descr.&type := DROPIMAGE_LABEL;
case Effect of
DROPEFFECT_NONE:
Descr.&type := DROPIMAGE_NONE;
DROPEFFECT_COPY:
Descr.&type := DROPIMAGE_COPY;
DROPEFFECT_MOVE:
Descr.&type := DROPIMAGE_MOVE;
DROPEFFECT_LINK:
Descr.&type := DROPIMAGE_LINK;
end;
{format message for system}
if Length(Value) <= MAX_PATH then
begin
Move(Value[1], Descr.szMessage[0], Length(Value) * SizeOf(WideChar));
Descr.szInsert := '';
end
else
begin
s := Copy(Value, 1, MAX_PATH - 2) + '%1';
Move(s[1], Descr.szMessage[0], Length(s) * SizeOf(WideChar));

s := Copy(Value, MAX_PATH - 1, MAX_PATH);
Move(s[1], Descr.szInsert[0], Length(s) * SizeOf(WideChar));
end;
{prepare structures to set DROPDESCRIPTION data}
FormatEtc.cfFormat := FDragDescriptionFormat; {registered clipboard format}
FormatEtc.ptd := nil;
FormatEtc.dwAspect := DVASPECT_CONTENT;
FormatEtc.lindex := -1;
FormatEtc.tymed := TYMED_HGLOBAL;

ZeroMemory(@Medium, SizeOf(TStgMedium));
Medium.tymed := TYMED_HGLOBAL;
Medium.HGlobal := GlobalAlloc(GHND or GMEM_SHARE, SizeOf(DROPDESCRIPTION));
Data := GlobalLock(Medium.HGlobal);
Move(Descr, Data^, SizeOf(DROPDESCRIPTION));
GlobalUnlock(Medium.HGlobal);

DataObject.SetData(FormatEtc, Medium, True);
end;

最后 - 使用 SetDragHint,例如 - 在 VirtualTreeView.OnDragOver 事件中:

procedure TForm12.vt1DragOver(Sender: TBaseVirtualTree; Source: TObject; Shift: TShiftState; State: TDragState;
Pt: TPoint; Mode: TDropMode; var Effect: Integer; var Accept: Boolean);
begin
Accept := True;
Effect := DROPEFFECT_LINK;
if State = dsDragMove then
begin
SetDragHint(vt1.DragManager.DataObject, Format('Point: (%d, %d)', [Pt.X, Pt.Y]), Effect);
end
else
begin
Accept := False;
Effect := DROPEFFECT_NONE;
SetDragHint(vt1.DragManager.DataObject, '', Effect);
end;
end;

结果(将文件从 Explorer 拖到 VirtualStringTree):

Screenshot

关于shell - 从 Explorer Shell 拖放到 Virtual TreeView 时如何更改放置提示(Delphi 应用程序)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47395267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com