WinUI3 : Understanding WinUI3 desktop app

Harshithraj1871 1,536 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

Universal Windows Platform (UWP)
Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
780 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,589 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 84,546 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;  
    }  
    

0 additional answers

Sort by: Most helpful

Your answer

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