Notifications
Clear all

[Closed] dotNetObject "maxCustomControls.win32HandleWrapper" missing in Max 2015?

Is it just me, or is win32HandleWrapper missing from the 2015 MaxCustomControls assembly? If this is the case, pretty much ALL my scripts will need to be changed to work with 2015.

dotNetObject "maxCustomControls.win32HandleWrapper"
8 Replies
 lo1

What an incredibly bizarre class to omit. Seems unlikely that this is done on purpose.

Look at http://msdn.microsoft.com/en-us/library/System.Windows.Forms.NativeWindow(v=vs.110).aspx

So the code would be something like this, no? I dont have max around atm.


nw = DotNetObject "System.Windows.Forms.NativeWindow"
nw.AssingHandle (DotNetObject "System.IntPtr" (Windows.GetMaxHWND()))
myForm.Show(nw)

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Thanks haavard for this replacement snippet. Also thanks to lo for “ReleaseHandle” suggestion.
Test form code


if ::frm != undefined do try(frm.Close())catch()
(	fn defNWin = 
	(
		nw = DotNetObject "NativeWindow"
		nw.AssignHandle (DotNetObject "System.IntPtr" (Windows.GetMaxHWND())) 
		nw
	)
	 fn defColor r g b = ((dotNetClass "System.Drawing.Color").FromArgb r g b)
	 fn defSize w h = (dotNetObject "System.Drawing.Size" w h)
	fn defPoint x y = (dotNetObject "System.Drawing.Point" x y)
	local maxBC = defColor 80 80 80, maxFC = defColor 200 200 200

	fn defForm dnFrm w: h: = --FORM
	 (
		 dnFrm.FormBorderStyle = dnFrm.FormBorderStyle.FixedToolWindow
		dnFrm.StartPosition = dnFrm.StartPosition.Manual 
		 dnFrm.Text = "test"
		dnFrm.BackColor = maxBC
		 dnFrm.ShowInTaskbar = off
		 dnFrm.ClientSize = defSize w h
		dnFrm.Location = defPoint 10 110
	 )
	fn defBtn btn w: h: txt: = --BUTTON
	(
		btn.Size = defSize w h
		btn.text = txt
		btn.FlatStyle = btn.FlatStyle.Flat
		btn.FlatAppearance.BorderSize = 0
		btn.BackColor = maxBC
		btn.ForeColor = maxFC
	)	
	nw = defNWin()
	frm = dotnetobject "Form" ; defForm frm w:100 h:50
	ts = dotnetobject "Button" ; defBtn ts w:100 h:50 txt:"Button"
	frm.Controls.Add (ts)
	frm.Show(nw)
	nw.ReleaseHandle() 
	ok
)

 lo1

No, not at all.

maxCustomControls.win32HandleWrapper is an implementation of the System.Windows.Forms.IWin32Window Interface, used for exposing handles.

It should be no problem to recreate it in your own assembly to replace it (untested):

namespace maxCustomControls
{
   public class Win32HandleWrapper : System.Windows.Forms.IWin32Window
   {
       private IntPtr handle;
       public IntPtr Handle { get; }

       public Win32HandleWrapper(IntPtr handle) { this.handle = handle; }
   }
}
 lo1

Actually, come to think of it, NativeWindow also happens to implement IWin32Window, so your suggested code will also work fine, though NativeWindow is a bit overkill, and you’d have to call ‘ReleasedHandle’ when you don’t need it anymore.

Thanks for the code lo

The only thing I had to change was adding a ‘set;’ in Handle.

 lo1

I may have been asleep when I wrote that. The correct code should be

namespace maxCustomControls
{
   public class Win32HandleWrapper : System.Windows.Forms.IWin32Window
   {
       public IntPtr Handle { get; set; }
       public Win32HandleWrapper(IntPtr handle) { this.Handle = handle; }
   }
}