的后续修正
效果如图
代码如下
#include <stdio.h>
#include <windows.h>
#pragma warning(disable : 4996) // visual studio 宏定义,避免移植到Visual studio编译报错
// 核心代码自
//https://learn.microsoft.com/en-us/previous-versions/ms997538(v=msdn.10)
//掩码图,其中有 XOR AND 俩图片,都是用一个bit 0表示黑,1表示白,即一个字节对应八个像素
typedef struct
{
BITMAPINFOHEADER icHeader; // DIB header
RGBQUAD icColors[1]; // Color table
BYTE icXOR[1]; // DIB bits for XOR mask
BYTE icAND[1]; // DIB bits for AND mask
} ICONIMAGE, *LPICONIMAGE;
// 一个ICON 文件有多个图片,是因为不同机器上识别不同格式图片,这里是紧随ICON文件头之后的图片信息结构体
typedef struct
{
BYTE bWidth; // Width, in pixels, of the image
BYTE bHeight; // Height, in pixels, of the image
BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
BYTE bReserved; // Reserved ( must be 0)
WORD wPlanes; // Color Planes
WORD wBitCount; // Bits per pixel
DWORD dwBytesInRes; // How many bytes in this resource?
DWORD dwImageOffset; // Where in the file is this image?
} ICONDIRENTRY, *LPICONDIRENTRY;
// ICON 文件头
typedef struct
{
WORD idReserved; // Reserved (must be 0)
WORD idType; // Resource Type (1 for icons)
WORD idCount; // How many images?
ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em)
} ICONDIR, *LPICONDIR;
// 用于显示 Icon 的全部结构体数据 ,如果正常显示,说明微软的代码靠谱
void showIcon(LPICONDIR pIconDir,LPICONDIRENTRY pIconDirEntry,LPICONIMAGE pIconImage)
{
printf("pIconDir\n");
printf("%0x\n",pIconDir->idReserved);
printf("%0x\n",pIconDir->idType);
printf("%0x\n",pIconDir->idCount);
printf("pIconDirEntry\n");
printf("bHeight = %d\n",pIconDirEntry->bHeight);
printf("bWidth = %d\n",pIconDirEntry->bWidth);
printf("%0