How to create the main window (UWP/windows-rs)

424 Views Asked by At

I am trying to use the UWP capture api Windows.Graphics.Capture to capture a window. For that I have to use the GraphicsCapturePicker to select a screen/window. But I get the error message:

Error { code: HRESULT(0x8000000E), message: "Could not create a new view because the main window has not yet been created" }

From this it is clear that in have to create the main window, but I don't know how to do that. The code example (C#) given by the windows docs (https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/screen-capture) just does it like this:

CoreWindow window = CoreApplication.MainView.CoreWindow;

await window.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
    await StartCaptureAsync();
});

However I cant find CoreApplication.MainView.CoreWindow anywhere in the windows-rs docs. The code that I currently have looks like this:

use windows;

fn window_dispatch() -> windows::core::Result<()> {
    let picker = windows::Graphics::Capture::GraphicsCapturePicker::new().unwrap();
    picker.PickSingleItemAsync().unwrap().get();
    let return_value: windows::core::Result<()> = Ok(());
    return return_value;
}

fn main() {
    let support = windows::Graphics::Capture::GraphicsCaptureSession::IsSupported().unwrap();
    println!("Support Capture: {}", support);

    let handler = windows::UI::Core::DispatchedHandler::new(window_dispatch);
    let prio =  windows::UI::Core::CoreDispatcherPriority::Normal;
    let window = windows::ApplicationModel::Core::CoreApplication::MainView().unwrap().CoreWindow().unwrap().Dispatch

Does anyone have information on how to create the main window or where this is documented in UWP?

0

There are 0 best solutions below