Ejemplo n.º 1
0
IFACEMETHODIMP CDialogEventHandler::OnTypeChange(IFileDialog *pfd)
{
    IFileSaveDialog *pfsd;
    HRESULT hr = pfd->QueryInterface(&pfsd);
    if (SUCCEEDED(hr)) {
        UINT uIndex;
        hr = pfsd->GetFileTypeIndex(&uIndex);   // index of current file-type
        if (SUCCEEDED(hr)) {

            IFileDialogCustomize* pfdc;
            hr = pfd->QueryInterface(&pfdc);
            if (SUCCEEDED(hr)) {

                switch (uIndex)
                {
                case 1:
                case 5:
                case 6:
                    pfdc->SetControlState(IDS_THUMB_IMAGE_QUALITY, CDCS_INACTIVE);
                    pfdc->SetControlState(IDS_THUMB_QUALITY, CDCS_INACTIVE);
                    pfdc->SetControlState(IDC_EDIT4, CDCS_INACTIVE);

                    pfdc->SetControlState(IDS_THUMB_LEVEL, CDCS_INACTIVE);
                    pfdc->SetControlState(IDC_EDIT5, CDCS_INACTIVE);
                    break;
                case 2:
                case 4:
                    pfdc->SetControlState(IDS_THUMB_IMAGE_QUALITY, CDCS_ENABLEDVISIBLE);
                    pfdc->SetControlState(IDS_THUMB_QUALITY, CDCS_ENABLEDVISIBLE);
                    pfdc->SetControlState(IDC_EDIT4, CDCS_ENABLEDVISIBLE);

                    pfdc->SetControlState(IDS_THUMB_LEVEL, CDCS_INACTIVE);
                    pfdc->SetControlState(IDC_EDIT5, CDCS_INACTIVE);
                    break;
                case 3:
                    pfdc->SetControlState(IDS_THUMB_IMAGE_QUALITY, CDCS_ENABLEDVISIBLE);
                    pfdc->SetControlState(IDS_THUMB_QUALITY, CDCS_INACTIVE);
                    pfdc->SetControlState(IDC_EDIT4, CDCS_INACTIVE);

                    pfdc->SetControlState(IDS_THUMB_LEVEL, CDCS_ENABLEDVISIBLE);
                    pfdc->SetControlState(IDC_EDIT5, CDCS_ENABLEDVISIBLE);
                    break;
                default :
                    break;
                }
                pfdc->Release();
            }
        }
        pfsd->Release();
    }
    return hr;
}
Ejemplo n.º 2
0
void gameOfLife3D::MainWnd::OnSaveFileAs()
{
    IFileSaveDialog* pFileSaveDialog = nullptr;
    HRESULT hr = CoCreateInstance(CLSID_FileSaveDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileSaveDialog));
    if (SUCCEEDED(hr)) {
        hr = pFileSaveDialog->SetFileTypes(NUMBER_OF_DIALOG_FILTERS, DIALOG_FILTERS);
    }
    if (SUCCEEDED(hr)) {
        hr = pFileSaveDialog->Show(m_hwnd);
    }
    IShellItem *pResult = nullptr;
    if (SUCCEEDED(hr)) {
        hr = pFileSaveDialog->GetResult(&pResult);
    }
    WCHAR *pPath = nullptr;
    if (SUCCEEDED(hr)) {
        hr = pResult->GetDisplayName(SIGDN_FILESYSPATH, &pPath);
    }
    UINT fileTypeIndex = 0;
    if (SUCCEEDED(hr)) {
        hr = pFileSaveDialog->GetFileTypeIndex(&fileTypeIndex);
    }
    if (SUCCEEDED(hr)) {
        auto lifeFile = std::make_shared<gameOfLife3D::io::LifeFile>();
        m_canvasPanel->GetLifeFile(lifeFile);

        std::wstring fileName(pPath);
        if (fileTypeIndex == 0) {
            std::wregex rx(L".*\\" L".l3d");
            bool ret = std::regex_match(fileName.begin(), fileName.end(), rx);
            if (!ret) {
                fileName += L".l3d";
            }
            lifeFile->Save(fileName, gameOfLife3D::io::LIFEFILE_FORMAT_LIFE3D100);
        } else {
            std::wregex rx(L".*\\" L".lif");
            bool ret = std::regex_match(fileName.begin(), fileName.end(), rx);
            if (!ret) {
                fileName += L".lif";
            }
            lifeFile->Save(fileName, gameOfLife3D::io::LIFEFILE_FORMAT_LIFE106);
        }
    }
    if (pPath != nullptr) {
        CoTaskMemFree(pPath);
    }
    SafeRelease(&pResult);
    SafeRelease(&pFileSaveDialog);
}