Windows 资源管理器中的图标在使用 resource.rc 时显示 2 个不同的图标

Icon in Windows Explorer showing 2 different icons when using resource.rc

我正在尝试更改 Windows 应用程序的图标。我在下面使用简单的 window 代码,并在解决方案中添加了 resource.hresource.rc。我正在使用 test.icotest2.ico 文件,它们都包含 64x64、32x32、24x24 和 16x16 尺寸。

当我通过简单地将 .rc-file 中的这一行 TESTICON ICON "test.ico" 更改为 TESTICON ICON "test2.ico" 来在 icon 和 icon2 之间切换时,图标在程序 header 栏中相应地改变、任务栏和 alt-tab 视图。但是我的 windows 资源管理器中的图标表现得很奇怪。当我将视图设置为详细信息、列表或小型时,我会看到 test.ico-图标,但是对于中型、大型和超大型,无论我在 .[ 中设置什么,我都会看到 test2.ico-图标=35=]。我完全迷失在这里,我错过了哪个设置?

'resource.h'

#pragma once
#define TESTICON 1

和'resource.rc'

#include "resource.h"
TESTICON ICON "test.ico"

简单windows来源:

#ifndef UNICODE
#define UNICODE
#endif 

#include <windows.h>
#include "resource.h"

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{

    // Register the window class.
    const wchar_t CLASS_NAME[] = L"Sample Window Class";

    WNDCLASSEX wc = { };

    //Step 1: Registering the Window Class
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = 0;
    wc.lpfnWndProc = WindowProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = CLASS_NAME;
    wc.hIcon = (HICON)LoadImage(hInstance,
        MAKEINTRESOURCE(TESTICON), IMAGE_ICON,
        ::GetSystemMetrics(SM_CXICON),
        ::GetSystemMetrics(SM_CYICON), 0);
    wc.hIconSm = (HICON)LoadImage(hInstance,
         MAKEINTRESOURCE(TESTICON), IMAGE_ICON,
        ::GetSystemMetrics(SM_CXSMICON),
        ::GetSystemMetrics(SM_CYSMICON), 0);

    RegisterClassEx(&wc);

    // Create the window.
    HWND hwnd = CreateWindowEx(
        0,                              // Optional window styles.
        CLASS_NAME,                     // Window class
        L"Learn to Program Windows",    // Window text
        WS_OVERLAPPEDWINDOW,            // Window style

        // Size and position
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

        NULL,       // Parent window    
        NULL,       // Menu
        hInstance,  // Instance handle
        NULL        // Additional application data
    );

    if (hwnd == NULL)
    {
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);

    // Run the message loop.
    MSG msg = { };
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return 0;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;

    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hwnd, &ps);

        // All painting occurs here, between BeginPaint and EndPaint.
        FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
        EndPaint(hwnd, &ps);
    }
    return 0;
    }

    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

正如 Jonathan Potter 所指出的:Explorer 有一个图标缓存;如果它显示错误的图标,您可能需要清除缓存。 http://leodavidson.blogspot.com/2011/05/clear-icon-cache-1001.html