PDA

View Full Version : max rollout floater in .net form


denisT
02-03-2010, 06:58 PM
as i promised here is a snippet how to put rollout floater into .net form:

fn CreateUser32Assembly forceRecompile:on =
(
if (forceRecompile or
(classof ::User32Assembly) != dotNetObject or
((::User32Assembly.GetType()).ToString()) != "System.Reflection.Assembly") do
(
source = "using System;\n"
source += "using System.Runtime.InteropServices;\n"
source += "class User32\n"
source += "{\n"
source += " [DllImport(\"User32.DLL\", EntryPoint=\"GetWindowLong\")]\n"
source += " public static extern Int32 GetWindowLong(IntPtr hWnd, Int32 index);\n"
source += " [DllImport(\"User32.DLL\", EntryPoint=\"SetWindowLong\")]\n"
source += " public static extern Int32 SetWindowLong(IntPtr hWnd, Int32 index, Int32 newVal);\n"
source += " [DllImport(\"User32.DLL\", EntryPoint=\"SetWindowLong\")]\n"
source += " public static extern Int32 SetWindowLongPtr(IntPtr hWnd, Int32 index, IntPtr dwNewLong);\n"
source += " [DllImport(\"user32.dll\")]\n"
source += " public static extern bool SetWindowPos(IntPtr hWnd, int hWndArg, int Left, int Top, int Width, int Height, int hWndFlags);\n"
source += "}\n"

csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"

compilerParams.GenerateInMemory = true
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
::User32Assembly = compilerResults.CompiledAssembly
)
::User32Assembly.CreateInstance "User32"
)
global User32 = CreateUser32Assembly()
fn setOwnerWindow main title = if (hwnd = windows.getChildHWND 0 title) != undefined do
(
hwnd = dotnetobject "IntPtr" hwnd[1]
main = dotnetobject "IntPtr" main
::User32.SetWindowLongPtr hwnd -8 main -- set ownership
::User32.SetWindowPos hwnd 0 0 0 0 0 0x3 -- set z-top
hwnd
)

try(closeRolloutFloater max_float) catch()
try(destroydialog max_rol) catch()
try(win.close()) catch()

win = dotNetObject "MaxCustomControls.MaxForm"
win.size = dotNetObject "System.Drawing.Size" 200 270
win.Location = dotNetObject "System.Drawing.Point" 900 150
win.StartPosition = win.StartPosition.Manual
win.text = "Max Form"


rollout max_rol "Radius"
(
local sph
spinner sp "Radius: " fieldwidth:60 align:#right
on max_rol open do with undo off
(
sph = sphere radius:(random 10 40) isselected:on
sp.controller = sph.radius.controller = bezier_float()
)
-- on max_rol resized val do (if sp.pos.x != val.x-25 do sp.pos.x = val.x-25)
fn close = (if isvalidnode sph do with undo off delete sph)
)
rollout hem_rol "Hemisphere" rolledup:on
(
spinner sp "Hemisphere: " range:[0,1,0] scale:0.01 fieldwidth:60 align:#right
bitmap bm bitmap:(bitmap 160 100 color:blue)

on hem_rol open do with undo off
(
sp.controller = max_rol.sph.hemisphere.controller = bezier_float()
)
)

win.showmodeless()

p = win.RectangleToScreen win.ClientRectangle
max_float = newRolloutFloater "Max Floater" (p.width-10) p.height p.left -1000

--win.tag = dotnetmxsvalue #(max_rol)
win.tag = dotnetmxsvalue #(max_rol)

addrollout max_rol max_float
addrollout hem_rol max_float rolledup:on
--createdialog max_rol p.width p.height p.left p.top bgcolor:white style:#()
--win.tag.value[2] = setOwnerWindow win.handle max_rol.title
win.tag.value[2] = setOwnerWindow win.handle max_float.title

GWL_STYLE = -16
WS_BORDER = 0x00800000
WS_DLGFRAME = 0x00400000
WS_THICKFRAME = 0x00040000
WS_POPUP = 0x80000000
WS_CHILD = 0x40000000
WS_DISABLED = 0x08000000

f = ::User32.GetWindowLong win.tag.value[2] GWL_STYLE

f = bit.xor f (WS_BORDER + WS_DLGFRAME + WS_THICKFRAME + WS_CHILD + WS_POPUP)
::User32.SetWindowLong win.tag.value[2] GWL_STYLE f

p = win.RectangleToScreen win.ClientRectangle
::User32.SetWindowPos win.tag.value[2] 0 p.x p.y (win.tag.value[1].width+20) p.height 0
win.Focus()

fn onMove s a =
(
p = s.RectangleToScreen s.ClientRectangle
::User32.SetWindowPos s.tag.value[2] 0 p.x p.y (win.tag.value[1].width+20) p.height 0
)
dotnet.addEventHandler win "Move" onMove
fn onResized s a =
(
p = s.RectangleToScreen s.ClientRectangle
::User32.SetWindowPos s.tag.value[2] 0 p.x p.y (win.tag.value[1].width+20) p.height 0
)
dotnet.addEventHandler win "Resize" onResized
fn onClosing s a =
(
s.tag.value[1].close()
)
dotnet.addEventHandler win "Closing" onClosing


owner window doesn't lose focus!

ps. i didn't have a time to clean it up.

HornBerger
02-05-2010, 04:50 AM
:thumbsup: brilliant big D. :) was wondering if its possible to embed the pflow view inside the viewport. (but i doubt theres a handle to each viewport is there?) i have posted the same in 3d max forum :- http://forums.cgsociety.or (http://forums.cgsociety.org/showthread.php?f=6&t=850606%20)g/showthread.php?f=6&t=850606 (http://forums.cgsociety.org/showthread.php?f=6&t=850606%20)

any help is appreciated thanks :)

CGTalk Moderation
02-05-2010, 04:50 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.