How to use FileSavePicker with C++/WinRT for desktop app? #1434
-
I want to open a dialog and save files with C++/WinRT for desktop app, here is my code: Windows::Foundation::IAsyncAction click_button(Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e) {
Windows::Storage::Pickers::FileSavePicker savepicker;
savepicker.SuggestedStartLocation(Windows::Storage::Pickers::PickerLocationId::DocumentsLibrary);
auto plainTextExtensions = winrt::single_threaded_vector<winrt::hstring>();
plainTextExtensions.Append(winrt::param::hstring(L".jpg"));
savepicker.FileTypeChoices().Insert(L"jpg", plainTextExtensions);
savepicker.SuggestedFileName(L"new ducument");
co_await winrt::resume_background();
auto file = co_await savepicker.PickSaveFileAsync();
co_await resume_foreground(DispatcherQueue());
} But no dialog showed, and no error occurred. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @ZhouJJJKKK, sorry for the delayed response. In desktop-based apps, you have to use InitializeWithWindow on pickers like FilePicker to let the picker know which window (hwnd) it should display over. auto picker = winrt::Windows::Storage::Pickers::FileOpenPicker();
picker.as<IInitializeWithWindow>()->Initialize(hwnd);
... Here's some more info: https://docs.microsoft.com/windows/apps/desktop/modernize/desktop-to-uwp-supported-api#classes-that-use-iinitializewithwindow |
Beta Was this translation helpful? Give feedback.
Hi @ZhouJJJKKK, sorry for the delayed response. In desktop-based apps, you have to use InitializeWithWindow on pickers like FilePicker to let the picker know which window (hwnd) it should display over.
Here's some more info: https://docs.microsoft.com/windows/apps/desktop/modernize/desktop-to-uwp-supported-api#classes-that-use-iinitializewithwindow