Dela via


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
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
class CoreWindow final : ICoreWindow
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
class CoreWindow final : ICorePointerRedirector, ICoreWindow
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
public sealed class CoreWindow : ICoreWindow
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
public sealed class CoreWindow : ICorePointerRedirector, ICoreWindow
Public NotInheritable Class CoreWindow
Implements ICoreWindow
Public NotInheritable Class CoreWindow
Implements ICorePointerRedirector, ICoreWindow
Inheritance
Object Platform::Object IInspectable CoreWindow
Attributes
Implements

Windows 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 a Rect value that contains the origin, height, and width of the client area of the window, in device-independent pixels (DIPs).

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 pointer 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

Occurs when a window is closed (or the app terminates altogether).

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

The event that's raised when a non-system key is pressed.

The delegate type for this event is TypedEventHandler<TSender,TResult>, where TSender is of type CoreWindow, and TResult is of type KeyEventArgs.

KeyUp

The event that's raised when a non-system key is released after a press.

The delegate type for this event is TypedEventHandler<TSender,TResult>, where TSender is of type CoreWindow, and TResult is of type KeyEventArgs.

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 input object receiving pointer input when the pointer is redirected to another input object (possibly in a separate process).

PointerRoutedReleased

Occurs on all input objects ever associated with, but not currently receiving input from, a pointer that fires a CoreIndependentInputSource.PointerReleased event on an input object.

PointerRoutedTo

Occurs when captured pointer input previously being delivered to another object, transitions to being delivered to this object.

PointerWheelChanged

The event that's raised when the mouse wheel is rotated.

The delegate type for this event is TypedEventHandler<TSender,TResult>, where TSender is of type CoreWindow, and TResult is of type PointerEventArgs.

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