「已注销」 2017-08-18 00:59 采纳率: 0%
浏览 710

如下代码中ProcessMsgLoop()的作用是什么呢?FILEMISC.H

bool DeleteFolderContents(LPCTSTR szFolder, BOOL bIncludeSubFolders, LPCTSTR szFileMask, HANDLE hTerminate, BOOL bProcessMsgLoop)
{
// if the dir does not exists just return
DWORD dwAttr = GetFileAttributes(szFolder);

    if (dwAttr == 0xffffffff || !(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
        return false;

    // if a file mask has been specified with subfolders we need to do 2 passes on each folder, 
    // one for the files and one for the sub folders
    int nPasses = (bIncludeSubFolders && (szFileMask && lstrlen(szFileMask))) ? 2 : 1;

    bool bResult = true;
    bool bStopped = (WaitForSingleObject(hTerminate, 0) == WAIT_OBJECT_0);

    for (int nPass = 0; !bStopped && nPass < nPasses; nPass++)
    {
        CString sSearchSpec(szFolder), sMask(szFileMask);

        if (sMask.IsEmpty() || nPass == 1) // (nPass == 1) == 2nd pass (for folders)
            sMask = "*.*";

        TerminatePath(sSearchSpec);
        sSearchSpec += sMask;

        WIN32_FIND_DATA finfo;
        HANDLE hSearch = NULL;

        if ((hSearch = FindFirstFile(sSearchSpec, &finfo)) != INVALID_HANDLE_VALUE)
        {
            do
            {
                if (bProcessMsgLoop)
                **  ProcessMsgLoop();**

                if (finfo.cFileName[0] != '.')
                {
                    CString sItem(szFolder);
                    sItem += "\\";
                    sItem += finfo.cFileName;

                    if (finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                    {
                        if (bIncludeSubFolders && (nPass == 1 || nPasses == 1))
                        {
                            if (DeleteFolderContents(sItem, TRUE, szFileMask, hTerminate, bProcessMsgLoop))
                            {
                                if (!szFileMask || !lstrlen(szFileMask))
                                    bResult = (RemoveDirectory(sItem) == TRUE);
                            }
                        }
                    }
                    else
                        bResult = (DeleteFile(sItem) == TRUE);
                }

                bStopped = (WaitForSingleObject(hTerminate, 0) == WAIT_OBJECT_0);
            } while (!bStopped && bResult && FindNextFile(hSearch, &finfo));

            FindClose(hSearch);
        }
    }

    return (!bStopped && bResult);
}

void ProcessMsgLoop()
{
    MSG msg;

    while (::PeekMessage((LPMSG)&msg, NULL, 0, 0, PM_REMOVE))
    {
        if (IsDialogMessage(msg.hwnd, (LPMSG)&msg))
        {
            // do nothing - its already been done
        }
        else
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
}
  • 写回答

1条回答 默认 最新

  • Coder_Yuan 2017-08-18 05:41
    关注

    ProcessMsgLoop的作用是DeleteFolderContents在界面线程操作的时候预防界面卡死,不过这是不好的风格,违背了函数功能单一原则,也不能很好的
    解决界面卡住,但是开一个线程去操作deletefolder才能彻底解决界面卡死

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable