| 70 | } |
| 71 | |
| 72 | std::optional<std::wstring> browse_for_directory(HWND parent_wnd, const wchar_t *initial_path) { |
| 73 | // Thanks to http://vcfaq.mvps.org/sdk/20.htm |
| 74 | BROWSEINFO bi; |
| 75 | memset(&bi, 0, sizeof(bi)); |
| 76 | std::vector<wchar_t> path; |
| 77 | |
| 78 | LPITEMIDLIST pidl_root = nullptr; |
| 79 | SHGetFolderLocation(parent_wnd, 0, nullptr, NULL, &pidl_root); |
| 80 | |
| 81 | auto title = rc_str(IDS_PICK_A_DIRECTORY); |
| 82 | bi.pidlRoot = pidl_root; |
| 83 | bi.lpszTitle = title.c_str(); |
| 84 | bi.pszDisplayName = path.data(); |
| 85 | bi.ulFlags = BIF_RETURNONLYFSDIRS; |
| 86 | bi.lpfn = browse_callback_proc; |
| 87 | bi.lParam = reinterpret_cast<LPARAM>(initial_path); |
| 88 | LPITEMIDLIST pidl = SHBrowseForFolder(&bi); |
| 89 | std::optional<std::wstring> ret; |
| 90 | if (pidl != nullptr) { |
| 91 | // get the name of the folder |
| 92 | std::vector<wchar_t> sz_path(MAX_PATH); |
| 93 | if (SHGetPathFromIDList(pidl, sz_path.data())) |
| 94 | ret = sz_path.data(); |
| 95 | CoTaskMemFree(pidl); |
| 96 | // free memory used |
| 97 | |
| 98 | CoUninitialize(); |
| 99 | } |
| 100 | return ret; |
| 101 | } |
| 102 | |
| 103 | HWND create_tooltip(int tool_id, HWND h_dlg, const wchar_t *psz_text) { |
| 104 | if (tool_id == 0 || h_dlg == nullptr || psz_text == nullptr) { |
no test coverage detected