Windows.UI.Core.CoreWindow

September 2, 2020 ยท View on GitHub

-description

Represents the UWP app with input events and basic user interface behaviors.

-remarks

New instances of this class are obtained by calling CoreApplication.CreateNewView and then inspecting the CoreWindow property on the returned CoreApplicationView instance. Or you can obtain existing CoreWindow instances for a running app from the CoreApplication.Views property, or by calling CoreWindow.GetForCurrentThread, as seen in the following example.

// App.cpp
...
// An implementation of IFrameworkView::Run.
void Run()
{
    CoreWindow window{ CoreWindow::GetForCurrentThread() };
    window.Activate();

    CoreDispatcher dispatcher{ window.Dispatcher() };
    dispatcher.ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
}

// The CoreApplication::Run call indirectly calls the App::Run function above.
int __stdcall wWinMain(HINSTANCE, HINSTANCE, PWSTR, int)
{
    CoreApplication::Run(App());
}
void MyCoreWindowEvents::Run() // this is an implementation of IFrameworkView::Run() used to show context
{
    CoreWindow::GetForCurrentThread()->Activate();

    /...

    CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
}

Note

This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX).

Version history

Windows versionSDK versionValue added
151110586PointerRoutedAway
151110586PointerRoutedReleased
151110586PointerRoutedTo
160714393ClosestInteractiveBoundsRequested
160714393GetCurrentKeyEventDeviceId
170315063ResizeCompleted
170315063ResizeStarted
170916299ActivationMode
170916299DispatcherQueue
190318362UIContext

-examples

-see-also

CoreApplicationView, CoreApplication.CreateNewView, CoreApplication.Views, Direct2D custom image effects sample (Windows 10)