[英]Icon in Windows Explorer showing 2 different icons when using resource.rc
I'm trying to change the icon of my Windows application.我正在尝试更改我的 Windows 应用程序的图标。 I'm using the simple window code below and added a resource.h
and resource.rc
to the solution.我正在使用下面的简单 window 代码,并在解决方案中添加了resource.h
和resource.rc
。 I'm using a test.ico
and a test2.ico
-file which both contain 64x64, 32x32, 24x24 and 16x16 sizes.我正在使用一个test.ico
和一个test2.ico
文件,它们都包含 64x64、32x32、24x24 和 16x16 大小。
The when I switch between icon and icon2 by simple changing this line TESTICON ICON "test.ico"
to TESTICON ICON "test2.ico"
in the.rc-file, the icons change accordingly in program header bar, taskbar and alt-tab view.当我通过简单地将.rc文件中的TESTICON ICON“test.ico”这一行更改为TESTICON ICON "test2.ico"
TESTICON ICON "test.ico"
来在icon和icon2之间切换时,图标在程序header栏、任务栏和alt-tab视图中会相应改变. But the icon in my windows explorer is acting totally strange.但是我的 windows 资源管理器中的图标表现得很奇怪。 When I set the view to details,list or small I see the test.ico
-icon, but for medium, large and extra large I see the test2.ico
-icon, no matter what I set in the.rc-file.当我将视图设置为详细信息、列表或小时,我会看到test.ico
-icon,但对于中、大和超大,无论我在 .rc 文件中设置什么,我都会看到test2.ico
-icon。 I'm totally lost here, which setting am I missing?我完全迷失在这里,我错过了哪个设置?
The 'resource.h' 'resource.h'
#pragma once
#define TESTICON 1
and the 'resource.rc'和'resource.rc'
#include "resource.h"
TESTICON ICON "test.ico"
The simple windows source:简单的 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);
}
As pointed out by Jonathan Potter: Explorer has an icon cache;正如 Jonathan Potter 所指出的: Explorer 有一个图标缓存; if it's showing the wrong icon you probably need to clear the cache.如果它显示错误的图标,您可能需要清除缓存。 http://leodavidson.blogspot.com/2011/05/clear-icon-cache-1001.html http://leodavidson.blogspot.com/2011/05/clear-icon-cache-1001.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.