Author Topic: Can I get System.Windows.Forms.Form, or System.Windows.Window from Autodesk.Aut  (Read 3089 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
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

MexicanCustard

  • Swamp Rat
  • Posts: 705
What would you need the "Form" for?

You can get a pointer/Handle to the main window with Autodesk.AutoCAD.Application.Window.Handle.
Revit 2019, AMEP 2019 64bit Win 10

Andrey Bushman

  • Swamp Rat
  • Posts: 864
It is more convenient for me - to work with managed code.

kaefer

  • Guest
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()

TheMaster

  • Guest
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.


Andrey Bushman

  • Swamp Rat
  • Posts: 864
Thanks to all for answers.