6

I'm working with DirectShow in firemonkey, and i have a problem with outputting Video.

iVideoWindow.Put_Owner(Panel1.Handle); 

I need handle of TPanel, to display video at it. But FMX controls have no handle. I know, that Firemonkey is not based on traditional windows and FMX do not provide this, but how to solve this problem? I have no idea, please, help me.

user2202896
  • 61
  • 1
  • 3
  • 6
    I'd say, you'll be out of luck. Although, you might use a form as the target of the `IVideoWindow.Owner` by converting form's `Handle` with `FmxHandleToHWND` function or take a look at alternative ways of playing video files e.g. at [`How to play video files in Firemonkey`](http://stackoverflow.com/q/8130097/960757). – TLama Mar 23 '13 at 19:02

4 Answers4

5

If you want to get a window handle as an HWND (Win32 API) type, you can now call this function:

WindowHandleToPlatform(form1.Handle).wnd

Put this in your uses clause:

uses
  FMX.Platform.Win;

Note that just calling WindowHandleToPlatform(form1.Handle) will not work, you have to access its .Wnd property to obtain the Win32 handle.

Since this makes an application less portable, it is also a good idea to put {$IFDEF MSWINDOWS} around the code whenever doing this, and if you ever port to MacOS, you'll have to write separate code for that platform. Or, put this code into a separate unit that deals only with MSWindows-related stuff, and IFDEF that unit into your uses.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Another Prog
  • 841
  • 13
  • 19
  • "*you can now call this function*" - or simpler, the [`FormToHWND()`](https://docwiki.embarcadero.com/Libraries/en/FMX.Platform.Win.FormToHWND) function. – Remy Lebeau Nov 16 '22 at 17:05
  • In addition: That would be the window handle of the form, not the Panel, so you might have issues positioning the video output where you want. – Hans Nov 17 '22 at 09:01
2

FmxHandleToHWND is marked deprecated now.

WindowHandleToPlatform will convert given FireMonkey handle to its platform dependent window handle (in your case a Windows handle).

Kromster
  • 7,181
  • 7
  • 63
  • 111
  • And even simpler, there is the [`FormToHWND()`](https://docwiki.embarcadero.com/Libraries/en/FMX.Platform.Win.FormToHWND) function for Win32 `HWND`s specifically. – Remy Lebeau Nov 16 '22 at 17:07
-1

Use Timage control, then you can assign your output to Image1.Bitmap.Handle. Its the only component that provides window Handle under FMX

  • FMX's `TImage` does not provide an `HWND`, only `TForm` does. And the `Bitmap.Handle` is not an `HWND`, nor does it represent anything that can be converted to an `HWND`. – Remy Lebeau Nov 16 '22 at 17:00
-2

To get handle of a panel, try this :

uses 
  FMX.Platform.Win;

var
  Handle : HWND;

begin

  Handle := TWinWindowHandle (Panel1).Wnd;

end;
Zac
  • 1,305
  • 3
  • 17
  • 28
  • You can't type-cast a `TPanel` object to a `TWinWindowHandle`. The only way to get a valid `TWinWindowHandle` is to pass the `TForm.Handle` to [`WindowHandleToPlatform()`](https://docwiki.embarcadero.com/Libraries/en/FMX.Platform.Win.WindowHandleToPlatform). Or, you can simply use [`FormToHWND()`](https://docwiki.embarcadero.com/Libraries/en/FMX.Platform.Win.FormToHWND) instead. – Remy Lebeau Nov 16 '22 at 17:02