public static iWindowAttribute Add(string title, iWindow win, bool visible = true, bool canDock = true, bool register2menu = true) { uint uuid = s_uuid++; WindowAttribute attr = new WindowAttribute(); attr.window = win; attr.UUID = uuid; attr.title = title; attr.visible = visible; attr.canDock = canDock; attr.register2menu = register2menu; pool.Add(uuid, attr); if (visible) { ShowWindow(uuid); } else { CloseWindow(uuid); } win.Init(); return(attr); }
public static int GetWindowAttribute(WindowHandle window, WindowAttribute attribute) { var value = glfwGetWindowAttrib(window, attribute); CheckError(nameof(GetWindowAttribute)); return(value); }
/// <summary> /// 初始化 /// </summary> /// <param name="assemblyName">窗口类所在的程序集</param> public void Initialize(string assemblyName) { if (string.IsNullOrEmpty(assemblyName)) { throw new ArgumentNullException(); } _assemblyName = assemblyName; List <Type> types = AssemblyUtility.GetAssignableAttributeTypes(assemblyName, typeof(UIWindow), typeof(WindowAttribute)); for (int i = 0; i < types.Count; i++) { System.Type type = types[i]; WindowAttribute attribute = Attribute.GetCustomAttribute(type, typeof(WindowAttribute)) as WindowAttribute; // 判断是否重复 if (_types.ContainsKey(attribute.WindowType)) { throw new Exception($"Window type {attribute.WindowType} already exist."); } // 添加到集合 _types.Add(attribute.WindowType, type); } }
public static int GetWindowAttribute(WindowPtr window, WindowAttribute attrib) { var result = glfwGetWindowAttrib(window, attrib); CheckError(); return(result); }
// Gets a rectangle value for the given attribute private Rectangle GetRectangleValue(WindowAttribute attribute) { // Stores the result Rectangle result = new Rectangle(); // Native API call DwmGetWindowAttribute(hwndForm, attribute, out result, Marshal.SizeOf(result)); return(result); }
// Gets a boolean value for the specified attribute private bool GetBoolValue(WindowAttribute attribute) { // Stores the result bool result; // Native API call DwmGetWindowAttribute(hwndForm, attribute, out result, sizeof(int)); return(result); }
private void LoadPlugins() { //плагины string pluginPath = Path.Combine(Directory.GetCurrentDirectory(), "Plugins"); DirectoryInfo pluginDirect = new DirectoryInfo(pluginPath); //if (!pluginDirect.Exists) //{ pluginDirect.Create(); } //берем все dll var pluginFiles = Directory.GetFiles(pluginPath, "*.dll"); foreach (var file in pluginFiles) { //загружаем сборку Assembly asm = Assembly.LoadFrom(file); //Ищем типы //type of plugin is AssignableFrom var types = asm.GetTypes().Where(t => t.GetInterfaces().Where(j => j.FullName == typeof(FormInterface).FullName).Any()); foreach (var type in types) { var form = asm.CreateInstance(type.FullName) as Form; form.MdiParent = this; form.StartPosition = FormStartPosition.Manual; object[] attributes = type.GetCustomAttributes(typeof(WindowAttribute), inherit: true); if (attributes.Length != 0) { WindowAttribute windowAttribute = (WindowAttribute)attributes[0]; form.Dock = windowAttribute.Dock; } FieldInfo[] fields = type.GetFields(); foreach (FieldInfo field in fields) { attributes = field.GetCustomAttributes(typeof(WindowAttribute), inherit: true); if (attributes.Length != 0) { WindowAttribute windowAttribute = (WindowAttribute)attributes[0]; Control butt = field.GetValue(form) as Control; butt.Dock = windowAttribute.Dock; } } form.Show(); } } }
/// <summary> /// 创建类的实例 /// </summary> /// <param name="windowType">窗口类型</param> /// <returns>如果类型没有在程序集里定义会发生异常</returns> public UIWindow CreateInstance(EWindowType windowType) { UIWindow window = null; if (_types.TryGetValue(windowType, out Type type)) { WindowAttribute attribute = Attribute.GetCustomAttribute(type, typeof(WindowAttribute)) as WindowAttribute; window = (UIWindow)Activator.CreateInstance(type); window.Init(attribute.WindowType, attribute.WindowLayer); } if (window == null) { throw new KeyNotFoundException($"{nameof(UIWindow)} {windowType} is not define in assembly {_assemblyName}"); } return(window); }
/// <summary> /// Changes an attribute for the specified window. /// </summary> /// <param name="hWnd">A handle to the window and, indirectly, the class to which the window belongs.</param> /// <param name="attribute">An enumeration value that specifies the window attribute to replace.</param> /// <param name="dwNewLong">The replacement value.</param> /// <returns></returns> public static IntPtr SetWindowLongPtr(IntPtr hWnd, WindowAttribute attribute, IntPtr dwNewLong) => IntPtr.Size == 4 ? SetWindowLongPtr32(hWnd, (int)attribute, dwNewLong) : SetWindowLongPtr64(hWnd, (int)attribute, dwNewLong);
public static extern void SetWindowAttrib(Window window, WindowAttribute attrib, bool value);
public static extern int GetWindowAttrib(IntPtr window, WindowAttribute attrib);
private static extern void DwmSetWindowAttribute(IntPtr hwnd, WindowAttribute attribute, ref int attributeValue, int attributeSize);
private static extern int DwmSetWindowAttribute(IntPtr hwnd, WindowAttribute dwAttribute, ref object pvAttribute, int pvAttributeSize);
public static extern int DwmSetWindowAttribute(IntPtr hwnd, WindowAttribute dwAttribute, ref bool pvAttribute, int cbAttribute);
public static extern int GetWindowAttrib(Window window, [MarshalAs(UnmanagedType.I4)] WindowAttribute attribibute);
public static bool Contains(this WindowAttribute atr1, WindowAttribute atr2) { return((atr1 & atr2) == atr2); }
public static void SetWindowAttribute(WindowHandle window, WindowAttribute attribute, bool value) { glfwSetWindowAttrib(window, attribute, value ? 1 : 0); CheckError(nameof(SetWindowAttribute)); }
public static void SetWindowCreationHint(WindowAttribute hint, int value) { SetWindowCreationHint((WindowCreationHint)hint, value); }
public static void SetWindowCreationHint(WindowAttribute hint, bool value) { SetWindowCreationHint((WindowCreationHint)hint, value ? 1 : 0); }
// Sets an int value for the specified attribute private void SetIntValue(WindowAttribute attribute, ref int value) { // Native API call DwmSetWindowAttribute(hwndForm, attribute, ref value, sizeof(int)); }
// Gets a rectangle value for the given attribute private Rectangle GetRectangleValue(WindowAttribute attribute) { // Stores the result Rectangle result = new Rectangle(); // Native API call DwmGetWindowAttribute(hwndForm, attribute, out result, Marshal.SizeOf(result)); return result; }
// Gets a boolean value for the specified attribute private bool GetBoolValue(WindowAttribute attribute) { // Stores the result bool result; // Native API call DwmGetWindowAttribute(hwndForm, attribute, out result, sizeof(int)); return result; }
public static extern int glfwGetWindowAttrib(WindowPtr window, WindowAttribute attrib);
/// <summary> /// Retrieves information about a specified window. /// </summary> /// <param name="hWnd">A handle to the window and, indirectly, the class to which the window belongs.</param> /// <param name="attribute">An enumeration value that specifies the window attribute to retrieve.</param> /// <returns>The requested value if successful; otherwise, zero.</returns> public static IntPtr GetWindowLongPtr(IntPtr hWnd, WindowAttribute attribute) => IntPtr.Size == 4 ? GetWindowLongPtr32(hWnd, (int)attribute) : GetWindowLongPtr64(hWnd, (int)attribute);
private static extern void glfwSetWindowAttrib(WindowHandle window, WindowAttribute attribute, int value);
public static extern void glfwSetWindowAttrib(Window *window, WindowAttribute attrib, int value);
private static extern void DwmGetWindowAttribute(IntPtr hwnd, WindowAttribute attribute, out Rectangle attributeValue, int attributeSize);
public static extern void WindowHint(WindowAttribute hint, int value);
private static extern int glfwGetWindowAttrib(WindowHandle window, WindowAttribute attribute);