// ---------------------------------------------------------------------- // IWindow // ---------------------------------------------------------------------- Window::Window() { // The first window created internally by DXamlCore _must_ be a UWP Window. DXamlCore // requires and controls the lifetime of a hidden UWP Microsoft.UI.Xaml.Window. // note that this Window instance will be the 'real' window for UWP instances, but // serves as a dummy for all other instances. dummy behavior is deprecated and being removed. auto dxamlCore = DXamlCore::GetCurrent(); Window* window = dxamlCore->GetDummyWindowNoRef();
if (!window) { // Do a runtime check to see if UWP should be enabled staticauto runtimeEnabledFeatureDetector = RuntimeFeatureBehavior::GetRuntimeEnabledFeatureDetector(); auto UWPWindowEnabled = runtimeEnabledFeatureDetector->IsFeatureEnabled(RuntimeEnabledFeature::EnableUWPWindow);
// WinUI UWP if (!UWPWindowEnabled && DXamlCore::GetCurrent()->GetHandle()->GetInitializationType() != InitializationType::IslandsOnly) { ::RoOriginateError( E_NOT_SUPPORTED, wrl_wrappers::HStringReference( L"WinUI: Error creating an UWP Window. Creating an UWP window is not allowed." ).Get()); XAML_FAIL_FAST(); } m_spWindowImpl = std::make_shared<UWPWindowImpl>(this); } else { m_spWindowImpl = std::make_shared<DesktopWindowImpl>(this); } }
We have packaged this project into winrt. With the winrt version, we can use it in cpp/winrt and other projects. You can find the winrt version in winrt branch.
How to use it
There are two way to reference it.
Reference to the project directly
Fork this repository and change the branch to winrt.
If your project is face to uwp, add this to your .vcproj