当前位置: 首页>>代码示例>>C++>>正文


C++ ComPtr::Show方法代码示例

本文整理汇总了C++中microsoft::wrl::ComPtr::Show方法的典型用法代码示例。如果您正苦于以下问题:C++ ComPtr::Show方法的具体用法?C++ ComPtr::Show怎么用?C++ ComPtr::Show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在microsoft::wrl::ComPtr的用法示例。


在下文中一共展示了ComPtr::Show方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SaveCrashDump

/**
 * This method handles the actual details of saving an assertion report. It will
 * bring up the "File save as..." dialog and then write the report out to
 * whichever file the user selects
 *
 * \return  True if the user saved the file, false if they aborted the action
 */
bool AssertionDialog::SaveCrashDump() const
{
    bool didSaveFile = false;

    // Create the file save as dialog
    Microsoft::WRL::ComPtr<IFileDialog> fileDialog;
    HRESULT hr = CoCreateInstance(CLSID_FileSaveDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&fileDialog));

    if (!SUCCEEDED(hr))
    {
        return false;
    }

    // File types supported
    COMDLG_FILTERSPEC filters[] = { { L"Text Files", L"*.txt" } };

    // Configure the save dialog with useful defaults
    fileDialog->SetTitle(L"Save crash dump to a file");
    fileDialog->SetFileTypes(ARRAYSIZE(filters), filters);
    fileDialog->SetDefaultExtension(L"*.txt");
    fileDialog->SetFileName(L"crash details.txt");

    // Show the file save as dialog
    fileDialog->Show(mWindowHandle);

    // Find the name of the file they want to save the assertion report to.
    // If the user didn't give an appropriate response, simply leave the filename
    // to be null
    Microsoft::WRL::ComPtr<IShellItem> dialogResult;
    PWSTR filepath = nullptr;

    hr = fileDialog->GetResult(&dialogResult);

    if (SUCCEEDED(hr))
    {
        HRESULT hr = dialogResult->GetDisplayName(SIGDN_FILESYSPATH, &filepath);

        if (SUCCEEDED(hr))
        {
            std::string fileContents = Utils::ConvertWideStringToUtf8(GetFileReportString());

            // First we have to create the file
            HANDLE fileHandle = CreateFile(
                filepath,
                GENERIC_WRITE,
                0,
                nullptr,
                CREATE_ALWAYS,
                FILE_ATTRIBUTE_NORMAL,
                nullptr);

            // Convert the text file to UTF8 and then write the string to disk.
            WriteFile(
                fileHandle,
                fileContents.c_str(),
                static_cast<DWORD>(fileContents.size()),
                nullptr,
                nullptr);

            // Remember that we wrote the file out
            didSaveFile = true;
        }
    }

    // Now clean up. Release the dialog window and close the file stream.
    CoTaskMemFree(filepath);
    return didSaveFile;
}
开发者ID:smacdo,项目名称:Hailstorm,代码行数:75,代码来源:assertiondialog.cpp


注:本文中的microsoft::wrl::ComPtr::Show方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。