C#在MXS

这是一种不优雅的书写方式, 更推荐封装好dll调用

(
	fn Compile =
	(
		src  = "using System;\n"
		src += "using System.Threading;\n"
		src += "using System.Threading.Tasks;\n"
		src += "using System.Windows.Forms;\n"
		src += "public static class ThreadForm\n"
		src += "{\n"
		src += "	public static Thread Show (Form form)\n"
		src += "	{\n"
		src += "		Thread thread = new Thread(() => form.ShowDialog());\n"
		src += "		thread.SetApartmentState(ApartmentState.STA);\n"
		src += "		thread.Start();\n"
		src += "		Task.Delay(100).Wait();\n"
		src += "		return (thread);\n"
		src += "	}\n"
		src += "	public static Thread ShowAsChild (Form form, IntPtr hwnd)\n"
		src += "	{\n"
		src += "		NativeWindow nw = new NativeWindow();\n"
		src += "		nw.AssignHandle (hwnd);\n"
		src += "		Thread thread = new Thread(() => form.ShowDialog(nw));\n"
		src += "		thread.Start();\n"
		src += "		Task.Delay(100).Wait();\n"
		src += "		return (thread);\n"
		src += "	}\n"
		src += "}"
		
		params = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
		params.ReferencedAssemblies.Add "System.dll"
		params.ReferencedAssemblies.Add "System.Windows.Forms.dll"
		
		result = (dotnetobject "Microsoft.CSharp.CSharpCodeProvider").CompileAssemblyFromSource params #(src)
		result.CompiledAssembly
	)
	
	Compile()
	
	form = dotnetobject "System.Windows.Forms.Form"
	form.ShowInTaskbar = false
	
	-- NOT AS MAX CHILD
	thread = (dotnetclass "ThreadForm").Show form
	
	-- AS MAX CHILD
-- 	hwnd = dotnetobject "system.intptr" (windows.getMAXHWND())
-- 	thread = (dotnetclass "ThreadForm").ShowAsChild form hwnd
)

评论0

请先

没有账号? 注册  忘记密码?

社交账号快速登录