If you are writing a tool that contains a separate window it can be very useful to make that window dockable in the viewport. Following code demonstrated how to do that using Max.NET and any .NET form:
class MainViewWindow : global::Autodesk.Max.Plugins.ViewWindow
{
IntPtr previousParent;
WindowStyles previousStyle;
public override IntPtr CreateViewWindow( IntPtr hParent, int x, int y, int w, int h )
{
this.previousParent = GetParent( Plugin.Instance.MainFrame.Handle );
this.previousStyle = GetWindowStyle( Plugin.Instance.MainFrame.Handle );
Form mainFrame = GetMyForm();
SetWindowStyle( mainFrame.Handle, WindowStyles.WS_CHILD | WindowStyles.WS_VISIBLE );
SetParent( mainFrame.Handle, hParent );
mainFrame.dockedInsideExtendedView = true;
return mainFrame.Handle;
}
public override void DestroyViewWindow( IntPtr hWnd )
{
GetMyForm().dockedInsideExtendedView = false;
SetWindowStyle( Plugin.Instance.MainFrame.Handle, this.previousStyle );
SetParent( Plugin.Instance.MainFrame.Handle, this.previousParent );
GetMyForm().FormBorderStyle = FormBorderStyle.Sizable;
GetMyForm().Close();
}
public override string Name
{
get { return "Main Window"; }
}
/// <summary>
/// Can only have one mainframe!
/// </summary>
public override int NumberCanCreate
{
get { return 1; }
}
}
SetWindowStyle(...) and SetParent(...) are native Win32 methods marshalled into .net using PInvoke.
Once you have docked the window inside the viewport you will probably need a way to undock it (revert the viewport back to a 3d view or to another extended viewport option). This is achieved pretty simply- 3dsmax provides a method to bring up a context menu that will allow a user to switch a viewport to another option.
To bring this context menu handle a right click event somewhere in your .NET window and when it happens call the IGlobal.COREInterface.PutUpViewMenu(...) method. For example:
void menuStrip_MouseDown( object sender, MouseEventArgs e )
{
if( e.Button == MouseButtons.Right && this.dockedInsideExtendedView )
{
Plugin.Instance.Global.COREInterface.PutUpViewMenu( this.Handle, e.Location );
}
}
Once the user picks an option from the context menu 3dsmax will automatically call your ViewWindow class to destroy the window and replace it with something else.
10 May 2010
#1924 | |
SetWindowStyle(...) and SetParent(...) need more detail code............ | |
10 May 2010
#1928 | |
I have made a post about this in the private forum, please look here. Marsel Khadiyev (Software Developer, EPHERE Inc.) | |
28 May 2010
#2012 | |
http://www.ephere.com/autodesk/max/forums/general/thread_930.html |