我有一个使用 WinForms 的跨平台 .NET 应用程序。
为了更好地与 Unity 兼容,我想设置 WM_CLASS
WinForms 窗口的属性。这可能吗?
最佳答案
在这里似乎有完整的示例项目 bitbucket.org/hindlemail/settingwmclass :
Example project showing how to set the WM_CLASS X11 property for a mono winform application running on Linux. This makes mono winforms applications behave better with the unity + gnome3 window managers.
// Managed struct of XSetClassHint classHint.
public struct XClassHint
{
public IntPtr res_name;
public IntPtr res_class;
}
[DllImport ("libX11", EntryPoint="XSetClassHint", CharSet=CharSet.Ansi)]
public extern static int XSetClassHint(IntPtr display, IntPtr window, IntPtr classHint);
public static void SetWmClass(string name, string @class, IntPtr handle)
{
var a = new NativeX11Methods.XClassHint {
res_name = Marshal.StringToCoTaskMemAnsi(name),
res_class = Marshal.StringToCoTaskMemAnsi(@class)
};
IntPtr classHints = Marshal.AllocCoTaskMem(Marshal.SizeOf(a));
Marshal.StructureToPtr(a, classHints, true);
NativeX11Methods.XSetClassHint(NativeReplacements.MonoGetDisplayHandle(), NativeReplacements.MonoGetX11Window(handle), classHints);
Marshal.FreeCoTaskMem(a.res_name);
Marshal.FreeCoTaskMem(a.res_class);
Marshal.FreeCoTaskMem(classHints);
}
以上页面有download link to the source code :
关于.net - 如何在 Linux 上更改 WinForms 应用程序的 WM_CLASS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11453687/