Windows下选择目录对话框

示例代码:

void ChmdwDemoDlg::OnBnClickedBtnSelectPath()

{

    WCHAR buffer[MAX_PATH];

    BROWSEINFO bi;

    WCHAR path[MAX_PATH];

    bi.hwndOwner = NULL;

    bi.pidlRoot = NULL;

    bi.pszDisplayName = buffer; //此参数如为NULL则不能显示对话框

    bi.lpszTitle = TEXT("选择一个目录");

    bi.ulFlags = BIF_RETURNONLYFSDIRS;

    bi.lpfn = NULL;

    bi.iImage = 0;   //初始化入口参数bi结束

    LPITEMIDLIST pIDList = SHBrowseForFolder(&bi);//调用显示选择对话框

    if(pIDList)

    {

        SHGetPathFromIDList(pIDList, path);

        CString strMsg(path);

        //MessageBox(strMsg);

        GetDlgItem(IDC_PATH)->SetWindowText(strMsg);

    }

}

 

你可能感兴趣的:(windows)