WinUI3 : Understanding WinUI3 desktop app

Harshithraj1871 1,786 Reputation points
2022-11-18T12:37:34.79+00:00

Hi,

As we can create a WinUI3 app in both the desktop app(win32 app) and the UWP app. What exactly does it mean to create a WinUI3 in a desktop app? As I understand, this app will follow the Win32 App model, that is, the app will not run on sandbox and the app will not have activation and lifecycle management like UWP apps. Is this right?

In this case, How can we use Win32 APIs in this project, and how can we follow the event loop like the WNDPROC callback function instead of Application::Start()?

Thank You

Developer technologies | Universal Windows Platform (UWP)
Windows development | Windows App SDK
Windows development | Windows API - Win32
0 comments No comments

Answer accepted by question author
Castorix31 91,976 Reputation points
2022-11-18T13:01:00.707+00:00

Application::Start replaces the main message loop
As it is a Win32 app, you can have access to the main window WndProc with SetWindowSubclass (for example in some samples I posted in C#, like in MainWindow.xaml.cs, where I needed to intercept particular messages)

I have this wWinMain in the C++ generated code :

int __stdcall wWinMain(HINSTANCE, HINSTANCE, PWSTR, int)  
{  
    {  
        void (WINAPI *pfnXamlCheckProcessRequirements)();  
        auto module = ::LoadLibrary(L"Microsoft.ui.xaml.dll");  
        if (module)  
        {  
            pfnXamlCheckProcessRequirements = reinterpret_cast<decltype(pfnXamlCheckProcessRequirements)>(GetProcAddress(module, "XamlCheckProcessRequirements"));  
            if (pfnXamlCheckProcessRequirements)  
            {  
                (*pfnXamlCheckProcessRequirements)();  
            }  
  
            ::FreeLibrary(module);  
        }  
    }  
  
    winrt::init_apartment(winrt::apartment_type::single_threaded);  
    ::winrt::Microsoft::UI::Xaml::Application::Start(  
        [](auto&&)  
        {  
            ::winrt::make<::winrt::WinUI3_CPP2::implementation::App>();  
        });  
  
    return 0;  
}  

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.