Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a Form from a Window Handle

Status
Not open for further replies.

ShankarJ

Programmer
Aug 9, 2003
856
0
0
Hi!

I am quite new to C# and so please be patient with me.

I am writing a WIN32 application in Clarion (similar to C) which calls a .NET Report control via COM InterOp i.e. my C# project is just a COM wrapper over the .NET control. If I pass a Window Handle to the C# app, is there any way to create a FORM class i.e. window as a child window to the window whose handle I have passed. Basically, I want the COM object (Preview window) to be contained within the window of my application window.

Regards
 
I thought I was the only one trying to do this. My calling language is FoxPro rather than Clarion though. After searching the web for a couple days and finding nothing helpful, I decided to change my approach. Rather than using a .NET COM object I converted it to a .NET ActiveX windows control - the concept is similar to the COM object. Now I'm able to put the ActiveX control in a FoxPro form so FoxPro can handle the parent/child relation. If you end up going this route, this linked helped me in creating the ActiveX control:

Good luck!
 
Hi!

I also googled and found two approaches that worked for me ::

Code:
 public void ShowReport(IntPtr WinHandle)
 {
      Form ParentForm = (Form)Control.FromHandle(WinHandle);
 }

OR

Code:
    public class WindowWrapper : System.Windows.Forms.IWin32Window
    {
        public WindowWrapper(IntPtr handle)
        {
            _hwnd = handle;
        }

        public IntPtr Handle
        {
            get { return _hwnd; }
        }

        private IntPtr _hwnd;
    }

...

 public void ShowReport(IntPtr WinHandle)
 {
      System.Windows.Forms.IWin32Window Owner;

      Owner = new WindowWrapper(WinHandle);

      report.Show(Owner);
 }

Regards
 
Hi!

Sorry - the first one should be ::

Code:
 public void ShowReport(IntPtr WinHandle)
 {
      Form ParentForm = (Form)Control.FromHandle(WinHandle);

      [red]report.Show(ParentForm);[/red]
 }

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top