static inline HRESULT showFilesPicker(ComPtr<IAsyncOperation<IVectorView<StorageFile*>*> >& AsyncFiles) { ComPtr<IFileOpenPicker> Picker; HRESULT ToReturn; if (FAILED(ToReturn = ActivateInstance(HString::MakeReference(RuntimeClass_Windows_Storage_Pickers_FileOpenPicker).Get(), &Picker)) || !Picker) { qDebug() << "WinRT: unable to initialize picker"; return ToReturn; } if (FAILED(ToReturn = Picker->put_ViewMode(PickerViewMode_Thumbnail))) { qDebug() << "WinRT: Unable to set view mode"; return ToReturn; } if (FAILED(ToReturn = Picker->put_SuggestedStartLocation(PickerLocationId_VideosLibrary))) { qDebug() << "WinRT: Unable to set location"; return ToReturn; } ComPtr<IVector<HSTRING> > FileTypes; if (FAILED(ToReturn = Picker->get_FileTypeFilter(&FileTypes)) || !FileTypes) { qDebug() << "WinRT: Unable to get files filter"; return ToReturn; } if (FAILED(ToReturn = FileTypes->Append(HString::MakeReference(L"*").Get()))) { qDebug() << "WinRT: Unable to append files filter"; return ToReturn; } if (FAILED(ToReturn = Picker->PickMultipleFilesAsync(&AsyncFiles)) || !AsyncFiles) { qDebug() << "WinRT: unable to pick files"; return ToReturn; } return ToReturn; }
void FrameworkView::AddSetting(ISettingsPaneCommandsRequestedEventArgs* aArgs, uint32_t aId, HString& aSettingName) { HRESULT hr; ComPtr<ABI::Windows::UI::ApplicationSettings::ISettingsPaneCommandsRequest> request; AssertHRESULT(aArgs->get_Request(request.GetAddressOf())); // ApplicationCommands - vector that holds SettingsCommand to be invoked ComPtr<IVector<ABI::Windows::UI::ApplicationSettings::SettingsCommand*>> list; AssertHRESULT(request->get_ApplicationCommands(list.GetAddressOf())); ComPtr<IUICommand> command; ComPtr<ISettingsCommandFactory> factory; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_ApplicationSettings_SettingsCommand).Get(), factory.GetAddressOf()); AssertHRESULT(hr); // Create the IInspectable string property that identifies this command ComPtr<IInspectable> prop; ComPtr<IPropertyValueStatics> propStatics; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Foundation_PropertyValue).Get(), propStatics.GetAddressOf()); AssertHRESULT(hr); hr = propStatics->CreateUInt32(aId, prop.GetAddressOf()); AssertHRESULT(hr); // Create the command hr = factory->CreateSettingsCommand(prop.Get(), aSettingName.Get(), Callback<ABI::Windows::UI::Popups::IUICommandInvokedHandler>( this, &FrameworkView::OnSettingsCommandInvoked).Get(), command.GetAddressOf()); AssertHRESULT(hr); // Add it to the list hr = list->Append(command.Get()); AssertHRESULT(hr); }
bool QWinRTMessageDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) { Q_UNUSED(windowFlags) Q_UNUSED(windowModality) Q_UNUSED(parent) Q_D(QWinRTMessageDialogHelper); QSharedPointer<QMessageDialogOptions> options = this->options(); const QString informativeText = options->informativeText(); const QString title = options->windowTitle(); const QString text = informativeText.isEmpty() ? options->text() : (options->text() + QLatin1Char('\n') + informativeText); HRESULT hr; ComPtr<IMessageDialogFactory> dialogFactory; hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_Popups_MessageDialog).Get(), IID_PPV_ARGS(&dialogFactory)); RETURN_FALSE_IF_FAILED("Failed to create dialog factory"); ComPtr<IUICommandFactory> commandFactory; hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_Popups_UICommand).Get(), IID_PPV_ARGS(&commandFactory)); RETURN_FALSE_IF_FAILED("Failed to create command factory"); ComPtr<IMessageDialog> dialog; HStringReference nativeText(reinterpret_cast<LPCWSTR>(text.utf16()), text.size()); if (!title.isEmpty()) { HStringReference nativeTitle(reinterpret_cast<LPCWSTR>(title.utf16()), title.size()); hr = dialogFactory->CreateWithTitle(nativeText.Get(), nativeTitle.Get(), &dialog); RETURN_FALSE_IF_FAILED("Failed to create dialog with title"); } else { hr = dialogFactory->Create(nativeText.Get(), &dialog); RETURN_FALSE_IF_FAILED("Failed to create dialog"); } // Add Buttons ComPtr<IVector<IUICommand *>> dialogCommands; hr = dialog->get_Commands(&dialogCommands); RETURN_FALSE_IF_FAILED("Failed to get dialog commands"); // If no button is specified we need to create one to get close notification int buttons = options->standardButtons(); if (buttons == 0) buttons = Ok; for (int i = FirstButton; i < LastButton; i<<=1) { if (!(buttons & i)) continue; // Add native command const QString label = d->theme->standardButtonText(i); HStringReference nativeLabel(reinterpret_cast<LPCWSTR>(label.utf16()), label.size()); ComPtr<IUICommand> command; hr = commandFactory->Create(nativeLabel.Get(), &command); RETURN_FALSE_IF_FAILED("Failed to create message box command"); ComPtr<IInspectable> id = Make<CommandId>(static_cast<StandardButton>(i)); hr = command->put_Id(id.Get()); RETURN_FALSE_IF_FAILED("Failed to set command ID"); hr = dialogCommands->Append(command.Get()); if (hr == E_BOUNDS) { qErrnoWarning(hr, "The WinRT message dialog supports a maximum of three buttons"); continue; } RETURN_FALSE_IF_FAILED("Failed to append message box command"); if (i == Abort || i == Cancel || i == Close) { quint32 size; hr = dialogCommands->get_Size(&size); RETURN_FALSE_IF_FAILED("Failed to get command list size"); hr = dialog->put_CancelCommandIndex(size - 1); RETURN_FALSE_IF_FAILED("Failed to set cancel index"); } } ComPtr<IAsyncOperation<IUICommand *>> op; hr = dialog->ShowAsync(&op); RETURN_FALSE_IF_FAILED("Failed to show dialog"); hr = op->put_Completed(Callback<DialogCompletedHandler>(this, &QWinRTMessageDialogHelper::onCompleted).Get()); RETURN_FALSE_IF_FAILED("Failed to set dialog callback"); d->shown = true; hr = op.As(&d->info); RETURN_FALSE_IF_FAILED("Failed to acquire AsyncInfo for MessageDialog"); return true; }