Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom message loop and WinMain in WinUI 3? #4160

Open
sylveon opened this issue Feb 11, 2021 · 14 comments
Open

Custom message loop and WinMain in WinUI 3? #4160

sylveon opened this issue Feb 11, 2021 · 14 comments
Labels
appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps area-XamlWindow feature proposal New feature proposal team-Reach Issue for the Reach team

Comments

@sylveon
Copy link
Contributor

sylveon commented Feb 11, 2021

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?

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Feb 11, 2021
@StephenLPeters
Copy link
Contributor

This feels very similar to #3408 @sylveon do you argree?

@sylveon
Copy link
Contributor Author

sylveon commented Feb 12, 2021

For the custom main part yes, but not the message loop

@StephenLPeters StephenLPeters added appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps product-winui3 WinUI 3 issues labels Feb 12, 2021
@StephenLPeters
Copy link
Contributor

@ocalvo and @MikeHillberg FYI

@StephenLPeters StephenLPeters added the team-Reach Issue for the Reach team label Feb 12, 2021
@MikeHillberg
Copy link
Contributor

Xaml islands is the design for hosting WinUI3 and running your own message pump. Just avoiding the call to Start won't help because in addition to running the pump it does some necessary initialization.

And I'm not sure that the Window class will work when running the thread as an island. Maybe we should make that a feature request, and at least call out in the spec/docs.

@sylveon
Copy link
Contributor Author

sylveon commented Feb 15, 2021

Why not make it possible to do the initialization as a separate API call so that a consumer can simply call that, new up Windows, and run their own message loop?

The XAML Island API is a lot more trouble than using Window (because you have to implement all the windowing/custom titlebar stuff that Window takes care of yourself).

Making Window supported in XAML islands would be a valid alternative yes.

@marb2000 marb2000 added the feature proposal New feature proposal label Feb 20, 2021
@ghost ghost added this to Freezer in Feature tracking Feb 20, 2021
@marb2000 marb2000 removed needs-triage Issue needs to be triaged by the area owners product-winui3 WinUI 3 issues labels Feb 20, 2021
@marb2000
Copy link
Contributor

@sylveon I added the label feature proposal to the issue. Does this sound good for you? Feel free to close the issue.

@sylveon
Copy link
Contributor Author

sylveon commented Feb 20, 2021

Yep, sounds good to me

@sylveon
Copy link
Contributor Author

sylveon commented Jul 6, 2023

Bump? I'm thinking of introducing new features to my app which require custom message loop handling (specifically, using MsgWaitForMultipleObjectsEx and using an event to wake up the code to process some events), but they would block an eventual migration to WinUI 3 currently.

@sylveon
Copy link
Contributor Author

sylveon commented Jul 6, 2023

Application.Run being blocking is a huge problem for me :(

@Ajith-GS
Copy link

Application.Run being blocking is a huge problem for me :(

Is there any update on this issue? I am facing the same issue

@bpulliam bpulliam changed the title Question: Custom message loop and WinMain in WinUI 3? Custom message loop and WinMain in WinUI 3? Oct 18, 2023
@bpulliam bpulliam removed the question label Oct 18, 2023
@myth384
Copy link

myth384 commented Feb 24, 2024

Application.Run being blocking is a huge problem for me :(

For me as well! I recently made a wide scoped feature request. I think your suggestion falls into this request as well. Can you relate to that?

@sylveon
Copy link
Contributor Author

sylveon commented Feb 24, 2024

Allowing custom message loops would probably be required to implement your feature proposal, but your proposal in specific isn't related to my use case (everything is contained within a single assembly/app, I just want to be able to use custom code for my message loop)

@sylveon
Copy link
Contributor Author

sylveon commented Feb 24, 2024

Also, I don't use C#

@myth384
Copy link

myth384 commented Feb 29, 2024

Your very technical specific suggestion is indeed one of the requirements to be able to implement mine. My suggestion may have a larger audience, which could give traction to yours. That's the reason I'm replying here.
Lastly, I don't think Microsoft would limit any solution for your problem to just C++.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps area-XamlWindow feature proposal New feature proposal team-Reach Issue for the Reach team
Projects
Development

No branches or pull requests

7 participants