处理多个文件时,我必须在 COleDropTarget::OnDrop() 中返回哪个值
Which value do I have to return in COleDropTarget::OnDrop() when handling multiple files?
我通过从COleDropTarget
派生类CDropTarget
并重写所有必要的函数,使我的MFC应用程序成为放置目标。一切都按预期工作。但是,OnDrop(( 的返回值让我感到困惑。其描述如下:
如果删除成功,则为非零;否则为 0。
我不明白如果在我的应用程序上放置多个文件,"成功"是什么意思。例如,请考虑以下实现:
BOOL CDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObj, DROPEFFECT tDropEffect, CPoint tPoint)
{
// I left out declaration/definition of hDrop and path for reasons of clarity.
[...]
UINT numHandledFiles = 0;
// Determine the number of dropped files.
UINT numDroppedFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
// Iterate over all dropped files.
for (UINT n = 0; n < numDroppedFiles; n++)
{
// Get the path of the current file from the HDROP structure.
if (DragQueryFile(hDrop, n, path, PATH_MAX) > 0)
{
// Try to handle each dropped file in my function handleFile().
// It returns true if a file could be handled and false otherwise.
// (The latter happens if a file with the wrong type was dropped.)
if (handleFile(path))
numHandledFiles++;
}
}
return ? // See description below.
}
现在假设我的函数handleFile()
只能处理.png文件并且具有不同文件类型的多个文件一次放在我的应用程序上。
如何正确替换上述代码中的return ?
?我看到两个选项:
return numHandledFiles > 0; // At least one file could be handled.
和:
return numHandledFiles == numDroppedFiles; // All files could be handled.
我尝试了这两种方法,但是当我的应用程序从Windows资源管理器或Total Commander中删除文件时,我根本没有注意到任何区别。返回值有什么影响?
当阅读 MFC 文档让您感到困惑时,您应该按照您提供的链接中的建议转向 Windows SDK 文档:">有关更多信息,请参阅 Windows SDK 中的 IDropTarget::D rop。
返回时,必须包含 DROPEFFECT 标志之一,该标志指示删除操作的结果。
请注意,IDropTarget::Drop
更类似于 COLEDropTarget::OnDropEx,您应该实现它而不是COleDropTarget::OnDrop
。对于您描述的情况没有严格的规则。但是,DROPEFFECT
应与应用程序行为匹配(即接受或拒绝(。
相关文章:
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- 什么时候在C++中返回常量引用是个好主意
- 你能重载对象变量名本身返回的内容吗
- 为什么 Serial.println(<char[]>);返回随机字符?
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 如何获取std::result_of函数的返回类型
- QueryWorkingSet总是返回false
- (C++)分析树以计算返回错误值的简单算术表达式
- 访问者访问变体并返回不同类型时出错
- 如何返回一个类的两个对象相加的结果
- OpenInventor从9.8升级到10.4.2后,GLSL纹理返回零
- lower_bound()返回最后一个元素
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 如何取消对nullptr的屏蔽,返回正确的对象
- 奇怪的结构&GCC&clang(void*返回类型)
- 架构决策:返回std::future还是提供回调
- 从python中调用C++函数并获取返回值
- 矩阵向量乘法(cublasDgemv)返回零
- 处理多个文件时,我必须在 COleDropTarget::OnDrop() 中返回哪个值