首页 > 代码库 > 选择文件或文件夹对话框---带有回调函数

选择文件或文件夹对话框---带有回调函数

QString FileDialogUtils::getSaveFileDir(const QString& tips/* = QString()*/, QWidget* parent/* = 0*/) {    QString result;    BROWSEINFO bi = {0};    if(!tips.isEmpty()) {        bi.lpszTitle = tips.utf16();    }    if(parent) {        bi.hwndOwner = (HWND)parent->winId();    }  //BIF_BROWSEINCLUDEFILES | // 用来显示文件    bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;     bi.lpfn = BrowseCallbackProc; // 回调函数    LPITEMIDLIST pidl = SHBrowseForFolder(&bi);    if (pidl != NULL) {  // else, user canceled        TCHAR szPath[MAX_PATH];        if(SHGetPathFromIDList(pidl, szPath)) {            result = QString::fromUtf16(szPath);        }    }        return result;}INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) {    LPITEMIDLIST tmp = (LPITEMIDLIST)pData;    QString result;    switch(uMsg)     {    case BFFM_INITIALIZED:        //SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szdir);        break;    case BFFM_SELCHANGED:         // Set the status window to the currently selected path.        if (tmp != NULL) {  // else, user canceled            TCHAR szPath[MAX_PATH];            if(SHGetPathFromIDList(tmp, szPath)) {                result = QString::fromUtf16(szPath);            }        }        break;    }    return 0;}

 

选择文件或文件夹对话框---带有回调函数