CoreWindow 類別

定義

表示具有輸入事件和基本使用者介面行為的 UWP 應用程式。

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
繼承
Object Platform::Object IInspectable CoreWindow
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

備註

呼叫CoreApplication.CreateNewView,然後檢查傳回CoreApplicationView實例上的CoreWindow屬性,即可取得這個類別的新實例。 或者,您可以從 CoreApplication.Views 屬性,或是呼叫 CoreWindow.GetForCurrentThread,取得執行中應用程式的現有 CoreWindow 實例,如下列範例所示。

// 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);
}

注意

這個類別不是敏捷的,這表示您必須考慮其執行緒模型和封送處理行為。 如需詳細資訊,請參閱 執行緒和封送處理 (C++/CX)

版本歷程記錄

Windows 版本 SDK 版本 新增值
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

屬性

ActivationMode

取得值,這個值表示視窗的啟用狀態。

AutomationHostProvider

取得指派給這個視窗的自動化提供者。

Bounds

取得 Rect 值,其中包含視窗工作區的原點、高度和寬度,以裝置無關的圖元 (DIP) 。

CustomProperties

取得視窗的自訂屬性集。

Dispatcher

取得視窗的事件發送器。

DispatcherQueue

取得視窗的 DispatcherQueue

FlowDirection

取得或設定視窗讀取順序對齊的水準原點。 如果使用者介面所指定的語言靠右對齊 (,例如阿拉伯文或希伯來文) ,則視窗的閱讀版面配置水準原點位於右邊緣。

IsInputEnabled

取得或設定值,這個值表示是否為應用程式啟用輸入。

PointerCursor

取得或設定應用程式所使用的指標資料指標。

PointerPosition

取得指標的用戶端座標。

UIContext

取得核心視窗的內容識別碼。

Visible

取得值,這個值表示視窗是否可見。

方法

Activate()

啟用視窗。 呼叫這個方法可呈現螢幕上的視窗。

Close()

關閉次要視窗並結束訊息迴圈。

GetAsyncKeyState(VirtualKey)

以非同步方式擷取虛擬金鑰的狀態。

GetCurrentKeyEventDeviceId()

擷取產生此金鑰事件之輸入裝置的唯一識別碼。

所有輸入裝置都不支援 GetCurrentKeyEventDeviceId。

GetForCurrentThread()

取得目前使用中線程的 CoreWindow 實例。

GetKeyState(VirtualKey)

擷取虛擬金鑰的狀態。

ReleasePointerCapture()

如果先前透過 SetPointerCapture相關聯,則會將指標輸入與應用程式解除關聯,並還原一般指標輸入處理。

SetPointerCapture()

將指標輸入與應用程式產生關聯。 擷取指標之後,與該指標相關聯的所有後續事件都會由應用程式引發。

事件

Activated

當視窗完成啟用或停用時,就會引發 。

AutomationProviderRequested

在產生自動化處理常式的要求時引發。

CharacterReceived

當輸入佇列收到新字元時,就會引發 。

Closed

當視窗關閉 (或應用程式完全終止) 時發生。

ClosestInteractiveBoundsRequested

注意

不適用於一般用途。

當架構輸入管理員要求特定周框內互動式元素的周框,且最接近特定指標時發生。

InputEnabled

發生于為應用程式啟用或停用輸入時。

KeyDown

按下非系統按鍵時所引發的事件。

此事件的委派類型為TypedEventHandler < TSender,TResult >,其中TSender的類型為CoreWindow而 TResult的類型為KeyEventArgs

KeyUp

按下後放開非系統按鍵時所引發的事件。

此事件的委派類型為TypedEventHandler < TSender,TResult >,其中TSender的類型為CoreWindow而 TResult的類型為KeyEventArgs

PointerCaptureLost

當指標移至另一個應用程式時發生。 此事件會在 PointerExited 之後引發,而且是應用程式針對此指標接收的最終事件。

PointerEntered

當指標移至應用程式的周框方塊時發生。

PointerExited

發生于指標在應用程式周框方塊外移動時。

PointerMoved

發生于指標在應用程式的周框方塊內移動時。

PointerPressed

發生于按一下滑鼠按鍵,或在應用程式周框內的手指或手寫筆觸碰數位板表面時。

當偵測到單一連絡人,並在該連絡人和相同會話中的所有後續連絡人都不再偵測到時,就會開始互動會話。

針對在互動會話中偵測到的第一個連絡人,會引發此事件。 所有其他並行連絡人指標的詳細資料都會透過PointerPointProperties物件公開, (透過從PointerPoint物件取得Properties屬性) 取得。

PointerReleased

發生于按下的滑鼠按鍵放開時,如果指標) 擷取指標,就會從數位板介面中,從數位板 (表面增益觸控或手寫筆接觸。

PointerRoutedAway

當指標重新導向至另一個輸入物件時,會在接收指標的輸入物件上發生, (可能在不同的進程中) 。

PointerRoutedReleased

發生在與輸入物件相關聯但目前未接收輸入的所有輸入物件上,該指標會在輸入物件上引發 CoreIndependentInputSource.PointerReleased 事件。

PointerRoutedTo

發生于先前擷取的指標輸入傳遞至另一個物件時,轉換至傳遞至這個物件。

PointerWheelChanged

旋轉滑鼠滾輪時所引發的事件。

此事件的委派類型為TypedEventHandler < TSender,TResult >,其中TSender的類型為CoreWindow而 TResult的類型為PointerEventArgs

ResizeCompleted

發生于使用者完成調整視窗大小時。

ResizeStarted

發生于使用者開始調整視窗大小時。

SizeChanged

發生于視窗大小變更時。

TouchHitTesting

發生于觸控接觸區域與已登錄觸控點擊測試之視窗的周框 (或多邊形交集) 時。

VisibilityChanged

當視窗可見度變更時,就會引發 。

適用於

另請參閱