CString sf_GetComputerDir() { IMalloc *pShellMalloc = NULL; IShellFolder *psfParent; LPITEMIDLIST pidlItem = NULL; LPITEMIDLIST pidlRelative = NULL; STRRET str; WCHAR szDisplayName[MAX_PATH] = L""; WCHAR szPath[MAX_PATH] = L""; HRESULT hres = SHGetMalloc(&pShellMalloc); if (FAILED(hres)) return _T(""); hres = SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &pidlItem); if (SUCCEEDED(hres)) { hres = SHBindToParent(pidlItem, IID_IShellFolder, (void**)&psfParent, (LPCITEMIDLIST*)&pidlRelative); if (SUCCEEDED(hres)) { memset(&str, 0, sizeof(str)); hres = psfParent->GetDisplayNameOf(pidlRelative, SHGDN_NORMAL, &str); if (SUCCEEDED(hres)) StrRetToBuf(&str, pidlItem, szDisplayName, ARRAYSIZE(szDisplayName)); memset(&str, 0, sizeof(str)); hres = psfParent->GetDisplayNameOf(pidlRelative, SHGDN_NORMAL | SHGDN_FORPARSING, &str); if (SUCCEEDED(hres)) StrRetToBuf(&str, pidlItem, szPath, ARRAYSIZE(szPath)); psfParent->Release(); } } if (pidlItem) pShellMalloc->Free(pidlItem); pShellMalloc->Release(); return szPath; } |
CFileDialog dlg(FALSE, _T("rtf"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("*.*|*.*||")); dlg.m_ofn.lpstrInitialDir = sf_GetComputerDir(); if(dlg.DoModal() == IDOK) { m_sPath = dlg.GetPathName(); } |
'C / C++ / Win32 / MFC' 카테고리의 다른 글
Excel 파일을 SQLite로 변환 (0) | 2009.05.20 |
---|---|
미니덤프를 이용하여 디버깅하기 (0) | 2009.04.22 |
IWebBrower의 DocumentComplete 이벤트에서 마지막 호출인지 검사하기 (0) | 2009.04.21 |
비스타에서 Visual Studio 2003의 Find in Files 기능 사용하기 (0) | 2009.04.20 |
왜 C/C++인가? (2) | 2009.04.20 |