TheSwamp

Code Red => .NET => Topic started by: Andrey Bushman on October 08, 2012, 01:23:30 PM

Title: Can I get System.Windows.Forms.Form, or System.Windows.Window from Autodesk.Aut
Post by: Andrey Bushman on October 08, 2012, 01:23:30 PM
Hi all.

The main AutoCAD window has type Autodesk.AutoCAD.Windows.Window. The Document.Window has this type too. Can I get System.Windows.Forms.Form, or System.Windows.Window from Autodesk.AutoCAD.Windows.Window?

Regards
Title: Re: Can I get System.Windows.Forms.Form, or System.Windows.Window from Autodesk.Aut
Post by: MexicanCustard on October 08, 2012, 02:16:43 PM
What would you need the "Form" for?

You can get a pointer/Handle to the main window with Autodesk.AutoCAD.Application.Window.Handle.
Title: Re: Can I get System.Windows.Forms.Form, or System.Windows.Window from Autodesk.Aut
Post by: Andrey Bushman on October 08, 2012, 02:54:42 PM
It is more convenient for me - to work with managed code.
Title: Re: Can I get System.Windows.Forms.Form, or System.Windows.Window from Autodesk.Aut
Post by: kaefer on October 08, 2012, 04:08:06 PM
It is more convenient for me - to work with managed code.

You could wrap the unmanaged bit with a framework feature, for example an interface to a window handle. I do not think it neither unsafe nor inconvenient.

Code - F#: [Select]
  1.             let owner = { new System.Windows.Forms.IWin32Window with
  2.                 member __.Handle =
  3.                     Autodesk.Windows.ComponentManager.ApplicationWindow }
  4.  
  5.             let form = new System.Windows.Forms.Form()
  6.             form.Show owner
  7.             while form.Visible do
  8.                 System.Threading.Thread.Sleep 100
  9.             form.Close()
Title: Re: Can I get System.Windows.Forms.Form, or System.Windows.Window from Autodesk.Aut
Post by: TheMaster on October 08, 2012, 07:30:42 PM
Hi all.

The main AutoCAD window has type Autodesk.AutoCAD.Windows.Window. The Document.Window has this type too. Can I get System.Windows.Forms.Form, or System.Windows.Window from Autodesk.AutoCAD.Windows.Window?

Regards

The sample answer is no, you can't put a Form or Window wrapper around a Win32 window. You can put a NativeWindow wrapper around a Win32 window, however, which is standard means of subclassing a Win32 window in .NET. See the NativeWindow class in the docs or search here for an example.

Title: Re: Can I get System.Windows.Forms.Form, or System.Windows.Window from Autodesk.Aut
Post by: Andrey Bushman on October 09, 2012, 01:33:06 PM
Thanks to all for answers.