PDA

View Full Version : dotNet Form on top of Max only?


PEN
10-28-2009, 04:08 PM
So I have a form that I want to keep on top of Max. Setting topMost forces it to the top of everything. Placing another dialog, even Max dialogs over Max results in anything drawing in the form to be on top of everything. Is there a way to force it to at least only be on top of Max?

Any good cheats, like if Max looses focus force it to the back?

PEN
10-28-2009, 04:10 PM
And is there a way to not be able to select anything that is displayed in the form? This is the transparent form that I have so anything that is drawn into the form stops you from clicking on objects in Max or doing anything else. Any where the form is transparent you can click on objects.

Kameleon
10-28-2009, 04:27 PM
Hey Paul,
Can you show us how are you creating the form?

Cheers.

PEN
10-28-2009, 04:51 PM
form=dotNetObject "form"
form.AllowTransparency=false
form.BackColor=(dotNetClass "system.drawing.color").fromArgb 0 0 255
-- form.TransparencyKey=(dotNetClass "system.drawing.color").fromArgb 0 0 255
form.ShowInTaskBar =false
form.FormBorderStyle=form.FormBorderStyle.none
form.TopMost=true

form.show()

--form.close()

Kameleon
10-28-2009, 04:59 PM
Have you tried the MaxCustomControls.MaxForm? And then using the ShowModal() method?

form=dotNetObject "MaxCustomControls.MaxForm"
form.AllowTransparency=false
form.BackColor=(dotNetClass "system.drawing.color").fromArgb 0 0 255
--form.TransparencyKey=(dotNetClass "system.drawing.color").fromArgb 0 0 255
form.ShowInTaskBar =false
form.FormBorderStyle=form.FormBorderStyle.none
form.TopMost=true

form.showmodal()

Although I dont think transparency works with this way.

Note: Press Alt+F4 to close the window after running the script

Cheers.

denisT
10-28-2009, 05:06 PM
form=dotNetObject "form"
form.AllowTransparency=false
form.BackColor=(dotNetClass "system.drawing.color").fromArgb 0 0 255
-- form.TransparencyKey=(dotNetClass "system.drawing.color").fromArgb 0 0 255
form.ShowInTaskBar =false
form.FormBorderStyle=form.FormBorderStyle.none
form.TopMost=true

form.show()

--form.close()

instead of ising dotnetobject "Form" you can use dotNetObject "MaxCustomControls.MaxForm"

maxWin = dotNetObject "MaxCustomControls.MaxForm"
maxWin.size = dotNetObject "System.Drawing.Size" 800 600
maxWin.text = "Max DotNet Dialog"
maxWin.showmodeless()


this maxForm has the same properties and methods as "Form" but has the max dialog behavior ...

PEN
10-28-2009, 05:08 PM
I saw that but I can't get transparency working with the MaxCustomControls.MaxForm. Would be nice if it would work as I would use it. I don't want it to be model in that I want it always there just not affecting how you work. I'm most of the way to having that just not quite far enough.

try(form.close())catch()
fn formPaint sender arg=
(
rec=dotNetObject "system.drawing.rectangle" 2 2 200 200
bgColor=(dotNetClass "system.drawing.color").red
brush=dotnetobject "System.Drawing.SolidBrush" bgColor
arg.graphics.FillRectangle brush rec
)

form=dotNetObject "form"
form.AllowTransparency=false
form.BackColor=(dotNetClass "system.drawing.color").fromArgb 0 0 255
form.TransparencyKey=(dotNetClass "system.drawing.color").fromArgb 0 0 255
form.ShowInTaskBar =false
form.FormBorderStyle=form.FormBorderStyle.none
form.TopMost=true

dotnet.addEventHandler form "paint" formPaint
dotnet.setLifeTimeControl form #dotNet
form.show()

--form.close()

Kameleon
10-28-2009, 05:31 PM
Hey Paul, I don't know if I quite understood, but the first example you have, if you add controls to the form, they work and are transparent. I just added a button and there and a label, and changed it's backcolor. Dunno if this is it but here goes:

try(form.close())catch()

form=dotNetObject "form"
form.AllowTransparency=false
form.BackColor=(dotNetClass "system.drawing.color").fromArgb 1 1 255
form.TransparencyKey=(dotNetClass "system.drawing.color").fromArgb 1 1 255
form.ShowInTaskBar =false
form.FormBorderStyle=form.FormBorderStyle.none
form.TopMost=true

form.location=dotNetObject "System.Drawing.Point" 200 200

tbutton = dotnetobject "button"
tbutton.text="Test"
tbutton.backcolor=(dotNetClass "system.drawing.color").fromArgb 127 127 127

lblTest=dotnetobject "system.windows.forms.label"
lblTest.text="Test Label"
lblTest.Location=dotNetObject "System.Drawing.Point" 0 30
lblTest.backcolor=(dotNetClass "system.drawing.color").fromArgb 127 127 127

form.controls.add(tbutton)
form.controls.add(lblTest)

form.show()

--form.close()

PEN
10-28-2009, 05:44 PM
I'm not using any controls at all. I'm drawing into the form using rectangles, text and lines. I don't have a problem with the transparency of the form at all, I want the rectangles that I draw in to have a level of transparency so that I can see through them. Look at the last example that I posted, can you make red fillRectangle 50% transparent for instance.

PEN
10-28-2009, 05:46 PM
Denis, have you been able to make that dialog transparent? It doesn't work for me and I just get a gray dialog.

PEN
10-28-2009, 05:52 PM
Got the Max form to work. Looks like I had to use showModeless before setting any parameters on the dialog. If you set all the parameters and then showModeless it doesn't work.

Let me see if this will work in the full script now.

try(form.close())catch()
fn formPaint sender arg=
(
rec=dotNetObject "system.drawing.rectangle" 2 2 200 200
bgColor=(dotNetClass "system.drawing.color").red
brush=dotnetobject "System.Drawing.SolidBrush" bgColor
arg.graphics.FillRectangle brush rec
)

-- form=dotNetObject "form"
form=dotNetObject "MaxCustomControls.MaxForm"
form.showmodeless()
-- form.show()
form.AllowTransparency=true
form.opacity=10
form.BackColor=(dotNetClass "system.drawing.color").fromArgb 0 255 0
form.TransparencyKey=(dotNetClass "system.drawing.color").fromArgb 0 255 0
form.ShowInTaskBar =false
form.FormBorderStyle=form.FormBorderStyle.none
-- form.TopMost=true

dotnet.addEventHandler form "paint" formPaint
dotnet.setLifeTimeControl form #dotNet

LHM_methods.formatProps form

PEN
10-28-2009, 05:55 PM
Hows this for odd, this doesn't work as it is now being created in local scope.

(
try(form.close())catch()
fn formPaint sender arg=
(
rec=dotNetObject "system.drawing.rectangle" 2 2 200 200
bgColor=(dotNetClass "system.drawing.color").red
brush=dotnetobject "System.Drawing.SolidBrush" bgColor
arg.graphics.FillRectangle brush rec
)

-- form=dotNetObject "form"
form=dotNetObject "MaxCustomControls.MaxForm"
form.showmodeless()
-- form.show()
form.AllowTransparency=true
-- form.opacity=10
form.BackColor=(dotNetClass "system.drawing.color").fromArgb 0 255 0
form.TransparencyKey=(dotNetClass "system.drawing.color").fromArgb 0 255 0
-- form.ShowInTaskBar =false
form.FormBorderStyle=form.FormBorderStyle.none
-- form.TopMost=true

dotnet.addEventHandler form "paint" formPaint
dotnet.setLifeTimeControl form #dotNet

LHM_methods.formatProps form
)

PEN
10-28-2009, 06:24 PM
I also can't get it to display correctly when using file in. So there is just about no way so far to get this to work out, I can't even run it with the Max script run command and have it show up transparent.

Can any one confirm this?

denisT
10-28-2009, 09:11 PM
well... if we can't do anything without c#'s help just ask c# for this help :)


global WindowWrapper
(
fn getWindowWrapper =
(
source = ""
source += "using System;\n"
source += "using System.Windows.Forms;\n"
source += "public class WindowWrapper : IWin32Window\n"
source += "{\n"
source += " public WindowWrapper(IntPtr handle) { _hwnd = handle; }\n"
source += " public WindowWrapper(Int32 handle) { _hwnd = (IntPtr)handle; }\n"
source += " public IntPtr Handle { get { return _hwnd; } }\n"
source += " private IntPtr _hwnd;\n"
source += "}\n"
-- Compile on fly
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
compilerParams.GenerateInMemory = on
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)

compilerResults.CompiledAssembly
)
try(form.close())catch()

if WindowWrapper == undefined do
(
getWindowWrapper()
WindowWrapper = dotnetobject "WindowWrapper" (windows.getMAXHWND())
)
fn formPaint sender arg=
(
rec = dotNetObject "system.drawing.rectangle" 2 2 200 200
bgColor = (dotNetClass "system.drawing.color").red
brush = dotnetobject "System.Drawing.SolidBrush" bgColor
arg.graphics.FillRectangle brush rec
)
-- form = dotNetObject "MaxCustomControls.MaxForm"
form = dotNetObject "Form"
dotnet.addEventHandler form "paint" formPaint
form.AllowTransparency = true
form.opacity = 10
form.TransparencyKey = (dotNetClass "system.drawing.color").fromArgb 0 255 0
form.FormBorderStyle = form.FormBorderStyle.none
form.ShowInTaskBar = false
form.BackColor = (dotNetClass "system.drawing.color").fromArgb 0 255 0
--form.showmodeless()
--form.show()
form.show(WindowWrapper) -- Shows the form with the specified owner (MAX) to the user
)
--dotnet.setLifeTimeControl form #dotNet

Light
10-28-2009, 09:21 PM
I think you could also do the same like so:

local MainForm = DotNetObject "MaxCustomControls.MaxForm"
local p = DotNetObject "System.IntPtr" ( Windows.GetMAXHWND() )
local maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" p
MainForm.Show ( maxHwnd )




Light

denisT
10-28-2009, 09:31 PM
I think you could also do the same like so:

local MainForm = DotNetObject "MaxCustomControls.MaxForm"
local p = DotNetObject "System.IntPtr" ( Windows.GetMAXHWND() )
local maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" p
MainForm.Show ( maxHwnd )




Light

great! i don't have time to check all new methods of all new max dlls

but it works for dotnetobject "Form" only

(
form = dotNetObject "Form"
p = DotNetObject "System.IntPtr" ( Windows.GetMAXHWND() )
maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" p -- I like it!
form.Show ( maxHwnd )
)

Light
10-28-2009, 09:37 PM
great! i don't have time to check all new methods of all new max dlls

but it works for dotnetobject "Form" only

(
form = dotNetObject "Form"
p = DotNetObject "System.IntPtr" ( Windows.GetMAXHWND() )
maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" p -- I like it!
form.Show ( maxHwnd )
)


I like your determination (:

Mine works on MaxForm too in Max 2010.




Thanks,
Light

PEN
10-29-2009, 01:29 PM
Thanks guys, I will have a poke at this later today.

MerlinEl
10-29-2009, 07:59 PM
Hi

any sugestions for 3DsMax 9 ?


form = dotNetObject "Form"
diag = dotnetclass "System.Diagnostics.Process"
app_array = diag.GetProcessesByName "3Dsmax"
app_array[1].MainWindowHandle
app_array[1].MainWindowTitle
app_array[1].Handle

hwnd = DotNetObject "IntPtr" app_array[1].MainWindowHandle

--how to convert it in to System.Windows.Forms.IWin32Window

maxHwnd = DotNetObject "System.Windows.Forms.IWin32Window" ???

form.Show ( maxHwnd )

MerlinEl
10-29-2009, 10:23 PM
p = DotNetObject "System.IntPtr" ( Windows.GetMAXHWND() )
c = dotNetclass "System.Windows.Forms.Control"

maxHwnd = ctrl.FromHandle c


listener: undefined


why ?

denisT
10-29-2009, 10:35 PM
Hi

any sugestions for 3DsMax 9 ?


form = dotNetObject "Form"
diag = dotnetclass "System.Diagnostics.Process"
app_array = diag.GetProcessesByName "3Dsmax"
app_array[1].MainWindowHandle
app_array[1].MainWindowTitle
app_array[1].Handle

hwnd = DotNetObject "IntPtr" app_array[1].MainWindowHandle

--how to convert it in to System.Windows.Forms.IWin32Window

maxHwnd = DotNetObject "System.Windows.Forms.IWin32Window" ???

form.Show ( maxHwnd )



"MaxCustomControls.Win32HandleWrapper" dotnet object was added to max 2010 ...
you can use my c# solution for 2009 (see above)

MerlinEl
10-29-2009, 10:43 PM
Hi Denis this function is cool! How can I mis it again :p

fn getWindowWrapper =
(
source = ""
source += "using System;\n"
source += "using System.Windows.Forms;\n"
source += "public class WindowWrapper : IWin32Window\n"
source += "{\n"
source += " public WindowWrapper(IntPtr handle) { _hwnd = handle; }\n"
source += " public WindowWrapper(Int32 handle) { _hwnd = (IntPtr)handle; }\n"
source += " public IntPtr Handle { get { return _hwnd; } }\n"
source += " private IntPtr _hwnd;\n"
source += "}\n"
-- Compile on fly
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
compilerParams.GenerateInMemory = on
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)

compilerResults.CompiledAssembly
)


Thanks Man


Global mc2ViewportRecorderDialog
Global WindowWrapper
if mc2ViewportRecorderDialog != undefined do destroyDialog mc2ViewportRecorderDialog
rollout mc2ViewportRecorderDialog "rec" width:304 height:24
(
local dMove = false, DmPos, frame_min = [100,100], frame_max = [2048,2048]
local netDMove = false, netDmPos, netform
button btn_rec "R" pos:[0,0] width:24 height:24 --images:(mc2Call.getIcon 172) tooltip:"Start Reco"
button btn_stop "S" pos:[24,0] width:24 height:24 --images:(mc2Call.getIcon 171) tooltip:"Stop Record"
button btn_play "P" pos:[48,0] width:24 height:24
label lbl1 "FPS:" pos:[76,4] width:24 height:12
spinner spn_fps "" pos:[104,4] width:52 height:16 range:[1,45,4] type:#integer scale:1
label lbl2 "W:" pos:[160,4] width:16 height:12
spinner spn_w "" pos:[176,4] width:52 height:16 range:[frame_min.x,frame_max.x,280] type:#integer scale:1
label lbl3 "H:" pos:[236,4] width:16 height:12
spinner spn_h "" pos:[248,4] width:52 height:16 range:[frame_min.y,frame_max.y,180] type:#integer scale:1
fn getWindowWrapper = --made by DenisT :-)
(
print "compile WindowWrapper"

source = ""
source += "using System;\n"
source += "using System.Windows.Forms;\n"
source += "public class WindowWrapper : IWin32Window\n"
source += "{\n"
source += " public WindowWrapper(IntPtr handle) { _hwnd = handle; }\n"
source += " public WindowWrapper(Int32 handle) { _hwnd = (IntPtr)handle; }\n"
source += " public IntPtr Handle { get { return _hwnd; } }\n"
source += " private IntPtr _hwnd;\n"
source += "}\n"
-- Compile on fly
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
compilerParams.GenerateInMemory = on
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)

compilerResults.CompiledAssembly
)
fn resizing ctrl arg =
(
--mc2system.show ctrl
--ctrl.MouseButtons
--ctrl.MousePosition
mc2ViewportRecorderDialog.spn_w.value = ctrl.Width
mc2ViewportRecorderDialog.spn_h.value = ctrl.Height
--netform.Location =dotNetObject "System.Drawing.Point" 200 300
)
fn updateFrameSize axis val =
(
case axis of
(
#x:(netform.Width = val)
#y:(netform.Height = val)
)
)
fn updateFramePos dia_pos: =
(
if dia_pos == unsupplied do dia_pos = getDialogPos mc2ViewportRecorderDialog
netform.Location = dotNetObject "System.Drawing.Point" (dia_pos.x) (dia_pos.y+mc2ViewportRecorderDialog.height+6)
)
fn dragFrame ctrl arg =
(
if netDMove do
(
local netDPos = [ctrl.MousePosition.x, ctrl.MousePosition.y] - netDmPos
netform.Location = dotNetObject "System.Drawing.Point" netDPos.x netDPos.y
)
)
fn enableDrag =
(
format "dia pos :%\t dia m pos:%\tscreen m pos:%\n" [netform.Location.x, netform.Location.y] [netform.MousePosition.x, netform.MousePosition.y] mouse.screenpos
netDmPos = [netform.MousePosition.x, netform.MousePosition.y] - [netform.Location.x, netform.Location.y]
netDMove = true
--.Cursor : <System.Windows.Forms.Cursor>
)
fn disableDrag = (netDMove = false)
fn createFrame =
(
if WindowWrapper == undefined do
(
getWindowWrapper()
WindowWrapper = dotnetobject "WindowWrapper" (windows.getMAXHWND())
print WindowWrapper
)
try( netform.close(); netform.dispose() )catch()

local color_class = (dotnetclass "System.Drawing.Color")
netform = dotnetobject "System.Windows.Forms.Form"
netform.width = 200
netform.height = 200
netform.MinimumSize = dotNetObject "System.Drawing.Size" frame_min.x frame_min.y
netform.MaximumSize = dotNetObject "System.Drawing.Size" frame_max.x frame_max.y
--netform.TopMost = true --always top on all
netform.ShowInTaskbar = false --hide from windows task bar
netform.ControlBox = false --hide main bar
netform.backColor = color_class.fromArgb 0 255 0 --form Back Color
--netform.TransparencyKey = color_class.fromArgb 0 255 0 --form Back Color
netform.opacity = 0.5

--.Controls : <System.Windows.Forms.Control+ControlCollection>, read-only

--mc2system.show netform
dotNet.addEventHandler netform "SizeChanged" resizing
dotNet.addEventHandler netform "MouseMove" dragFrame
dotNet.addEventHandler netform "MouseDown" enableDrag
dotNet.addEventHandler netform "MouseUp" disableDrag

netform.Show ( WindowWrapper )

updateFramePos()
)
on mc2ViewportRecorderDialog rbuttonup pos do (destroyDialog mc2ViewportRecorderDialog)
-->MoveMode
on mc2ViewportRecorderDialog lbuttondown pos do (dMove = true; DmPos = pos; if not keyboard.shiftPressed do pushprompt "Pres Shift To Move...")
on mc2ViewportRecorderDialog lbuttonup pos do (dMove = false; pushprompt "")
on mc2ViewportRecorderDialog mouseMove pos do
(
if dMove and keyboard.shiftPressed do
(
setDialogPos mc2ViewportRecorderDialog (mouse.screenpos - DmPos)
)
)
on mc2ViewportRecorderDialog open do
(
createFrame()
)
on mc2ViewportRecorderDialog close do try( netform.close(); netform.dispose() )catch()
on mc2ViewportRecorderDialog moved pos do (updateFramePos dia_pos:pos)
on spn_w changed val do (updateFrameSize #x val)
on spn_h changed val do (updateFrameSize #y val)
on btn_rec pressed do
(
netform.backColor = color_class.fromArgb 0 255 0 --form Back Color
netform.TransparencyKey = netform.backColor
)
on btn_stop pressed do
(
--netform.backColor= color_class.fromArgb 0 255 0 --form Back Color
netform.TransparencyKey = undefined
)
)

createDialog mc2ViewportRecorderDialog pos:[200,200] style:#(#style_border)

Light
10-30-2009, 12:30 AM
"MaxCustomControls.Win32HandleWrapper" dotnet object was added to max 2010 ...
you can use my c# solution for 2009 (see above)

Actually it's added in Max 2008.




Cheers,
Light

denisT
10-30-2009, 12:55 AM
Actually it's added in Max 2008.




Cheers,
Light

it was not added for me :(... eh...

PEN
10-30-2009, 01:10 AM
Nice work guys. I still have yet to poke at it with my stick but I hope to get back to this part of the project tomorrow.

LoneRobot
10-30-2009, 11:23 AM
Hope i got the right end of the stick here Paul. there could be a few things going on here form what i can work out.

If you use a windows.forms.form object, you can use the transparency key to set the client window to transparent. You have this working already with your code. The transparent color is matted out on the backgorund of the form, leaving you to paint the
contents. However, because you are using the paint event to draw things onto the form, and even when supplying a see-through brush color it doesnt appear to give the painted controls a seethrough quality. This is because the form seems to blend the resultant color with the color supplied as the form's transparency key. Even though the form itself is see-through, if for example you use red as a form transparency key and put a yellow square at 50% alpha in the paint event, all you will end up with is an orange square on a transparent form, as it creates a color blend between the two. The bummer is a form won't support using the transparent color as a background color.

Setting a form's opacity to anything above 1 will not work, despite visual studio asking for a percentage, your values specified need to be between 0 and 1.

However, this didnt seem to work when used with a maxform. Maxform automatically gets the background color of the maxUI and paints this on the form. In VB you can prevent the form background painting itself by overideing the protected sub onBackgroundPaint. However I dont know if this is it here. Again you can set the maxform opacity to values between 0 and 1 but not the abilty to make the painted contents a different opacity level.

one option might be to mask the area of the form you need to hide, then use the opacity to blend the form's drawn controls with the background viewport seen through it. You can do this by creating a region object (either from a rectangle or a graphics path if you need more compicated shapes - check my GDI+ framework for examples) You could in theory have a sub that calculates the path and then uses the same coordinates in the paint handler i guess. The thing about using a region means you do however need to build some form of movement into the control by click-dragging the client area, so far I havent been able to do this in max, only in VS by inherting a form object and adding the code into the class. humph.

(
try(form.close())catch()


fn formPaint sender arg=
(
-- arg.graphics.clear((dotNetClass "system.drawing.color")fromargb 255 255 255)
rec=dotNetObject "system.drawing.rectangle" 2 2 200 200
bgColor=(dotNetClass "system.drawing.color").fromargb 255 255 0 0
brush=dotnetobject "System.Drawing.SolidBrush" bgColor
arg.graphics.FillRectangle brush rec
)

fn clickhandler sender arg =
(
sender.close()
)

--form=dotNetObject "form"
form=dotNetObject "MaxCustomControls.MaxForm"
-- form.show()


-- form.AllowTransparency=true
form.opacity=0.5
-- form.BackColor=(dotNetClass "system.drawing.color").green
-- form.TransparencyKey=(dotNetClass "system.drawing.color").green
-- form.ShowInTaskBar =false
form.FormBorderStyle=form.FormBorderStyle.none
-- form.TopMost=true

dotnet.addEventHandler form "paint" formPaint
dotnet.addEventHandler form "click" clickhandler
dotnet.setLifeTimeControl form #dotNet

cliprect=dotNetObject "system.drawing.rectangle" 2 2 200 200
formregion =dotnetobject "system.drawing.Region" clipRect
form.Region = formregion

form.showmodeless()
)

PEN
10-30-2009, 12:03 PM
Thanks Pete. It is indeed the blending of the BG color with the transparency value of the painted color, you can really see this when you change the blending methods. I think that I have another possible solution to the transparency and that is to draw in a label that is the same size as the form and use it as a sort of layer. It isn't exactly what I want but it will be close enough. I can paint the items that I want to have a tranparency into a base layer and the items that I don't want in a layer above.

PEN
11-03-2009, 03:15 PM
I think you could also do the same like so:

local MainForm = DotNetObject "MaxCustomControls.MaxForm"
local p = DotNetObject "System.IntPtr" ( Windows.GetMAXHWND() )
local maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" p
MainForm.Show ( maxHwnd )
Light

Well this is just fantastic. I tried getting DotNetObject "System.IntPtr" ( Windows.GetMAXHWND() ) to work early in my test but just got errors. I guess I was just doing it wrong but at least I was on the right track. Is MaxCustomControls in the SDK help as it is not in the Max script help at all. I should be able to get this tool complete, not something that I can release to the public as it is very specific to this project but I will release some screen grabs so you can see where I have been going with it all.

Thanks for every ones help.

PEN
11-03-2009, 04:34 PM
The last thing that I thought I had an answer for and it turns out that I don't is the transparent problem. I figured I could use a label as a sort of layer and make it transparent or not but it also shows the same problems as the drawing methods.

Any one have any other ideas on this?

PEN
11-03-2009, 07:05 PM
Here is another problem with the transparencies. Notice that even though the top label is transparent it only shows the form below, not the other label below it. Looks like the transparency of a control is only transparent to its parent form.


try(form.close())catch()

solidBrush1=(dotnetobject "System.Drawing.SolidBrush" ((dotNetClass "system.drawing.color").fromArgb 255 0 0))
solidBrush2=(dotnetobject "System.Drawing.SolidBrush" ((dotNetClass "system.drawing.color").fromArgb 0 255 0))

form=dotNetObject "form"

fn lb1Paint sender arg=
(
arg.graphics.fillRectangle solidBrush1 (dotNetObject "system.drawing.rectangle" 0 0 20 20)
)
fn lb2Paint sender arg=
(
arg.graphics.fillRectangle solidBrush2 (dotNetObject "system.drawing.rectangle" 20 20 20 20)
)


lb1=dotNetObject "label"
lb1.bounds=dotNetObject "system.drawing.rectangle" 0 0 200 200
lb1.backColor=(dotNetClass "system.drawing.color").fromArgb 255 0 0
dotNet.addEventHandler lb1 "paint" lb1Paint

lb2=dotNetObject "label"
lb2.bounds=dotNetObject "system.drawing.rectangle" 0 0 200 200
lb2.backColor=(dotNetClass "system.drawing.color").fromArgb 0 0 0 0
dotNet.addEventHandler lb2 "paint" lb2Paint

form.controls.add lb2
form.controls.add lb1

form.show()

PEN
11-03-2009, 07:08 PM
This is the only way that I can see layers of drawing if any one is interested.


try(form.close())catch()

solidBrush1=(dotnetobject "System.Drawing.SolidBrush" ((dotNetClass "system.drawing.color").fromArgb 255 0 0))
solidBrush2=(dotnetobject "System.Drawing.SolidBrush" ((dotNetClass "system.drawing.color").fromArgb 0 255 0))
solidBrush3=(dotnetobject "System.Drawing.SolidBrush" ((dotNetClass "system.drawing.color").fromArgb 0 0 255))

form=dotNetObject "form"

fn lb1Paint sender arg=
(
arg.graphics.fillRectangle solidBrush1 (dotNetObject "system.drawing.rectangle" 0 0 20 20)
)
fn lb2Paint sender arg=
(
arg.graphics.fillRectangle solidBrush2 (dotNetObject "system.drawing.rectangle" 20 20 20 20)
)
fn lb3Paint sender arg=
(
arg.graphics.fillRectangle solidBrush3 (dotNetObject "system.drawing.rectangle" 40 40 20 20)
)


lb1=dotNetObject "label"
lb1.bounds=dotNetObject "system.drawing.rectangle" 0 0 200 200
lb1.backColor=(dotNetClass "system.drawing.color").fromArgb 0 0 0 0
dotNet.addEventHandler lb1 "paint" lb1Paint

lb2=dotNetObject "label"
lb2.bounds=dotNetObject "system.drawing.rectangle" 0 0 200 200
lb2.backColor=(dotNetClass "system.drawing.color").fromArgb 0 0 0 0
dotNet.addEventHandler lb2 "paint" lb2Paint

lb3=dotNetObject "label"
lb3.bounds=dotNetObject "system.drawing.rectangle" 0 0 200 200
lb3.backColor=(dotNetClass "system.drawing.color").fromArgb 0 0 0 0
dotNet.addEventHandler lb3 "paint" lb3Paint

form.controls.add lb1
lb1.controls.add lb2
lb2.controls.add lb3

form.show()

denisT
11-03-2009, 07:33 PM
you can parent the form to max:

maxw = dotnetobject "MaxCustomControls.Win32HandleWrapper" (dotnetobject "System.IntPtr" (Windows.GetMAXHWND()))
form.show(maxw)


it works for me

PEN
11-03-2009, 07:39 PM
Thanks Dennis, not sure what worked for you. I am doing that in my code how ever I'm also trying to get transparencies to work one on top of the other with labels. If one label in on top of another the one below will not show even if the top one is transparent.

denisT
11-03-2009, 07:58 PM
probably I don't understand how it supposes to be... could you show some image with desired result?

PEN
11-03-2009, 08:32 PM
Just run the last chunk of code that I posted, that is what I want but notice that each label has to be added to the previous to be able to see each rectangle that is being drawn in each. If I add each label to the form directly they over draw each other.

PEN
11-03-2009, 08:49 PM
Another interesting find is that a form that is open over the Max viewport with nothing in it but transparent slows the Max viewport FPS down considerably. Any one know why?

CGTalk Moderation
11-03-2009, 08:50 PM
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.