博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
周报_2012第13周(2012/03/25-2012/03/31)
阅读量:4680 次
发布时间:2019-06-09

本文共 3869 字,大约阅读时间需要 12 分钟。

项目:X保密项目

2012.03.28

// #pragmas are used here to insure that the structure's

// packing in memory matches the packing of the EXE or DLL.
#pragma pack( push )
#pragma pack( 2 )
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
    WORD    wPlanes;              // Color Planes
    WORD    wBitCount;            // Bits per pixel
    DWORD    dwBytesInRes;         // how many bytes in this resource?
    WORD    nID;                  // the ID
} GRPICONDIRENTRY, *LPGRPICONDIRENTRY;

typedef struct

{
    WORD            idReserved;   // Reserved (must be 0)
    WORD            idType;       // Resource type (1 for icons)
    WORD            idCount;      // How many images?
    GRPICONDIRENTRY    idEntries[1]; // The entries for each image
} GRPICONDIR, *LPGRPICONDIR;
#pragma pack( pop )

 

枚举图标资源名

Callback for enumerating resources in a DLL/EXE

 

    // Using an ID from the group, Find, Load and Lock the RT_ICON, Get the group icon.

    if( (hRsrc = FindResourceW( hInstance, nIndex, RT_GROUP_ICON )) == NULL )
        return NULL;
    if( (hGlobal = LoadResource( hInstance, hRsrc )) == NULL )
        return NULL;
    if( (lpRes = LockResource(hGlobal)) == NULL )
        return NULL;

    // Get the identifier of the icon that is most appropriate for the video display.

    LPGRPICONDIR lpGrpIconDir = (LPGRPICONDIR)lpRes;
    LPGRPICONDIRENTRY lpIconEntryAppropriate = QueryAppropriateSizeIcon(lpGrpIconDir, nSizeAppropriate);

    int nID;

    if (lpIconEntryAppropriate)
    {
        nID = lpIconEntryAppropriate->nID;
    }
    else
    {
        nID = LookupIconIdFromDirectoryEx((PBYTE)lpRes, TRUE, nSizeAppropriate, nSizeAppropriate, LR_DEFAULTCOLOR);
    }

    if( (hRsrc = FindResource( hInstance, MAKEINTRESOURCE(nID), RT_ICON )) == NULL )

        return NULL;
    if( (hGlobal = LoadResource( hInstance, hRsrc )) == NULL )
        return NULL;
    // Here, lpRes points to an ICONIMAGE structure
    if( (lpRes = LockResource(hGlobal)) == NULL )
        return NULL;

    // Let the OS make us an icon

    hIcon = CreateIconFromResourceEx( (LPBYTE)lpRes, SizeofResource(hInstance,hRsrc), TRUE, 0x00030000
        , nSizeAppropriate, nSizeAppropriate, LR_DEFAULTCOLOR );

 

LPGRPICONDIRENTRY CImageMgr::QueryAppropriateSizeIcon(LPGRPICONDIR lpGrpIconDir, int& nSizeAppropriate)

{
    LPGRPICONDIRENTRY lpIconRet = NULL;
    int nTmp;

    vector<LPGRPICONDIRENTRY> vector_icon_fit;   

    for (int i = 0; i < lpGrpIconDir->idCount; ++i)
    {
        LPGRPICONDIRENTRY lpIconEntry = &(lpGrpIconDir->idEntries[i]);
        // 查找最匹配的尺寸
        nTmp = (0 == lpIconEntry->bWidth) ? 256 : lpIconEntry->bWidth;
        if (nSizeAppropriate == nTmp)
        {
            vector_icon_fit.push_back(lpIconEntry);           
        }
    }

    if (0 == vector_icon_fit.size())

    {
        int nBetterSize = 257;
        // 如果没有最匹配的尺寸则查找最小的更大尺寸       
        for (int i = 0; i < lpGrpIconDir->idCount; ++i)
        {
            LPGRPICONDIRENTRY lpIconEntry = &(lpGrpIconDir->idEntries[i]);
            nTmp = (0 == lpIconEntry->bWidth) ? 256 : lpIconEntry->bWidth;
            if ((nTmp > nSizeAppropriate) && (nBetterSize > nTmp))
            {
                nBetterSize = nTmp;
            }
        }
        if (257 == nBetterSize)
        {
            nBetterSize = -1;
            // 如果没有最匹配的尺寸则查找最大的更小尺寸
            for (int i = 0; i < lpGrpIconDir->idCount; ++i)
            {
                LPGRPICONDIRENTRY lpIconEntry = &(lpGrpIconDir->idEntries[i]);
                nTmp = (0 == lpIconEntry->bWidth) ? 256 : lpIconEntry->bWidth;
                if ((nTmp < nSizeAppropriate) && (nBetterSize < nTmp))
                {
                    nBetterSize = nTmp;
                }
            }
        }

        nSizeAppropriate = nBetterSize;

        for (int i = 0; i < lpGrpIconDir->idCount; ++i)

        {
            LPGRPICONDIRENTRY lpIconEntry = &(lpGrpIconDir->idEntries[i]);
            nTmp = (0 == lpIconEntry->bWidth) ? 256 : lpIconEntry->bWidth;
            if (nBetterSize == nTmp)
            {
                vector_icon_fit.push_back(lpIconEntry);
            }
        }
    }

    // Bits per pixel 最高颜色位数

    int nBitsPixel = 0;
    int nPosMax = -1;
    for (int i = 0; i < vector_icon_fit.size(); ++i)
    {
        LPGRPICONDIRENTRY lpIconEntry = vector_icon_fit[i];
        if (nBitsPixel < lpIconEntry->wBitCount)
        {
            nBitsPixel = lpIconEntry->wBitCount;
            nPosMax = i;
        }
    }

    if (nPosMax > -1)

    {
        lpIconRet = vector_icon_fit[nPosMax];
    }

    return lpIconRet;

}

 

对比图标

转载于:https://www.cnblogs.com/DancingFish/archive/2012/03/28/2422404.html

你可能感兴趣的文章
软件測试自学指南---从入门到精通
查看>>
LoadImage()的使用
查看>>
SSL协议具体解释
查看>>
浅谈实际分辨率与逻辑分辨率实现像素与尺寸的准确转换
查看>>
HIVE中内连接和左半连接不一致问题
查看>>
实验11——指针的基础应用
查看>>
Go实现发送解析GET与POST请求
查看>>
Girls Like You--Maroon 5
查看>>
FZU 1343 WERTYU --- 水题
查看>>
angularjs 中使用 service 在controller 之间 share 对象和数据
查看>>
禁止在 .NET Framework 中执行用户代码。启用 "clr enabled" 配置选项
查看>>
JSON、闭包和原型----透视Javascript语言核心
查看>>
[苹果]苹果AppStore应用审核标准
查看>>
lxr看代码的时候出现中文乱码问题
查看>>
CImageList使用指南(转)
查看>>
常量like数据库表中的列
查看>>
VC2012编译CEF3-转
查看>>
Log4net的配置-按照日期+文件大小混合分割
查看>>
const char*、char*、char* const、char[]、string的区别
查看>>
『cs231n』绪论
查看>>