CoreWindow CoreWindow CoreWindow CoreWindow Class

Definition

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

public : sealed class CoreWindow : ICorePointerRedirector, ICoreWindow, ICoreWindow2, ICoreWindow3, ICoreWindow4, ICoreWindow5
struct winrt::Windows::UI::Core::CoreWindow : ICorePointerRedirector, ICoreWindow, ICoreWindow2, ICoreWindow3, ICoreWindow4, ICoreWindow5
public sealed class CoreWindow : ICorePointerRedirector, ICoreWindow, ICoreWindow2, ICoreWindow3, ICoreWindow4, ICoreWindow5
Public NotInheritable Class CoreWindow Implements ICorePointerRedirector, ICoreWindow, ICoreWindow2, ICoreWindow3, ICoreWindow4, ICoreWindow5
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.

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

Properties

ActivationMode ActivationMode ActivationMode ActivationMode

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

AutomationHostProvider AutomationHostProvider AutomationHostProvider AutomationHostProvider

Gets the automation provider assigned to this window.

Bounds Bounds Bounds Bounds

Gets the bounding rectangle of the window.

CustomProperties CustomProperties CustomProperties CustomProperties

Gets the set of custom properties for the window.

Dispatcher Dispatcher Dispatcher Dispatcher

Gets the event dispatcher for the window.

DispatcherQueue DispatcherQueue DispatcherQueue DispatcherQueue

Gets the DispatcherQueue for the window.

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

IsInputEnabled IsInputEnabled IsInputEnabled IsInputEnabled

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

PointerCursor PointerCursor PointerCursor PointerCursor

Gets or sets the cursor used by the app.

PointerPosition PointerPosition PointerPosition PointerPosition

Gets the client coordinates of the pointer.

Visible Visible Visible Visible

Gets a value that indicates whether the window is visible.

Methods

Activate() Activate() Activate() Activate()

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

Close() Close() Close() Close()

Closes a secondary window and exits the message loop.

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

Asynchronously retrieves the state of a virtual key.

GetCurrentKeyEventDeviceId() GetCurrentKeyEventDeviceId() GetCurrentKeyEventDeviceId() GetCurrentKeyEventDeviceId()

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

GetCurrentKeyEventDeviceId is not supported for all input devices.

GetForCurrentThread() GetForCurrentThread() GetForCurrentThread() GetForCurrentThread()

Gets the CoreWindow instance for the currently active thread.

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

Retrieves the state of a virtual key.

ReleasePointerCapture() ReleasePointerCapture() ReleasePointerCapture() ReleasePointerCapture()

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

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

Events

Activated Activated Activated Activated

Is fired when the window completes activation or deactivation.

AutomationProviderRequested AutomationProviderRequested AutomationProviderRequested AutomationProviderRequested

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

CharacterReceived CharacterReceived CharacterReceived CharacterReceived

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

Closed Closed Closed Closed

Is fired when the app terminates.

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

InputEnabled InputEnabled InputEnabled InputEnabled

Occurs when input is enabled or disabled for the app.

KeyDown KeyDown KeyDown KeyDown

Is fired when a non-system key is pressed.

KeyUp KeyUp KeyUp KeyUp

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

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

PointerEntered PointerEntered PointerEntered PointerEntered

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

PointerExited PointerExited PointerExited PointerExited

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

PointerMoved PointerMoved PointerMoved PointerMoved

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

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

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

PointerRoutedAway PointerRoutedAway PointerRoutedAway PointerRoutedAway

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

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

PointerRoutedTo PointerRoutedTo PointerRoutedTo PointerRoutedTo

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

PointerWheelChanged PointerWheelChanged PointerWheelChanged PointerWheelChanged

Occurs when the wheel button is rotated.

ResizeCompleted ResizeCompleted ResizeCompleted ResizeCompleted

Occurs when a user finishes resizing the window.

ResizeStarted ResizeStarted ResizeStarted ResizeStarted

Occurs when a user starts to resize the window.

SizeChanged SizeChanged SizeChanged SizeChanged

Occurs when the window size is changed.

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

VisibilityChanged VisibilityChanged VisibilityChanged VisibilityChanged

Is fired when the window visibility is changed.

See Also