gpt4 book ai didi

winapi - 如何从 HICON 确定图标的大小?

转载 作者:行者123 更新时间:2023-12-03 22:30:53 48 4
gpt4 key购买 nike

我有一个由 HICON 标识的图标我想以自定义控件为中心绘制的句柄。

如何确定图标的大小以便计算正确的绘图位置?

最佳答案

这是一个 C++ 版本的代码:

struct MYICON_INFO
{
int nWidth;
int nHeight;
int nBitsPerPixel;
};

MYICON_INFO MyGetIconInfo(HICON hIcon);

// =======================================

MYICON_INFO MyGetIconInfo(HICON hIcon)
{
MYICON_INFO myinfo;
ZeroMemory(&myinfo, sizeof(myinfo));

ICONINFO info;
ZeroMemory(&info, sizeof(info));

BOOL bRes = FALSE;

bRes = GetIconInfo(hIcon, &info);
if(!bRes)
return myinfo;

BITMAP bmp;
ZeroMemory(&bmp, sizeof(bmp));

if(info.hbmColor)
{
const int nWrittenBytes = GetObject(info.hbmColor, sizeof(bmp), &bmp);
if(nWrittenBytes > 0)
{
myinfo.nWidth = bmp.bmWidth;
myinfo.nHeight = bmp.bmHeight;
myinfo.nBitsPerPixel = bmp.bmBitsPixel;
}
}
else if(info.hbmMask)
{
// Icon has no color plane, image data stored in mask
const int nWrittenBytes = GetObject(info.hbmMask, sizeof(bmp), &bmp);
if(nWrittenBytes > 0)
{
myinfo.nWidth = bmp.bmWidth;
myinfo.nHeight = bmp.bmHeight / 2;
myinfo.nBitsPerPixel = 1;
}
}

if(info.hbmColor)
DeleteObject(info.hbmColor);
if(info.hbmMask)
DeleteObject(info.hbmMask);

return myinfo;
}

关于winapi - 如何从 HICON 确定图标的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1913468/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com