pFD->ScreenToClient(rectText);
pFD->GetDlgItem(stc3)->SetWindowPos(0, rectList2.left, rectCancel.top + 6, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
SetControlText(stc3, _T("Selected:"));
//ComboBox of current file
CRect rectComBo;
pFD->GetDlgItem(cmb13)->GetWindowRect(rectComBo);
pFD->ScreenToClient(rectComBo);
pFD->GetDlgItem(cmb13)->SetWindowPos(0, rectText.left + rectText.Width() - 40, rectCancel.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
//Set OK Button Position
CRect rectOK;
pFD->GetDlgItem(IDOK)->GetWindowRect(rectOK);
pFD->ScreenToClient(rectOK);
pFD->GetDlgItem(IDOK)->SetWindowPos(0, rectCancel.left - rectOK.Width() - 2, rectCancel.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
SetControlText(IDOK, _T("Select"));
pFD->SetWindowText(_T("Choose folder"));
pFD->CenterWindow();
m_wndProc = (WNDPROC)SetWindowLong(pFD->m_hWnd, GWL_WNDPROC, (long)WindowProcNew);
}
//Change the combobox context when select folder.
void CFolderDialog::OnFileNameChange()
{
ChangeFolder();
}
//If the folder contains no sub folder, the OnFileNameChange will not be triggered.
//Add this OnFolderChange to double sure even if there is no sub folder.
void CFolderDialog::OnFolderChange()
{
ChangeFolder();
}
//Change the combobox text to current selected folder
void CFolderDialog::ChangeFolder()
{
TCHAR path[MAX_PATH] = {0};
GetCurrentDirectory(MAX_PATH, path);
SetControlText(cmb13, path);
}
调用:
[cpp]print CString folderPath;
CFolderDialog dlg(&folderPath, this);
if(IDOK == dlg.DoModal())
{
UpdateData(false);
}
CString folderPath;
CFolderDialog dlg(&folderPath, this);
if(IDOK == dlg.DoModal())
{
UpdateData(false);
}
3. 复杂的但是功能比较全的窗口XFolderDialog:
界面:
链接:http://www.codeproject.com/KB/dialog/XFolderDialog.aspx
摘自 w174504744