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

Get native Window handle from control #6843

Closed
niksedk opened this issue May 5, 2022 · 6 comments
Closed

Get native Window handle from control #6843

niksedk opened this issue May 5, 2022 · 6 comments
Labels
legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor proposal/open

Comments

@niksedk
Copy link

niksedk commented May 5, 2022

Description

I would like to port a Winforms desktop app which uses a native lib to render video - so the app should have different code for different platforms, but I was unable to find a way to get an IntPtr Windows handle from e.g. a BoxView.

Public API Changes

I do not know where this functionality should be added...

Intended Use-Case

In Winforms we can do something like this:

_libvlc_media_player_set_hwnd(mediaPlayer, panelVideo.Handle); // Render video on Windows in a panel control

It would be very useful to have a similar feature in Maui - if it's not already available.

@jfversluis
Copy link
Member

I think we only have this on a window level now, but you're asking on a control level, right?

@jfversluis jfversluis added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 5, 2022
@niksedk
Copy link
Author

niksedk commented May 5, 2022

I think we only have this on a window level now, but you're asking on a control level, right?

Yes, that's correct.

@PureWeen
Copy link
Member

PureWeen commented Sep 7, 2022

@niksedk we've added the Window property to every single control. Once the view has been added to a control you can use BoxView.Window.Handler.PlatformView to return the platform window and then get the handle from that. Does that work for you for now?

@niksedk
Copy link
Author

niksedk commented Sep 8, 2022

@PureWeen: thanks for the Window property :)

I've added a BoxView to my app created with the default template:

            <BoxView 
                x:Name="BoxView1"
                WidthRequest="400"
                HeightRequest="200"
                MaximumHeightRequest="200"
                MaximumWidthRequest="400"
                />

image

In the OnCounterClicked method I've added:

#if WINDOWS
  videoPlayer.Initialize((IntPtr)(BoxView1.Window.Handler.PlatformView as MauiWinUIWindow).WindowHandle, "video.mp4");
#endif

Which seems to make a video player in the whole app window:
image

Any ideas?

@mattleibow
Copy link
Member

mattleibow commented Nov 10, 2022

This may be possible once you have the native WinUI control. So if you do BoxView.Handler.PlatformView as Microsoft.UI.Xaml.Element there may be a way.

I would actually suggest talking to the WinUI experts over on https://github.com/microsoft/microsoft-ui-xaml as I am not sure myself if I know of a proper (or a bit hacky) way to do this. It may also be the case that there is no HWND by default as these may not be "normal" controls and you have to add some sort of special composition or HWND-supporting panel.

But again, not sure we can be as helpful as we would like and opening a new issue on how to get a HWND from a UI element in WinUI 3 will be the solution. And then you take that and just use the PlatformView value from MAUI to merge the two worlds.

I am going to close this issue not because it is unimportant, but more that we can't really help. If there is anything that we have to do to make it work, please come back here and let us know so we can investigate on our side.

@mattleibow mattleibow closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2022
@ghost
Copy link

ghost commented Nov 29, 2022

Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor proposal/open
Projects
None yet
Development

No branches or pull requests

4 participants