代码参考了如下网页的实现:
https://www.cnblogs.com/zy791976083/p/9921069.html
整理成一个函数:
BOOL GetResGifSize(long nResId, LPCTSTR name, long *lnWidth, long *lnHeight) { HRSRC hRsrc = FindResource(NULL, MAKEINTRESOURCE(nResId), name); if (NULL == hRsrc) { return FALSE; } DWORD dwSize = SizeofResource(NULL, hRsrc); HGLOBAL hGlobal = LoadResource(NULL, hRsrc); if (NULL == hGlobal) { CloseHandle(hRsrc); return FALSE; } unsigned char* pBuffer = (unsigned char*)LockResource(hGlobal); if (NULL == pBuffer) { CloseHandle(hRsrc); FreeResource(hGlobal); return FALSE; } //判断是否为GIF文件 if(pBuffer[0] != 0x47 && pBuffer[1] != 0x49 && pBuffer[2] != 0x46 && pBuffer[3] != 0x38){ return FALSE; } //读取宽高 for(int i = 4; i < dwSize ; i++) { if(pBuffer[i] == 0x00 && pBuffer[i+1] == 0x2c) { *lnWidth = (pBuffer[i+7]<<8) | pBuffer[i+6]; *lnHeight = (pBuffer[i+9]<<8) | pBuffer[i+8]; UnlockResource(hGlobal); FreeResource(hGlobal); return TRUE; } } UnlockResource(hGlobal); FreeResource(hGlobal); return FALSE; }