question

HemanthB-9452 avatar image
0 Votes"
HemanthB-9452 asked HemanthB-9452 commented

App Icon - Windows App SDK

I've tried this https://github.com/microsoft/microsoft-ui-xaml/issues/4056 but no use.
How do I add an icon for my WinUI 3 Windows App SDK app both in window title bar as well as the taskbar?

windows-app-sdk
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered HemanthB-9452 commented

For the exe/Taskbar, in Properties :

195598-winui-exe-ico.jpg


For the main window, a way :

 IntPtr hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
 string sExe = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
 System.Drawing.Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(sExe);
 SendMessage(hWnd, WM_SETICON, ICON_BIG, ico.Handle);

with :

 public const int ICON_SMALL = 0;
 public const int ICON_BIG = 1;
 public const int ICON_SMALL2 = 2;
    
 public const int WM_GETICON = 0x007F;
 public const int WM_SETICON = 0x0080;
    
 [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]
 public static extern int SendMessage(IntPtr hWnd, uint msg, int wParam, IntPtr lParam);




winui-exe-ico.jpg (89.0 KiB)
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am getting all these errors. please help
195715-image.png


0 Votes 0 ·
image.png (123.1 KiB)

The code 'IntPtr hWnd = ..." must be added in the Constructor of MainWindow (after this.InitializeComponent();)

0 Votes 0 ·

Thanks! This worked! Also is there any way to change the title bar color in the app?

0 Votes 0 ·

You can see Title bar customization, but is is different if OS = Windows 11 or not
(many things don't work on my Windows 10 OS)

0 Votes 0 ·
Show more comments