无法为任务栏和窗口栏设置不同的图标?

时间:2015-08-16 17:06:00

标签: c++ winapi resources icons registerclass

我有两个图标(.ico文件)。一个32x32大,另一个小16x16。

enter image description here

我正在尝试将hIcon的{​​{1}}设置为较大的WNDCLASSEX,将hIconSm设置为较小的LoadIcon。然而,我不能为我的生活弄清楚如何做到这一点!我首先尝试wndclass.hIcon = LoadIcon(instance, MAKEINTRESOURCE(IDI_SKELETON)); wndclass.hIconSm = LoadIcon(instance, MAKEINTRESOURCE(IDI_SKELETON_SM));

LoadImage

它始终为顶部窗口栏和任务栏加载相同的图标。与#define IDI_SKELETON 1000 #define IDI_SKELETON_SM 1001 相同。

enter image description here

以下是所有代码:

RESOURCE.H

#include "Resource.h"

IDI_SKELETON       ICON "Skeleton.ico"
IDI_SKELETON_SM    ICON "Skeleton_sm.ico"

Skeleton.rc

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

LRESULT CALLBACK
HandleEvent(HWND   window,
            UINT   message,
            WPARAM wparam,
            LPARAM lparam)
{
    switch(message)
    {
        case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC dc;
            RECT rect;

            dc = BeginPaint(window, &ps);
            GetClientRect(window, &rect);
            DrawText(dc, TEXT("This is a test window"), -1, &rect,
                         DT_SINGLELINE | DT_CENTER | DT_VCENTER);
            EndPaint(window, &ps);
        }
        break;

        case WM_CLOSE:
        {
            PostQuitMessage(0);
            return 0;
        }
        break;
    }
    return DefWindowProc(window, message, wparam, lparam);
}

int CALLBACK
WinMain(HINSTANCE instance,
        HINSTANCE previous,
        LPSTR     cmd,
        int       cmdshow)
{
    WNDCLASSEX wndclass;
    TCHAR classname[] = TEXT("24HoursClass");

    wndclass.cbSize = sizeof(wndclass);
    wndclass.style = CS_VREDRAW | CS_HREDRAW;
    wndclass.lpfnWndProc = HandleEvent;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = instance;
    wndclass.hIcon = (HICON)LoadImage(instance, MAKEINTRESOURCE(IDI_SKELETON), IMAGE_ICON,
             GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);
    wndclass.hIconSm = (HICON)LoadImage(instance, MAKEINTRESOURCE(IDI_SKELETON_SM), IMAGE_ICON,
             GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0);
    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wndclass.lpszMenuName = 0;
    wndclass.lpszClassName = classname;

    RegisterClassEx(&wndclass);

    HWND window = CreateWindowA(classname, "24 Hours",
            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
            CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
            0, 0, instance, 0);

    MSG msg;

    while(GetMessage(&msg, window, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return 0;
}

WinMain.cpp

'a foo

我错过了什么?

感谢任何帮助!

0 个答案:

没有答案