Skip to content

Custom message loop and WinMain in WinUI 3? #4160

@sylveon

Description

@sylveon

I am interested in porting some Win32 XAML Islands code to WinUI 3 for a future release - but I have one major question that I can't seem to find an answer to anywhere: is there a way to host WinUI 3 in a custom wWinMain function and with a custom message loop?

I am asking this because currently:

  • I am using some Win32 features and third party components that require PreTranslateMessage to be inserted in the message loop
  • I need some custom initialization in that happens before anything from WinUI in wWinMain
  • I use APIs like WriteFileEx, which require to use MsgWaitForMultipleObjectsEx instead of the GetMessage loop.

Sure, I could just wait for WinUI 3's XAML islands and port all my existing code to that, but that seems like far away still, and I want to make use of WinUI's Window class to be able to remove most of my custom XAML island hosting code, since Window covers most of my use cases.

From what I understand, I can just disable the XAML generated main and use my own wWinMain for the first part, but the XAML generated main calls into Application.Start, which blocks until the app exits: this is undesired, and I can't find a non-blocking alternative.

Another side question: can we mix normal WinUI 3 and WinUI 3 XAML Islands in the same app?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions