My application icon is visible everywhere but in the Default File Association

Jean-Milost Reymond 21 Reputation points
2022-08-22T09:38:05.82+00:00

Under Windows 11, I'm writing a small application which may be opened by some file types like .jpg or .heic, meaning that it may change the default selected application for these types.

The application is created with Visual Studio 2019, and it contains its own icon, which I declared in the following manner:

MyApp.rc

#include "resource.h"  
#include "windows.h"  
  
// Icon with lowest ID value placed first to ensure application icon  
// remains consistent on all systems.  
  
IDI_APPICON       ICON         "MyAppIcon.ico"  
IDI_SMALL         ICON         "MyAppIcon.ico"  

Resources.h

#define IDI_APPICON 100  
#define IDI_SMALL   101  

main.cpp

...  
// resources  
#include "resource.h"  
...  
int APIENTRY wWinMain(_In_     HINSTANCE hInstance,  
                      _In_opt_ HINSTANCE hPrevInstance,  
                      _In_     LPWSTR    lpCmdLine,  
                      _In_     int       nCmdShow)  
{  
    ...  
    WNDCLASSEX wcex  = {0};  
    BOOL       bQuit = FALSE;  
  
    // register window class  
    wcex.cbSize        = sizeof(WNDCLASSEX);  
    wcex.style         = CS_OWNDC;  
    wcex.lpfnWndProc   = WindowProc;  
    wcex.cbClsExtra    = 0;  
    wcex.cbWndExtra    = 0;  
    wcex.hInstance     = hInstance;  
    wcex.hIcon         = ::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON));  
    wcex.hIconSm       = ::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SMALL));  
    wcex.hCursor       = ::LoadCursor(nullptr, IDC_ARROW);  
    wcex.hbrBackground = (HBRUSH)::GetStockObject(BLACK_BRUSH);  
    wcex.lpszMenuName  = nullptr;  
    wcex.lpszClassName = L"MyAppClassName";  
  
    if (!RegisterClassEx(&wcex))  
        return 0;  
  
    // create main window  
    g_hWnd = ::CreateWindowEx(0,  
                              L"MyAppClassName",  
                              L"My Application",  
                              WS_DLGFRAME | WS_CAPTION | WS_SYSMENU,  
                              CW_USEDEFAULT,  
                              CW_USEDEFAULT,  
                              800,  
                              650,  
                              nullptr,  
                              nullptr,  
                              hInstance,  
                              nullptr);  
  
    ::ShowWindow(g_hWnd, nCmdShow);  
    ...  
}  

The .ico file contains the following sizes: 16x16, 32x32, 48x48, 256x256

My application shows the icon correctly everywhere (header, taskbar, uninstall list, ...) except in one location: the Default File Association, and its relative settings, as shown in the below screenshot:
233370-def-icon.png

I cannot figure out what is wrong. Can someone explain me why my icon isn't visible only at this location?

Windows development | Windows App SDK
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2022-08-23T09:34:00.363+00:00

    Hello @Jean-Milost Reymond
    Welcome to Microsoft Q&A!

    Try to delete the default icon in the resource file, keep only your own icon resource, clean the project cache, and rebuild the project.

    You can add the following code after the window is created.

    HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,  
          CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);  
      
      HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));  
      
       SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);  
    

    234004-a48fb20a-0877-417e-897d-13bccad97058.jpg

    Thank you.
    Junjie


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.