Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Stuff FireMonkey Form into a HWND...



Permlink Replies: 3 - Last Post: Nov 18, 2016 4:01 PM Last Post By: Remy Lebeau (Te...
John Marinuzzi

Posts: 12
Registered: 3/2/07
Stuff FireMonkey Form into a HWND...
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 8, 2016 12:48 PM
I am creating a DLL for a program that provides a Window Handle (HWND) as the parent for the information contained on a FireMonkey form. With VCL you could assign the HWND to the ParentWindow property. Has anybody been able to do something similar with FireMonkey? It is just for a Windows application.

Thanks,

John
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Stuff FireMonkey Form into a HWND...
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 8, 2016 1:00 PM   in response to: John Marinuzzi in response to: John Marinuzzi
John wrote:

Has anybody been able to do something similar with FireMonkey?

FireMonkey does not have an equivilent of the ParentWindow property. You
would have to manually call the Win32 API SetParent() function directly instead.
You can get the HWND of a FireMonkey TForm using FireMonkey's FmxHandleToHWND(),
WindowHandleToPlatform(), or FormToHWND() function (depending on your version
of C++Builder) in FMX.Platform.Win.hpp.

--
Remy Lebeau (TeamB)
John Marinuzzi

Posts: 12
Registered: 3/2/07
Re: Stuff FireMonkey Form into a HWND...
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 18, 2016 7:52 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
John wrote:

Has anybody been able to do something similar with FireMonkey?

FireMonkey does not have an equivilent of the ParentWindow property. You
would have to manually call the Win32 API SetParent() function directly instead.
You can get the HWND of a FireMonkey TForm using FireMonkey's FmxHandleToHWND(),
WindowHandleToPlatform(), or FormToHWND() function (depending on your version
of C++Builder) in FMX.Platform.Win.hpp.

--
Remy Lebeau (TeamB)

Thank you for the reply.

So, I attempted this, but there are still some issues:

Here is the code:

bool FireMonkeyDev::DevOpen( HWND h )
{
	frmDisplay = new TfrmDisplay( NULL );
	frmDisplay->Top = 0;
	frmDisplay->Left = 0;
	SetParent( FormToHWND( frmDisplay ), h );
	// SetParent( ApplicationHWND(), h );
	frmDisplay->Visible = true;
 
	return SurveyDriver::DevOpen( h );
}


This is where the window shows up relative to the window handle in the parameter.

[Picture.|https://goo.gl/photos/bv469riZz6K3knaz5]

The grey window with the button should be in the white window.

Any suggestions?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Stuff FireMonkey Form into a HWND...
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 18, 2016 4:01 PM   in response to: John Marinuzzi in response to: John Marinuzzi
John wrote:

The grey window with the button should be in the white window.

The Form's HWND is not created with the WS_CHILD style by default, so calling
SetParent() establishes the external HWND as the Form's new owner window,
not its parent window. As stated on MSDN:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms633541.aspx

For compatibility reasons, SetParent does not modify the WS_CHILD or WS_POPUP
window styles of the window whose parent is being changed. Therefore, if
hWndNewParent is NULL, you should also clear the WS_CHILD bit and set the
WS_POPUP style after calling SetParent. Conversely, if hWndNewParent is not
NULL and the window was previously a child of the desktop, you should clear
the WS_POPUP style and set the WS_CHILD style before calling SetParent.

You can use the Win32 API SetWindowLongPtr() function to change the Form
HWND's style bits.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02