how to change the icon of an exe in c++

To change the icon of an executable (.exe) file in C++, you can use the Windows API functions. Here are the steps to accomplish this:

Step 1: Include the necessary headers Include the following headers at the beginning of your C++ file:

#include <Windows.h>
#include <winuser.h>

Step 2: Define a resource ID Define a unique resource ID for the icon in your C++ file. You can do this by adding the following line before the main() function:

#define MY_ICON 101

Step 3: Add the icon resource Add the icon file (.ico) to your project resources. You can do this by right-clicking on your project in the solution explorer, selecting "Add" -> "Resource", and then specifying the icon file.

Step 4: Set the icon Inside your main() function, call the SetClassLongPtr() function to set the icon for your window. This should be done before creating the window. Here's an example:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    // ...

    // Set the icon
    HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(MY_ICON));
    SetClassLongPtr(hWnd, GCLP_HICON, (LONG_PTR)hIcon);

    // ...
}

Step 5: Compile and run Compile your C++ code and run the executable. The icon specified in the resources should now be displayed for your executable.

That's it! These steps should allow you to change the icon of an executable file in C++ using the Windows API functions.