簡體   English   中英

Windows Explorer 中的圖標在使用 resource.rc 時顯示 2 個不同的圖標

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

我正在嘗試更改我的 Windows 應用程序的圖標。 我正在使用下面的簡單 window 代碼,並在解決方案中添加了resource.hresource.rc 我正在使用一個test.ico和一個test2.ico文件,它們都包含 64x64、32x32、24x24 和 16x16 大小。

當我通過簡單地將.rc文件中的TESTICON ICON“test.ico”這一行更改為TESTICON ICON "test2.ico" TESTICON ICON "test.ico"來在icon和icon2之間切換時,圖標在程序header欄、任務欄和alt-tab視圖中會相應改變. 但是我的 windows 資源管理器中的圖標表現得很奇怪。 當我將視圖設置為詳細信息、列表或小時,我會看到test.ico -icon,但對於中、大和超大,無論我在 .rc 文件中設置什么,我都會看到test2.ico -icon。 我完全迷失在這里,我錯過了哪個設置?

'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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM