material editor, render setup , light lister
so it’s not possible for these
I’m curious what’s cheaper to use performance wise. SetWinEventHook or a timer that simply checks if a certain window is opened at the moment?
SetWinEventHook
global WinHook =
(
source = "using System;\n"
source += "using System.Runtime.InteropServices;\n"
source += "class WinHook\n"
source += "{
public class MsgEventArgs : EventArgs
{
public MsgEventArgs( IntPtr hwnd, uint eventType )
{
HWND = hwnd;
EventType = eventType;
}
public readonly IntPtr HWND;
public readonly uint EventType;
}
public static event EventHandler MessageEvent;
public static IntPtr hWinHook;
delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType,
IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
[DllImport(\"user32.dll\")]
static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr
hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess,
uint idThread, uint dwFlags);
[DllImport(\"user32.dll\")]
static extern bool UnhookWinEvent(IntPtr hWinEventHook);
const uint EVENT_OBJECT_CREATE = 0x8000;
const uint EVENT_SYSTEM_DESTROY = 0x8001;
const uint WINEVENT_OUTOFCONTEXT = 0;
static WinEventDelegate procDelegate = new WinEventDelegate(WinEventProc);
public static void Start( uint procID, uint threadID )
{
hWinHook = SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_SYSTEM_DESTROY, IntPtr.Zero,
procDelegate, procID, threadID, WINEVENT_OUTOFCONTEXT);
}
public static void Stop()
{
if ( hWinHook != null ) UnhookWinEvent( hWinHook );
}
static void WinEventProc(IntPtr hWinEventHook, uint eventType,
IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
{
if(idObject != 0 || idChild != 0)
{
return;
}
if ( MessageEvent != null )
{
MsgEventArgs msg = new MsgEventArgs( hwnd, eventType );
MessageEvent( null, msg );
}
}
"
source += "}\n"
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.GenerateInMemory = on
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
if (compilerResults.Errors.Count > 0 ) then
(
local errs = stringstream ""
for i = 0 to (compilerResults.Errors.Count-1) do
(
local err = compilerResults.Errors.Item[i]
format "Error:% Line:% Column:% %\n" err.ErrorNumber err.Line err.Column err.ErrorText to:errs
)
format "%\n" errs
undefined
)
else
(
compilerResults.CompiledAssembly.CreateInstance "WinHook"
)
)
fn OnMsg s ev =
(
if ev.EventType == 0x8000 do
(
format "[ create ] %: %\n" ev.HWND (windows.getHWNDData ev.hwnd)
)
if ev.EventType == 0x8001 do
(
format "[ destroy ] %: %\n" ev.HWND (windows.getHWNDData ev.hwnd)
)
)
WinHook.Stop()
dotNet.removeAllEventHandlers WinHook
proc = (dotNetClass "System.Diagnostics.Process").GetCurrentProcess()
thread = GetCurrentThreadId()
dotNet.addEventHandler WinHook "MessageEvent" OnMsg
WinHook.Start proc.ID thread