Pop a Form from Unmanaged code

  • Thread starter Thread starter martin.bonneville
  • Start date Start date
M

martin.bonneville

Hi,

I have a .Net Form.

When I call the ShowDialog from unmanaged code (C++ compiled in VS2005
/clr),
the dialog don't appear... it seem to be behind the main window.

If I change the property "TopMost" of the form... then it appear
correctly but
all the children form appear behind.

Anyone have an idea how I can show the .Net Form correctly from
unmanaged code?

Best regards,

Martin
 
Martin,

When you call ShowDialog use the overload that accepts parameter and pass
reference to the main form. This way the main form becomes owner of the
dialog and the dialog will stay above. Top most is not what you wanna do.
 
Hi,

The overload of ShowDialog needs a "IWin32Window".

I call the ShowDialog from a "CMDIFrameWnd"... how I can
get a "IWin32Window" from my code?

Best regards,
 
Oh sorry, I didn't read the subject very well. You are using this from
unmanaged code. Managed System.Windows.Forms.Form implements this interface.

In your case try to use SetParent API to change the parent/owner of the
form.
 
Hi,

Ok... but here's an exemple of what I do:

Unmanaged code...

IManagedComponent^ clrComponent = GetManagedComponent();

clrComponent->ShowDialog();



Managed code....
In the class implementing "IManagedComponent"

ShowDialog()
{
formToPop^ newForm = gcnew formToPop();

newForm->ShowDialog();
}


If I understand correctly what you say, the
IManagedComponent::ShowDialog
needs to have a parameter the pass the CWnd pointer to the managed
code?

Can you show me how?

Best regards,
 
I don't think you can do it with pointers. BTW I'm really confused now. I
thought you are using C++ and MFC now that code
IManagedComponent^ clrComponent

confuses me. What is ^ on one side it looks Pascal (Delphi) on the other
hand the code is all C++. Is it something new in microsoft c++?

Anayways, I don't thing you can use references or pointers in this case.
What I meant is in your unmanaged code to get the managed form handle
Form.Handle (or to be more precise Control.Handle) which is the HWND of the
window as well as the get the HWND to the unmanged CWnd::m_hWnd (if it is
MFC) and then call the SetParent API to change the managed window's parent

HWND SetParent( HWND hWndChild, HWND hWndNewParent
);

In your case hWndChild would be the HWND for the managed dialog and
hWndNewParent would be hWndNewParent.

I'm sorry I can give you an example of how to do that. As I said I didn't
pay attention that your question is about unmanaged code. Even though I have
great deal of experience with MFC and unmanaged applications I have none as
far as it goes down to managed C++. You should probably try your question in
..NET C++ related groups.
 
Hi,

I'm using "managed C++" inside "unmanaged class".
^ is a replacement of * in mfc... new syntax in 2005.

I posted my question in microsoft.public.dotnet.languages.vc.

Thanks for your time Stoitcho. :-)

Best regards,

Martin
 
Back
Top