/// <summary> /// レイヤードウィンドウの透明度と透明のカラーキーを取得する。 /// </summary> /// <returns>レイヤードウィンドウの属性値</returns> public LayeredWindowAttribute GetLayeredWindowAttributes() { LayeredWindowAttribute attribute = new LayeredWindowAttribute(); if (this.IsLayeredWindow) { uint colorKey; byte alpha; uint flags; if (!WindowsAPI.GetLayeredWindowAttributes(this._handle, out colorKey, out alpha, out flags)) { throw new Win32Exception(); } if ((((WindowsAPI.LayeredWindowAttributes)flags) & WindowsAPI.LayeredWindowAttributes.LWA_ALPHA) == WindowsAPI.LayeredWindowAttributes.LWA_ALPHA) { attribute.Alpha = alpha; } else { attribute.Alpha = null; } if ((((WindowsAPI.LayeredWindowAttributes)flags) & WindowsAPI.LayeredWindowAttributes.LWA_COLORKEY) == WindowsAPI.LayeredWindowAttributes.LWA_COLORKEY) { attribute.ColorKey = ColorTranslator.FromWin32((int)colorKey); } else { attribute.ColorKey = null; } } else { attribute.Alpha = null; attribute.ColorKey = null; } return attribute; }
/// <summary> /// レイヤードウィンドウの透明度と透明のカラーキーを設定する。 /// </summary> /// <param name="attribute">レイヤードウィンドウの属性値</param> public void SetLayeredWindowAttributes(LayeredWindowAttribute attribute) { byte alpha; Color colorKey; WindowsAPI.LayeredWindowAttributes flags = 0; if (attribute.Alpha == null) { alpha = 0; } else { alpha = attribute.Alpha.Value; flags |= WindowsAPI.LayeredWindowAttributes.LWA_ALPHA; } if (attribute.ColorKey == null) { colorKey = Color.Empty; } else { colorKey = attribute.ColorKey.Value; flags |= WindowsAPI.LayeredWindowAttributes.LWA_COLORKEY; } if (!WindowsAPI.SetLayeredWindowAttributes(this._handle, (uint)ColorTranslator.ToWin32(colorKey), alpha, (uint)flags)) { throw new Win32Exception(); } }