Core​Window Core​Window Core​Window Class

Definition

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

public sealed class CoreWindow : ICorePointerRedirector, ICoreWindow, ICoreWindow2, ICoreWindow3, ICoreWindow4public sealed class CoreWindow : ICorePointerRedirector, ICoreWindow, ICoreWindow2, ICoreWindow3, ICoreWindow4Public NotInheritable Class CoreWindow Implements ICorePointerRedirector, ICoreWindow, ICoreWindow2, ICoreWindow3, ICoreWindow4
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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.

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).

Properties

AutomationHostProvider AutomationHostProvider AutomationHostProvider

Gets the automation provider assigned to this window.

public object AutomationHostProvider { get; }public object AutomationHostProvider { get; }Public ReadOnly Property AutomationHostProvider As object
Value
object object object

The automation provider for this window.

Attributes

Bounds Bounds Bounds

Gets the bounding rectangle of the window.

public Rect Bounds { get; }public Rect Bounds { get; }Public ReadOnly Property Bounds As Rect
Value
Rect Rect Rect

The bounding rectangle of the window, in device-independent pixels (DIPs).

Attributes

Remarks

To convert from DIPs to physical pixels (and back), use these equations (where DPI is the dots per inch value for the screen):

  • DIP value = (physical pixel x 96) / DPI
  • physical pixel value = (DIP x DPI) / 96

CustomProperties CustomProperties CustomProperties

Gets the set of custom properties for the window.

public IPropertySet CustomProperties { get; }public IPropertySet CustomProperties { get; }Public ReadOnly Property CustomProperties As IPropertySet
Value
IPropertySet IPropertySet IPropertySet

The set of custom properties for the window, represented as tuples.

Attributes

Dispatcher Dispatcher Dispatcher

Gets the event dispatcher for the window.

public CoreDispatcher Dispatcher { get; }public CoreDispatcher Dispatcher { get; }Public ReadOnly Property Dispatcher As CoreDispatcher
Value
CoreDispatcher CoreDispatcher CoreDispatcher

The event dispatcher for the window.

Attributes

FlowDirection FlowDirection 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.

public CoreWindowFlowDirection FlowDirection { get; set; }public CoreWindowFlowDirection FlowDirection { get; set; }Public ReadWrite Property FlowDirection As CoreWindowFlowDirection
Value
CoreWindowFlowDirection CoreWindowFlowDirection CoreWindowFlowDirection

The flow direction of the window's reading layout.

Attributes

IsInputEnabled IsInputEnabled IsInputEnabled

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

public bool IsInputEnabled { get; set; }public bool IsInputEnabled { get; set; }Public ReadWrite Property IsInputEnabled As bool
Value
bool bool bool

True if input is enabled for the app; false if it is disabled.

Attributes

PointerCursor PointerCursor PointerCursor

Gets or sets the cursor used by the app.

public CoreCursor PointerCursor { get; set; }public CoreCursor PointerCursor { get; set; }Public ReadWrite Property PointerCursor As CoreCursor
Value
CoreCursor CoreCursor CoreCursor

The app's cursor.

Attributes

PointerPosition PointerPosition PointerPosition

Gets the client coordinates of the pointer.

public Point PointerPosition { get; set; }public Point PointerPosition { get; set; }Public ReadWrite Property PointerPosition As Point
Value
Point Point Point

The position of the pointer in device-independent pixel (DIP).

Attributes

Remarks

You cannot read the pointer position with this API when the lock screen is present.

Visible Visible Visible

Gets a value that indicates whether the window is visible.

public bool Visible { get; }public bool Visible { get; }Public ReadOnly Property Visible As bool
Value
bool bool bool

True if the window is visible on the screen; false if it is not.

Attributes

Methods

Activate() Activate() Activate()

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

public void Activate()public void Activate()Public Function Activate() As void
Attributes

Remarks

The window is presented if the app is the foreground window. If the app has more than one window, the activating window is presented when the app is set to the foreground.

Close() Close() Close()

Closes a secondary window and exits the message loop.

public void Close()public void Close()Public Function Close() As void
Attributes

Remarks

This method also causes the ProcessEvents operation to exit the event-processing loop.

GetAsyncKeyState(VirtualKey) GetAsyncKeyState(VirtualKey) GetAsyncKeyState(VirtualKey)

Asynchronously retrieves the state of a virtual key.

public CoreVirtualKeyStates GetAsyncKeyState(VirtualKey virtualKey)public CoreVirtualKeyStates GetAsyncKeyState(VirtualKey virtualKey)Public Function GetAsyncKeyState(virtualKey As VirtualKey) As CoreVirtualKeyStates
Parameters
virtualKey
VirtualKey VirtualKey VirtualKey

The virtual key for which state is returned.

Returns

The flags indicating the current state of the supplied virtual key when the input event fired.

Note

All keys support the Locked state (not just the standard Caps Lock and Num Lock keys).

Attributes

GetCurrentKeyEventDeviceId() GetCurrentKeyEventDeviceId() GetCurrentKeyEventDeviceId()

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

GetCurrentKeyEventDeviceId is not supported for all input devices.

public string GetCurrentKeyEventDeviceId()public string GetCurrentKeyEventDeviceId()Public Function GetCurrentKeyEventDeviceId() As string
Returns
string string string

A unique identifier for the input device associated with the key event, or an empty string. The same device can be assigned a different ID each time it is connected.

After a key event is processed, this method returns an empty string.

Attributes

Remarks

Use GetCurrentKeyEventDeviceId to differentiate between devices that can generate key events, such as multiple Xbox controllers. The device id is useful for associating the input device with a specific user account.

To get a valid device ID, this method must be called from your KeyUp and KeyDown event handlers.

GetForCurrentThread() GetForCurrentThread() GetForCurrentThread()

Gets the CoreWindow instance for the currently active thread.

public static CoreWindow GetForCurrentThread()public static CoreWindow GetForCurrentThread()Public Static Function GetForCurrentThread() As CoreWindow
Returns

The CoreWindow for the currently active thread.

Attributes

GetKeyState(VirtualKey) GetKeyState(VirtualKey) GetKeyState(VirtualKey)

Retrieves the state of a virtual key.

public CoreVirtualKeyStates GetKeyState(VirtualKey virtualKey)public CoreVirtualKeyStates GetKeyState(VirtualKey virtualKey)Public Function GetKeyState(virtualKey As VirtualKey) As CoreVirtualKeyStates
Parameters
virtualKey
VirtualKey VirtualKey VirtualKey

The virtual key for which state is returned.

Returns

The flags indicating the current state of the supplied virtual key when the input event fired.

Note

All keys support the Locked state (not just the standard Caps Lock and Num Lock keys).

Attributes

ReleasePointerCapture() ReleasePointerCapture() ReleasePointerCapture()

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

public void ReleasePointerCapture()public void ReleasePointerCapture()Public Function ReleasePointerCapture() As void
Attributes

SetPointerCapture() SetPointerCapture() SetPointerCapture()

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

public void SetPointerCapture()public void SetPointerCapture()Public Function SetPointerCapture() As void
Attributes

Remarks

A pointer can be captured only by a single app at any time. Only the foreground window can capture the pointer. Pointer events continue even if the pointer moves outside the bounds of the app.

A pointer can only be captured when contact is detected (mouse button pressed, touch contact down, stylus in contact), and the pointer is within the bounding rectangle of the app.

The pointer is released on a PointerReleased or a PointerCaptureLost event, or ReleasePointerCapture is explicitly called.

Events

Activated Activated Activated

Is fired when the window completes activation or deactivation.

public event TypedEventHandler Activatedpublic event TypedEventHandler ActivatedPublic Event Activated
Attributes

AutomationProviderRequested AutomationProviderRequested AutomationProviderRequested

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

public event TypedEventHandler AutomationProviderRequestedpublic event TypedEventHandler AutomationProviderRequestedPublic Event AutomationProviderRequested
Attributes

CharacterReceived CharacterReceived CharacterReceived

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

public event TypedEventHandler CharacterReceivedpublic event TypedEventHandler CharacterReceivedPublic Event CharacterReceived
Attributes

Remarks

Apps do not receive this event when an Input Method Editor (IME) is enabled. The Input Method Editor (IME) handles all keyboard input and sets Handled to true.

Closed Closed Closed

Is fired when the app terminates.

public event TypedEventHandler Closedpublic event TypedEventHandler ClosedPublic Event Closed
Attributes

Remarks

Note

Apps are typically suspended, not terminated. As a result, this event is rarely fired, if ever.

ClosestInteractiveBoundsRequested ClosestInteractiveBoundsRequested 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.

public event TypedEventHandler ClosestInteractiveBoundsRequestedpublic event TypedEventHandler ClosestInteractiveBoundsRequestedPublic Event ClosestInteractiveBoundsRequested
Attributes

InputEnabled InputEnabled InputEnabled

Occurs when input is enabled or disabled for the app.

public event TypedEventHandler InputEnabledpublic event TypedEventHandler InputEnabledPublic Event InputEnabled
Attributes

KeyDown KeyDown KeyDown

Is fired when a non-system key is pressed.

public event TypedEventHandler KeyDownpublic event TypedEventHandler KeyDownPublic Event KeyDown
Attributes

Remarks

Apps do not receive this event when an Input Method Editor (IME) is enabled. The Input Method Editor (IME) handles all keyboard input and sets Handled to true.

KeyUp KeyUp KeyUp

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

public event TypedEventHandler KeyUppublic event TypedEventHandler KeyUpPublic Event KeyUp
Attributes

Remarks

Apps do not receive this event when an IME is enabled. The Input Method Editor (IME) handles all keyboard input and sets Handled to true.

PointerCaptureLost PointerCaptureLost 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.

public event TypedEventHandler PointerCaptureLostpublic event TypedEventHandler PointerCaptureLostPublic Event PointerCaptureLost
Attributes
See Also

PointerEntered PointerEntered PointerEntered

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

public event TypedEventHandler PointerEnteredpublic event TypedEventHandler PointerEnteredPublic Event PointerEntered
Attributes

Remarks

For touch input, the app receives this event before a PointerPressed event.

See Also

PointerExited PointerExited PointerExited

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

public event TypedEventHandler PointerExitedpublic event TypedEventHandler PointerExitedPublic Event PointerExited
Attributes

Remarks

For touch input, the app receives this event before a PointerReleased event.

See Also

PointerMoved PointerMoved PointerMoved

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

public event TypedEventHandler PointerMovedpublic event TypedEventHandler PointerMovedPublic Event PointerMoved
Attributes
See Also

PointerPressed PointerPressed 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).

public event TypedEventHandler PointerPressedpublic event TypedEventHandler PointerPressedPublic Event PointerPressed
Attributes
See Also

PointerReleased PointerReleased 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).

public event TypedEventHandler PointerReleasedpublic event TypedEventHandler PointerReleasedPublic Event PointerReleased
Attributes

Remarks

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 each contact detected in the interaction session (except for mouse, where this event is fired only when the last mouse button is released).

See Also

PointerRoutedAway PointerRoutedAway PointerRoutedAway

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

public event TypedEventHandler PointerRoutedAwaypublic event TypedEventHandler PointerRoutedAwayPublic Event PointerRoutedAway
Attributes

Remarks

This event is not fired on a PointerReleased event.

See Also

PointerRoutedReleased PointerRoutedReleased PointerRoutedReleased

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

public event TypedEventHandler PointerRoutedReleasedpublic event TypedEventHandler PointerRoutedReleasedPublic Event PointerRoutedReleased
Attributes
See Also

PointerRoutedTo PointerRoutedTo PointerRoutedTo

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

public event TypedEventHandler PointerRoutedTopublic event TypedEventHandler PointerRoutedToPublic Event PointerRoutedTo
Attributes

Remarks

This event is not fired on a PointerPressed event.

See Also

PointerWheelChanged PointerWheelChanged PointerWheelChanged

Occurs when the wheel button is rotated.

public event TypedEventHandler PointerWheelChangedpublic event TypedEventHandler PointerWheelChangedPublic Event PointerWheelChanged
Attributes
See Also

ResizeCompleted ResizeCompleted ResizeCompleted

Occurs when a user finishes resizing the window.

public event TypedEventHandler ResizeCompletedpublic event TypedEventHandler ResizeCompletedPublic Event ResizeCompleted
Attributes

ResizeStarted ResizeStarted ResizeStarted

Occurs when a user starts to resize the window.

public event TypedEventHandler ResizeStartedpublic event TypedEventHandler ResizeStartedPublic Event ResizeStarted
Attributes

SizeChanged SizeChanged SizeChanged

Occurs when the window size is changed.

public event TypedEventHandler SizeChangedpublic event TypedEventHandler SizeChangedPublic Event SizeChanged
Attributes

Remarks

The SizeChanged event is exposed to XAML apps as the Window.SizeChanged event and to HTML apps as the window.resize event.

This event occurs when the window size changes or when one of the following properties changes:

TouchHitTesting TouchHitTesting TouchHitTesting

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

public event TypedEventHandler TouchHitTestingpublic event TypedEventHandler TouchHitTestingPublic Event TouchHitTesting
Attributes

VisibilityChanged VisibilityChanged VisibilityChanged

Is fired when the window visibility is changed.

public event TypedEventHandler VisibilityChangedpublic event TypedEventHandler VisibilityChangedPublic Event VisibilityChanged
Attributes

See Also