Created
January 8, 2017 15:48
-
-
Save nibasya/bfbc99d6b26024ca291f41e586f96900 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CChangeFileNameGUIDlg::GetDirName(CEdit* pEdit) | |
{ | |
IFileDialog *pDialog=NULL; | |
HRESULT hr; | |
DWORD options; | |
// インスタンス生成 | |
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDialog)); | |
if (FAILED(hr)) | |
return; | |
// 設定の初期化 | |
pDialog->GetOptions(&options); | |
pDialog->SetOptions(options | FOS_PICKFOLDERS); | |
// フォルダ選択ダイアログを表示 | |
hr = pDialog->Show(NULL); | |
// 結果取得 | |
if (SUCCEEDED(hr)) { | |
IShellItem *pItem = NULL; | |
PWSTR pPath = NULL; | |
hr = pDialog->GetResult(&pItem); | |
if (SUCCEEDED(hr)) { | |
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pPath); | |
if (SUCCEEDED(hr)) { | |
// pPathを用いて所定の処理をする | |
pEdit->SetWindowText(pPath); | |
pEdit->SetSel(0, -1, FALSE); | |
// pPathのメモリを開放する | |
CoTaskMemFree(pPath); | |
} | |
} | |
} | |
// ダイアログインスタンスの開放 | |
pDialog->Release(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment