Combine Multiple ICO Files into One in Win32 Project with Visual Studio 2022

Abstract: Combine multiple ICO files into a single resource for Win32 projects in Visual Studio 2022 using a custom .rc script.

Created: 2026-09-21 by
To combine multiple ICO files into a single icon resource for a Win32 project in Visual Studio 2022, you must create a custom resource script (.rc file) that defines each icon variant and then compile it using the Resource Compiler. This process allows you to embed high-resolution variants (16x16, 32x32, 48x48, 256x256) into your application executable, ensuring crisp display across different Windows UI contexts without relying on external image files or complex runtime loading logic.

Preparing Your Icon Assets

Before opening Visual Studio, ensure you have all necessary icon sizes ready. A standard Windows application icon should include at least four distinct resolutions: 16x16 pixels for small taskbar icons, 32x32 for desktop and large icons, 48x48 for general system use, and 256x256 for modern high-DPI displays and app lists. While older standards sometimes included 64x64 or 128x128, these are less critical for most Win32 applications today. Save each size as a separate .ico file with a descriptive name, such as icon_16.ico, icon_32.ico, etc. It is crucial that each file contains only the specific resolution required; do not attempt to scale them dynamically within the resource compiler, as this often results in blurry artifacts. If you need to resize images, use dedicated tools like IcoFX or online converters before proceeding to the coding phase.

Creating the Resource Script

Visual Studio projects typically generate a default resource file named resource.h and an associated .rc file, but creating a dedicated script gives you precise control over the icon structure. Right-click your project in the Solution Explorer, select Add > New Item, and choose Resource File (.rc). Name it something logical, like app_icons.rc. Open this new file and add the following block of code. This script uses the ICON directive to map specific identifiers to your physical icon files.
#include "resource.h"

// Define unique identifiers for each icon size
#define IDI_ICON_16   101
#define IDI_ICON_32   102
#define IDI_ICON_48   103
#define IDI_ICON_256  104

// Include the actual icon files
IDI_ICON_16 ICON DISCARDABLE "icon_16.ico"
IDI_ICON_32 ICON DISCARDABLE "icon_32.ico"
IDI_ICON_48 ICON DISCARDABLE "icon_48.ico"
IDI_ICON_256 ICON DISCARDABLE "icon_256.ico"
The DISCARDABLE keyword informs the linker that these resources can be discarded if memory is tight, though they remain accessible via API calls. Ensure that the paths to your .ico files are correct relative to the project directory. If your icons are in a subfolder named assets, update the strings to "assets/icon_16.ico". After saving the .rc file, you must ensure it is included in the build process. In the Solution Explorer, right-click the .rc file and select Properties. Verify that Item Type is set to Microsoft Resource Compiler and that Excluded from Build is set to No. This step is frequently overlooked and causes the "unresolved external symbol" errors during linking.

Integrating Icons into Your Window Class

Once the resources are compiled, you need to associate them with your main window class. In your WinMain function or wherever you define your WNDCLASSEX structure, replace the default icon handle with one of your custom identifiers. Typically, you load the largest available icon for the class default, which Windows will automatically scale down when necessary.
WNDCLASSEX wc = {0};
wc.cbSize = sizeof(WNDCLASSEX);
wc.style          = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc    = WndProc;
wc.hInstance      = hInstance;
wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground  = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName   = NULL;
wc.lpszClassName  = L"MyAppClass";

// Load the 256x256 icon for the main class
wc.hIcon = LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON_256), IMAGE_ICON, 256, 256, LR_DEFAULTCOLOR);
wc.hIconSm = LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON_32), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
Using MAKEINTRESOURCE allows you to pass the integer identifier directly instead of a string name, which is more efficient. The hIconSm field specifically controls the small icon displayed in the title bar and taskbar switcher. By explicitly loading both, you guarantee that the correct resolution is used for each context, preventing Windows from stretching a low-res icon.

Handling Runtime Icon Changes

Sometimes you may want to change the icon dynamically, such as showing a "loading" state or a "success" state. You can unload the current icon and load a new one using the same LoadImage pattern followed by SendMessage with WM_SETICON.
HICON hNewIcon = LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON_48), IMAGE_ICON, 48, 48, LR_DEFAULTCOLOR);
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hNewIcon);
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hNewIcon);
Remember to call DestroyIcon on the old icon handle after sending the message to prevent memory leaks. This technique is useful for interactive applications where visual feedback is critical. For more advanced GUI development scenarios, such as those involving cross-platform constraints or different frameworks, you might explore related techniques in Building a Windows GUI Application with Winforms on a Mac.

Common Compilation Issues

If you encounter linker errors stating that symbols like IDI_ICON_16 are undefined, check two things. First, verify that the #include "resource.h" line is present in any source file that references these IDs. Second, ensure the .rc file is actually being compiled. Sometimes, adding a new file to the project does not automatically trigger a rebuild of the resource compiler output. Perform a clean solution build (Build > Clean Solution) followed by a full rebuild (Build > Rebuild Solution) to force the compiler to pick up the new definitions.

Frequently Asked Questions

Can I merge multiple icons into one .ico file using Visual Studio?

No, Visual Studio’s resource compiler does not support multi-image .ico files natively in the way some third-party tools do. Instead, you include each resolution as a separate resource entry in the .rc script. This approach gives you finer control over which resolution is loaded for which purpose, rather than forcing the OS to pick one from a bundled file.

Why does my icon look blurry on high-DPI monitors?

Blurry icons usually result from scaling a smaller image (like 16x16) to fit a larger space (like 256x256). To fix this, always load the highest resolution variant available (e.g., 256x256) for the hIcon member of your WNDCLASSEX. Windows will downscale it smoothly if needed, but it cannot upscale a tiny icon without quality loss.

Do I need to include all icon sizes in the final executable?

You only need to include the sizes your application actually uses. However, including 16x16, 32x32, and 256x256 covers nearly all standard Windows UI elements. Smaller sizes like 48x48 are optional but helpful for legacy compatibility. Excluding unused sizes reduces the final .exe file size slightly.

How do I assign different icons to buttons or controls?

You can load any of your defined icons using LoadImage and send them to controls using specific messages like BM_SETIMAGE for buttons. Just ensure you cast the icon handle correctly and manage memory by destroying unused handles to avoid leaks in long-running applications.

What happens if I omit the hIconSm field?

If you leave hIconSm as NULL, Windows will automatically scale down the large icon (hIcon) to fill the small icon slot. This often results in poor quality because the scaling algorithm is generic. Explicitly setting hIconSm to a dedicated 32x32 or 16x16 resource ensures a crisp appearance in the taskbar and alt-tab switcher.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More