处理多个文件时,COleDropTarget::OnDrop() 中的 return 必须是哪个值?

Which value do I have to return in COleDropTarget::OnDrop() when handling multiple files?

我通过从 COleDropTarget and overriding all necessary functions. Everything works as expected. However, the return value of OnDrop() 派生 class CDropTarget 使我的 MFC 应用程序成为放置目标,这让我很困惑。它的描述是:

Nonzero if the drop is successful; otherwise 0.

如果我的应用程序中有多个文件,我不明白 "successful" 是什么意思。 例如,考虑以下实现:

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 Explorer 或 Total Commander 中删除文件到我的应用程序时, 我根本没有注意到任何差异。 return值有什么作用?

当阅读 MFC 文档让您感到困惑时,您应该转向 Windows SDK 文档,正如您提供的 link 中所推荐的:"For more information, see IDropTarget::Drop in the Windows SDK.":

On return, must contain one of the DROPEFFECT flags, which indicates what the result of the drop operation would be.

请注意,IDropTarget::Drop 更类似于 COleDropTarget::OnDropEx,您应该实施而不是 COleDropTarget::OnDrop。你描述的情况没有严格的规定。但是,DROPEFFECT 应该匹配应用程序行为(即接受或拒绝)。