Problems with setting application icon

前端 未结 5 1898
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 14:53

(I\'m using Visual Studio 2008, though I remember having similar problems with older versions as well.)

I\'ve tried several different methods (many of them mentioned

5条回答
  •  春和景丽
    2021-01-05 15:20

    For anyone coming to this same difficulty if you are going to change ICON_BIG you must first send WM_SETICON with ICON_SMALL and then proceed to ICON_BIG.

    For example:

    SetLastError(0);
    SendMessage(windowHandle, WM_SETICON, ICON_SMALL, (LPARAM)iconsmallHandle);
    [do error handling]
    SetLastError(0);
    SendMessage(windowHandle, WM_SETICON, ICON_BIG, (LPARAM)iconbigHandle);
    [do error handling]
    

    You will need to use SetLastError after the first SendMessage to clear any returned error.

    If you are just setting ICON_SMALL you can ignore ICON_BIG. For whatever reason in all of my tests you must set ICON_SMALL regardless if that icon needs to change or not, before attempting to change ICON_BIG, otherwise you will always get error code 0x6 (invalid handle).

提交回复
热议问题