[Closed] How to get 3dsmax minimize/maximize handler
Hi guys,
I’m working with a .net Form, and I’d like to get it to minimize and maximize with 3ds Max, so it acts more like a rollout. I was thinking of adding handlers to run when 3dsmax minimizes or maximizes, but I’m not sure how to get those. I’m assuming its a hwnd call.
Unless there is an easier way that I’m not seeing. I have my form flagged to TopMost ‘true’ if that helps.
Thanks.
there are two easy way of doing this:
#1
form = dotnetobject "MaxCustomControls.Maxform"
form.showmodeless()
or
#2
form = dotnetobject "Form"
form.Show (dotnetobject "MaxCustomControls.Win32HandleWrapper" (dotnetobject "System.IntPtr" (windows.getmaxhwnd())))
I’ve just finished implementing this for something else, and my solution was not trivial in any way.
I created a nativewindow class wrapped around the 3dsmax hwnd (windows.getMaxHwnd()) and used that to fire events on WM_ACTIVATEAPP and WM_NCACTIVATE back to my script.
If there’s an easier way I’ll feel somewhat of a fool
edit:
If you are using a topmost dotnet form and it is not very small, you might have a slight problem with modal dialogs in max (object properties, send net render, error messages, etc.) because if the modal dialog is covered by your form, there will be no way to get to it and you’ll be stuck.
What I did to overcome this is catch the #MainWindowEnabled max callback and use that to temporarily cancel the topmost state of the form.
this is the c# code I used for the nativeWindow class:
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
public class MaxWindowOps : NativeWindow
{
public delegate void ActivationHandler(bool activated);
public event ActivationHandler ActivationEvent;
private const int WM_ACTIVATEAPP = 0x001C;
private const int WM_NCACTIVATE = 0x0086;
private IntPtr hwnd;
public bool Active;
public IntPtr handle
{
get { return hwnd; }
set
{
ReleaseHandle();
hwnd = value;
AssignHandle(hwnd);
}
}
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (Active)
{
switch (m.Msg)
{
case WM_ACTIVATEAPP:
if (ActivationEvent != null) ActivationEvent(m.WParam != IntPtr.Zero);
break;
case WM_NCACTIVATE:
if (ActivationEvent != null && m.WParam != IntPtr.Zero) ActivationEvent(true);
break;
default:
break;
}
}
}
}
what’s the difference?
form = dotnetobject "Form"
form.TopMost = on
form.Show (dotnetobject "MaxCustomControls.Win32HandleWrapper" (dotnetobject "System.IntPtr" (windows.getmaxhwnd())))
formm = dotnetobject "MaxCustomControls.Maxform"
formm.TopMost = on
formm.showmodeless()
You’re right, it does minimize and maximize with max, maybe this is enough for the OPs needs. The problem I had with it is that it still stays on top of other applications when max loses focus.
Thanks guys for the responses. That should do it.
Yea i figured the “top most” would cause some problems, but having it minimize and maximize with max will at least make it seem a bit more 3dsmax “internal”
Thanks guys.