Notifications
Clear all

[Closed] Blocking WPF Window

 MZ1

When I create a WPF window like this:

WPFWindow = dotnetobject "System.windows.Window"
WPFWindow.showintaskbar = false
WPFWindow.show()
(dotnetobject "System.Windows.Interop.WindowInteropHelper" WPFWindow).owner = dotnetobject "IntPtr" (windows.getMAXHWND())

Everything works fine, except when max modal dialog shows up, WPF window wouldn’t be (freezed) blocked. Is it possible to change WPF window behave like other max windows when max dialogs shows up?

4 Replies

first of all you have to make wpf window a child of max window:

wpf_hwnd = (dotnetobject "System.Windows.Interop.WindowInteropHelper" wpfwindow).handle	
max_hwnd = windows.GetMaxHWND()
	
_user32.setparent wpf_hwnd max_hwnd

where user32.setparent is something like:

global _user32 =
(
	source = "using System;
"
	source += "using System.Runtime.InteropServices;
"
	source += "class User32
"
	source += "{
"
	source += " [DllImport(\"user32.dll\")]
"
	source += " public static extern IntPtr SetParent(Int64 hWndChild, Int64 hWndNewParent);
"
	source += "}
"

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

	compilerParams.ReferencedAssemblies.AddRange #("System.dll")

	compilerParams.GenerateInMemory = true
	compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
	
	_user32Assembly = compilerResults.CompiledAssembly
	_user32Assembly.CreateInstance "User32"
)

after that we have to figure out what to do with its clipping… i don’t know yet

1 Reply
 MZ1
(@mz1)
Joined: 1 year ago

Posts: 0

Yea, It’s really bad. what about SetWindowLong function? doesn’t help? I just tested but got nothing:

fn CompileCSharp Source ClassName =
(
	csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
	compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
	compilerParams.GenerateInMemory = on
	compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
	assembly = compilerResults.CompiledAssembly
	assembly.CreateInstance ClassName
)

DN_User32 =
(
	source = "using System;
"
	source += "using System.Runtime.InteropServices;
"
	source += "class User32
"
	source += "{
"
	source += " [DllImport(\"User32\", CharSet=CharSet.Auto, ExactSpelling=true)]
"
	source += " public static extern IntPtr SetParent(Int64 hWndChild, Int64 hWndParent);
"
	source += "}
"
	CompileCSharp source "User32"
)

DN_WindowLong = 
(
	source = "using System;
"
	source += "using System.Runtime.InteropServices;
"
	source += "class WindowLong
"
	source += "{
"
	source += "const int GWL_STYLE = -16;
"
	source += "const UInt32 WS_POPUP = 0x80000000;
"
	source += "const UInt32 WS_CHILD = 0x40000000;
"
	source += "[DllImport(\"user32.dll\", SetLastError = true)]
"
	source += "static extern UInt32 GetWindowLong(Int64 hWnd, int nIndex);
"
	source += "[DllImport(\"user32.dll\")]
"
	source += "static extern int SetWindowLong(Int64 hWnd, int nIndex, UInt32 dwNewLong);
"
	source += "public static void SetWinLong(Int64 hWnd)
"
	source += "{
"
	source += "       SetWindowLong(hWnd, GWL_STYLE, ((GetWindowLong(hWnd, GWL_STYLE) & ~(WS_POPUP)) | WS_CHILD));
"
	source += "}
"
	source += " }
"
	CompileCSharp source "WindowLong"
)

WPFWindow = dotnetobject "System.windows.Window"
WPFWindow.show()
Wpf_hwnd = (dotnetobject "System.Windows.Interop.WindowInteropHelper" WPFWindow).handle	
Max_hwnd = windows.GetMaxHWND()
DN_User32.Setparent Wpf_hwnd Max_hwnd
DN_WindowLong.SetWinLong Wpf_hwnd

 MZ1

This might be a solution , but doesn’t work for me either , changing RendeMode of the window in c#:

this.Loaded += delegate
{
    var source = PresentationSource.FromVisual(this);
    var hwndTarget = source.CompositionTarget as HwndTarget;

    if (hwndTarget != null)
    {
        hwndTarget.RenderMode = RenderMode.SoftwareOnly;
    }
};