Maxscript : dialog active or inactive

Hi,

I’m creating a maxscript with a rollout and some rendering params. I would like to know if there is an event for when my script windows lost focus (become not active window anymore) and especially when it become active back to update some settings that can be change in render setup dialog.
Sort of :

rollout mySettings “mySettings”
(
–UI stuff !
on active event do mystuff()
on inactive event do mystuff2()
)
createdialog mySettings

I found some article on lostfocus and gotfocus but seems more for UI element than UI itself, if not only for dotnet UI elements :confused:

Well, there’s no such event but it doesn’t prevent you from checking yourself:

(
	fn getWindowClass =
	(
		local source  = "using System;
"
		source += "using System.Runtime.InteropServices;
"
		source += "public class Window
"
		source += "{
"
		source += "	[DllImport(\"user32.dll\")]
"
		source += "	public static extern IntPtr GetForegroundWindow();
"
		source += "}
"

		local csharpProvider = dotNetObject "Microsoft.CSharp.CSharpCodeProvider"
		local compilerParams = dotNetObject "System.CodeDom.Compiler.CompilerParameters"
		compilerParams.GenerateInMemory = true
		compilerParams.ReferencedAssemblies.Add "System.dll"
		local compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
		compilerResults.CompiledAssembly.CreateInstance "Window"
	)
	if NOT isKindOf ::window dotNetObject do window = getWindowClass()
)

try destroyDialog ::focusTest catch()
rollout focusTest "Focus Test"
(
	local prevFocus = true, currFocus = true
	timer clock interval:100
	label lblFocus "IN FOCUS"

  	on clock tick do
  	(
		currFocus = focusTest.hwnd == (window.getForegroundWindow())
		if prevFocus != currFocus do lblFocus.text = if currFocus then "IN FOCUS" else "OUT OF FOCUS"
		prevFocus = currFocus
  	)
)
createDialog focusTest

works nice, thanks.I didn’t knew clock tick either :wink:

Well - it’s only the timer called “clock” and the usual maxscript timer eventhandler is “on tick” - so this makes a nice handler signature of “on clock tick do”
But that’s quite the common thing, like “on myTimer tick do”