我正在开发缩略图创建者作为shell扩展。
为此,我选择实施接口IExtractImage
。
我的dll已加载并正确调用,但缩略图始终为黑色,而不是红色。
我错过了什么?
class MyShellPreview : public IExtractImage, IPersistFile
// set by IExtractImage::GetLocation
SIZE m_size;
IFACEMETHODIMP Extract(HBITMAP *phBmpImage)
{
size_t size = m_size.cx * m_size.cy * 3;
// alloc buffer
BYTE *buffer = (BYTE*)malloc(size);
// fill buffer
for (k = i = 0; i < m_size.cx; ++i)
{
for (j = 0; j < m_size.cy; ++j, ++k)
{
buffer[k] = 128;
buffer[k+1] = 0;
buffer[k+2] = 0;
}
}
*phBmpImage = CreateBitmap(m_size.cx, m_size.cy, 3, 8, buffer);
free(buffer);
return S_OK;
}
};
我知道出于性能原因,我应该使用CreateCompatibleBitmap
和SetDIBits
,但我不确定应该从哪里获得HDC
。
答案 0 :(得分:0)
正如评论所指出的,解决方案是使用:
class MyShellPreview : public IExtractImage, IPersistFile
// set by IExtractImage::GetLocation
SIZE m_size;
IFACEMETHODIMP Extract(HBITMAP *phBmpImage)
{
size_t size = m_size.cx * m_size.cy * 4;
// alloc buffer
BYTE *buffer = (BYTE*)calloc(size, 1);
// fill buffer
for (k = i = 0; i < m_size.cx; ++i)
{
for (j = 0; j < m_size.cy; ++j, k+=4)
{
buffer[k] = 128;
}
}
*phBmpImage = CreateBitmap(m_size.cx, m_size.cy, 1, 24, buffer);
free(buffer);
return S_OK;
}
};