.net - 如何在 Linux 上更改 WinForms 应用程序的 WM_CLASS?

标签 .net winforms unity-container x11

我有一个使用 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/

相关文章:

c# - 在 FullRowSelect 模式下将 datagridview 单元格内容复制到剪贴板

c# - Unity 无法加载文件或程序集 'Microsoft.Practices.ServiceLocation,版本 = 1.2.0.0

c# - Unity IOC、AOP & 接口(interface)拦截

c# - 将相同的方法值传递给多个表单

c# - Crystal Report 仅在回发时抛出 'Failed to open the connection.'

c# - 如何在不重新启动应用程序的情况下动态加载我的 C# 应用程序的一部分?

c# - EPPlus 从数据透视表创建图表

c# - 使用 telerik 在 radForm 中更改标题栏文本颜色

mvvm - 在 Prism 应用程序的上下文中 Unity 与 MEF?

c# - C# 4.0 中的 'dynamic' 类型是做什么用的?