Skip to content

Showing an App Icon for 64-bit Windows Apps

Xojo 2015 Release 3 added the ability to create 64-bit apps for OS X, Windows and Linux. This is still considered a “beta” feature because there are a few things that still need to be added. One of those things is the ability to specify the app icon for 64-bit Windows apps.

Until that is available, you can work around it by setting the app icon at run-time (so it shows correctly in the Task Bar) and by having the installer set the icon for the app shortcut so it appears in the Start menu or on the desktop.

Thanks to Jim Cramer and Michele Bujardet for putting together the Declare code to set the app icon at run-time. To use this, you need to have your app icon in ICO format. Then use a Copy Files Build Script to copy it to the Resources folder. Your app then gets a FolderItem to the app icon and call the SetApplicationIcon method to set it.

This code gets the icon file and calls the SetApplicationIcon method to set it to your icon file (replace “XojoLogo.ico” with your own file of course):

#If TargetWin32 Then
  // The Icon is copied to the Resoures folder
  // in a Copy Files Build Step.
  // Get a Reference to it.
  // The file must be an ICO file, not PNG or JPG.

  Dim resourceFolderName As String
  resourceFolderName = App.ExecutableFile.Name + " Resources"
  resourceFolderName = resourceFolderName.Replace(".exe", "")

  Dim f As FolderItem = App.ExecutableFile.Parent.Child(resourceFolderName).Child("XojoLogo.ico")

  Self.SetApplicationIcon(f)
#Endif

This is the code for SetApplicationIcon, which you would add to a module since it is implemented as an extension method for the Window class:

Sub SetApplicationIcon(Extends w As Window, iconFile As FolderItem)
#If TargetWin32 Then
  Const WM_SETICON = &h80
  Const ICON_BIG = 1
  Const ICON_SMALL = 0
  Const GW_OWNER = 4

  Soft Declare Function LoadImage Lib "User32" _
    Alias "LoadImageW" (hinst As Int32, lpszName As WString, _
    uType As Int32, cxDesired As Int32, cyDesired As Int32, _
    fuLoad As Int32) As Int32
  Soft Declare Sub SendMessage Lib "User32" _
    Alias "SendMessageW" (hwnd As Integer, msg As Integer, _
    wParam As Integer, lParam As Integer)
  Soft Declare Function GetWindow Lib "User32" _
    (HWND As Int32, uCmd As UInt32) As Int32

  // Get handle to the Icon Image on Disk
  // Default size and load from file. 
  Dim Flags As Integer = Bitwise.BitOr(&h40, &h10)
  Dim hIcon As Integer = LoadImage(0, IconFile.NativePath, _
    1, 0, 0, Flags)

  // Reset the Icon For This Window
  SendMessage(w.Handle, WM_SETICON, ICON_BIG, hIcon)
  SendMessage(w.handle, WM_SETICON, ICON_SMALL, hIcon)

  // Ensure the application Icon gets changed as well
  Dim ownerHandle As Integer = GetWindow(w.Handle, GW_OWNER)
  SendMessage(ownerHandle, WM_SETICON, ICON_BIG, hIcon)
  SendMessage(ownerHandle, WM_SETICON, ICON_SMALL, hIcon)
#Endif
End Sub

This Declare works for both 32-bit and 64-bit apps, so you can test that everything is working properly before you build as 64-bit.

The next step is to create your installer so that it uses the app icon for the Start menu and Desktop shortcuts that it creates. With InnoSetup, you just have to add this command to the items in the [Icons] section:

IconFilename: "{app}AppIconTest ResourcesXojoLogo.ico"

Of course, you’ll need to specify the appropriate path and filename in your own InnoSetup script. Lastly, to ensure your app gets installed as a 64-bit app and placed into “Program Files” (instead of “Program Files (x86)”), then also add this setting to the [Setup] section:

ArchitecturesInstallIn64BitMode=x64

Remember, you’ll need to modify the InnoSetup script to use the appropriate paths on your system.

With these two tricks, for all intents and purposes your 64-bit app will appear to have an app icon.


64bit desktop apps Xojo Mac Windows Linux