本文整理汇总了C++中IFileOpenDialog::SetDefaultExtension方法的典型用法代码示例。如果您正苦于以下问题:C++ IFileOpenDialog::SetDefaultExtension方法的具体用法?C++ IFileOpenDialog::SetDefaultExtension怎么用?C++ IFileOpenDialog::SetDefaultExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileOpenDialog
的用法示例。
在下文中一共展示了IFileOpenDialog::SetDefaultExtension方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: select_file
const bool Core::select_file() {
//Open file dialog, straight from https://msdn.microsoft.com/en-us/library/windows/desktop/ff485843(v=vs.85).aspx
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
PWSTR pszFilePath = nullptr;
if (SUCCEEDED(hr)) {
IFileOpenDialog *pFileOpen;
// Create the FileOpenDialog object.
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
if (SUCCEEDED(hr)) {
//Boilerplate for only showing *.nes files in the dialog. See the MSDN docs more info.
COMDLG_FILTERSPEC fileFilter;
fileFilter.pszName = L"iNES";
fileFilter.pszSpec = L"*.nes";
pFileOpen->SetFileTypes(1, &fileFilter);
pFileOpen->SetFileTypeIndex(1);
pFileOpen->SetDefaultExtension(L"nes");
// Show the Open dialog box.
hr = pFileOpen->Show(NULL);
// Get the file name from the dialog box.
if (SUCCEEDED(hr)) {
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr)) {
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
if (SUCCEEDED(hr)) {
logmsg("Opening file");
} else {
pszFilePath = nullptr;
}
pItem->Release();
}
}
pFileOpen->Release();
}
CoUninitialize();
}
if (pszFilePath == nullptr) {
alert_error("Unable to open file! File must have the extension \".nes\"");
return false;
}
//Convert wchar_t string to char string
std::size_t i;
wcstombs_s(&i, fileSelection, pszFilePath, MAX_PATH);
return true;
}
示例2: LoadMap
void EditorScreen::LoadMap()
{
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
{
IFileOpenDialog *pFileOpen = NULL;
HRESULT hr = CoCreateInstance(__uuidof(FileOpenDialog), NULL,
CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileOpen));
if (SUCCEEDED(hr))
{
hr = pFileOpen->SetDefaultExtension(L"xml");
hr = pFileOpen->SetFileTypes(ARRAYSIZE(c_rgSaveTypes), c_rgSaveTypes);
hr = pFileOpen->Show(NULL);
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr))
{
PWSTR pszFilePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
// Display the file name to the user.
if (SUCCEEDED(hr))
{
// Reset current Map information
ResetMap();
std::string filePath = utf8_encode(pszFilePath);
map->LoadMap(filePath);
CoTaskMemFree(pszFilePath);
}
pItem->Release();
}
}
pFileOpen->Release();
}
CoUninitialize();
}
}