CoreWindow Class

Definition

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

public ref class CoreWindow sealed : ICoreWindow
public ref class CoreWindow sealed : ICorePointerRedirector, ICoreWindow
class CoreWindow sealed : ICoreWindow
class CoreWindow sealed : ICorePointerRedirector, ICoreWindow
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Muse(Version=100794368)]
[Windows.Foundation.Metadata.Static(typeof(Windows.UI.Core.ICoreWindowStatic), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.WebHostHidden]
public sealed class CoreWindow : ICoreWindow
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Muse(Version=100794368)]
[Windows.Foundation.Metadata.WebHostHidden]
[Windows.Foundation.Metadata.Static(typeof(Windows.UI.Core.ICoreWindowStatic), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class CoreWindow : ICorePointerRedirector, ICoreWindow
Public NotInheritable Class CoreWindow
Implements ICoreWindow
Public NotInheritable Class CoreWindow
Implements ICorePointerRedirector, ICoreWindow
Inheritance
CoreWindow
Attributes
Implements
<xref href="Windows.UI.Core.ICorePointerRedirector?alt=Windows.UI.Core.ICorePointerRedirector&text=ICorePointerRedirector" data-throw-if-not-resolved="True"/> <xref href="Windows.UI.Core.ICoreWindow?alt=Windows.UI.Core.ICoreWindow&text=ICoreWindow" data-throw-if-not-resolved="True"/>

Windows 10 requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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 version SDK version Value added
1511 10586 PointerRoutedAway
1511 10586 PointerRoutedReleased
1511 10586 PointerRoutedTo
1607 14393 ClosestInteractiveBoundsRequested
1607 14393 GetCurrentKeyEventDeviceId
1703 15063 ResizeCompleted
1703 15063 ResizeStarted
1709 16299 ActivationMode
1709 16299 DispatcherQueue
1903 18362 UIContext

Properties

ActivationMode

Gets a value that indicates the activation state of the window.

AutomationHostProvider

Gets the automation provider assigned to this window.

Bounds

Gets the bounding rectangle of the window.

CustomProperties

Gets the set of custom properties for the window.

Dispatcher

Gets the event dispatcher for the window.

DispatcherQueue

Gets the DispatcherQueue for the window.

FlowDirection

Gets or sets the horizontal origin of the window's reading order alignment. If the language specified by the user interface is right-aligned (such as in Arabic or Hebrew), the horizontal origin of the reading layout for the window is on the right edge.

IsInputEnabled

Gets or sets a value that indicates whether input is enabled for the app.

PointerCursor

Gets or sets the cursor used by the app.

PointerPosition

Gets the client coordinates of the pointer.

UIContext

Gets the context identifier for the core window.

Visible

Gets a value that indicates whether the window is visible.

Methods

Activate()

Activates the window. This method is called to present the window on the screen.

Close()

Closes a secondary window and exits the message loop.

GetAsyncKeyState(VirtualKey)

Asynchronously retrieves the state of a virtual key.

GetCurrentKeyEventDeviceId()

Retrieves the unique ID for the input device that generated this key event.

GetCurrentKeyEventDeviceId is not supported for all input devices.

GetForCurrentThread()

Gets the CoreWindow instance for the currently active thread.

GetKeyState(VirtualKey)

Retrieves the state of a virtual key.

ReleasePointerCapture()

Dissociates pointer input from the app, if previously associated through SetPointerCapture, and restores normal pointer input processing.

SetPointerCapture()

Associates pointer input with the app. Once a pointer is captured, all subsequent events associated with that pointer are fired by the app.

Events

Activated

Is fired when the window completes activation or deactivation.

AutomationProviderRequested

Is fired when a request for an automation handler is generated.

CharacterReceived

Is fired when a new character is received by the input queue.

Closed

Is fired when the app terminates.

ClosestInteractiveBoundsRequested

Note

Not intended for general use.

Occurs when a framework input manager requests the bounding rectangle of an interactive element within a specific bounding rectangle and closest to a specific pointer.

InputEnabled

Occurs when input is enabled or disabled for the app.

KeyDown

Is fired when a non-system key is pressed.

KeyUp

Is fired when a non-system key is released after a press.

PointerCaptureLost

Occurs when a pointer moves to another app. This event is raised after PointerExited and is the final event received by the app for this pointer.

PointerEntered

Occurs when a pointer moves into the bounding box of the app.

PointerExited

Occurs when the pointer moves outside the bounding box of the app.

PointerMoved

Occurs when a pointer moves within the bounding box of the app.

PointerPressed

Occurs when a mouse button is clicked, or the digitizer surface has been touched by a finger or pen, within the bounding rectangle of the app.

An interaction session starts when a single contact is detected and ends when that contact, and all subsequent contacts in the same session, are no longer detected.

This event is fired for the first contact detected in the interaction session. Details for all other concurrent contact pointers are exposed through a PointerPointProperties object (obtained by getting the Properties property from a PointerPoint object).

PointerReleased

Occurs when a pressed mouse button is released, or a touch or pen contact is lifted from the digitizer surface, within the bounding rectangle of the app (or outside the bounding rectangle, if the pointer is captured).

PointerRoutedAway

Occurs on the process receiving input when the pointer input is routed to another process.

PointerRoutedReleased

Occurs on a process associated with, but not currently receiving input from, a pointer that fires a PointerReleased event on a different process.

PointerRoutedTo

Occurs on the process not currently receiving input, but designated to begin receiving input from another process.

PointerWheelChanged

Occurs when the wheel button is rotated.

ResizeCompleted

Occurs when a user finishes resizing the window.

ResizeStarted

Occurs when a user starts to resize the window.

SizeChanged

Occurs when the window size is changed.

TouchHitTesting

Occurs when a touch contact area intersects the bounding rectangle (or polygon) of a window that is registered for touch hit testing.

VisibilityChanged

Is fired when the window visibility is changed.

Applies to

See also