Notifications
Clear all

[Closed] Get Dialog Position – Render Scene Dialog

Is there some hWnd flag for getting dialog positions? I want to work out where my Render Scene Dialog window is via script…

10 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

what is your Render Scene Dialog?
are you talking about Render Setup Dialog?
to get its hwnd you have to identify and find it first…
its title text might differ depending on the current renderer, but it keeps “Render Setup:” at the begging. so we can find it by doing something like:


 for hwnd in uiaccessor.getpopupdialogs() where (text = uiaccessor.getwindowtext hwnd) != undefined and matchpattern text pattern:"Render Setup:*" do exit with hwnd
 

I presume you have tried Pete(lonerobot) tool

if you want to support any (not just English) versions of max probably you can search by dll filename… but i’m not sure it will work for hieroglyph language systems.
just in case the dll filename is res3.dll

as someone noticed max 2014 has built-in function getWindowPos (or some similar name)
for earlier versions you have to use precompiled one. you can find some samples on this forum.
for example http://forums.cgsociety.org/showpost.php?p=7108679&postcount=9

This one…
RenderSceneDialog.open()

local hWnd = (for w in windows.GetChildrenHwnd 0  where matchPattern w[5] pattern:"Render Setup:*" collect w[1])[1]

This gets me the hWnd for the window, and I can set the position (max 2013) using…

fn createAssembly =
	(		
		str="using System;
"
		str+="using System.Runtime.InteropServices;
"
		str+="namespace Win32Helper
"
		str+="{
"
		str+="	class Win32HelperClass
"
		str+="	{
"		
		str+="		[DllImport(\"user32.dll\")]
"
		str+="		[return: MarshalAs(UnmanagedType.Bool)]
"
		str+="		public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
"
		str+="	}
"
		str+="}
"

		local csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
		local compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
		compilerParams.ReferencedAssemblies.addRange #("System.dll")
		compilerParams.GenerateInMemory = on
		local compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(str)
		
		for er = 0 to compilerResults.errors.count-1 do print (compilerResults.errors.item[er].tostring())
		return compilerResults.CompiledAssembly.createInstance "Win32Helper.Win32HelperClass"
	)
	
	local win32Helper = createAssembly()

and

win32Helper.setWindowPos hWndIntPtr 0 500 100 0 0 1

I just hoped there was an easier way to get the window position. There is a significant lag with the Render Scene Dialog checking licenses when it opens and I’d prefer to have a macroscript that just moves it off screen and brings it back into position bypassing the need to check the license every time. May sound like a small thing but will make a big difference especially in the heat of the moment at deadline time.

Of course I need to store the position so when I bring it back it pops back into the right place.

you are doing everything right. i don’t see an easier way by using mxs.

using WH_CTB window hook you theoretically can open any dialog at any place by hooking HCBT_MOVESIZE message.

Opening, setting the position is fine… I need to return a point 2 value for x and y screen positions of an opened dialog…

I’m trying to put some C# code in to do this but I’m not even sure where to go to find out what the method should be called…

I thought it would be something like this… but not sure what I should be doing…

str="using System;
"
		str+="using System.Runtime.InteropServices;
"
		str+="namespace Win32Helper
"
		str+="{
"
		str+="	class Win32HelperClass
"
		str+="	{
"		
		str+="		[DllImport(\"user32.dll\")]
"
		str+="		[return: MarshalAs(UnmanagedType.Bool)]
"
		str+="		public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
"
		str+="	}
"
		str+="	class Win32HelperClass
"
		str+="	{
"		
		str+="		[DllImport(\"user32.dll\")]
"
		str+="		[return: MarshalAs(UnmanagedType.Bool)]
"
		str+="		public static extern bool GetWindowRect(ByVal hWnd As System.IntPtr, ByRef lpRect As RECT);
"
		str+="	}
"
		str+="}
"
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

check the link that i showed couple posts above

or look at my script. Its pretty simple once you’ve registered the windowrect class. The only other way of getting anything to do with the render dialog with mxs is :

rPosArr = filterstring ( getinisetting (getMAXIniFile()) "RenderDialogPosition" "Dimension" ) " "
rPos = [rPosArr[1] as integer, rPosArr[2] as integer]

But this isn’t particularly useful, as it wont reflect the actual position, just the last time it was closed.