Beispiel #1
0
        /// <summary>
        /// Default the Window Icon to the icon stored in the .exe, if any.
        ///
        /// The Icon can be overriden by callers by calling SetIcon themselves.
        /// </summary>
        void SetIcon()
        {
            var processPath = Environment.ProcessPath;

            if (!string.IsNullOrEmpty(processPath))
            {
                var index = IntPtr.Zero;                 // 0 = first icon in resources
                _windowIcon = ExtractAssociatedIcon(IntPtr.Zero, processPath, ref index);
                if (_windowIcon != IntPtr.Zero)
                {
                    var appWindow = AppWindow.GetFromWindowId(Win32Interop.GetWindowIdFromWindow(WindowHandle));
                    if (appWindow is not null)
                    {
                        var iconId = Win32Interop.GetIconIdFromIcon(_windowIcon);
                        appWindow.SetIcon(iconId);
                    }
                }
            }
        }