より大きなプロジェクトの一環として、既存の HICON から HICON を作成しようとしています。最初にそのアイコンを HBITMAP にペイントし、次にそれを HICON に変換します。(これにより、アイコンにテキストを描画するなどして、アイコンを変更できます。)
残念ながら、アイコンは黒い四角で表示されています。これが私のコードです:
bool createIcon()
{
bool ret = false;
// get context of window
HDC context = GetDC(window_);
if (context != NULL)
{
// create a buffer context
HDC buffer = CreateCompatibleDC(context);
if (buffer != NULL)
{
PatBlt(buffer, 0, 0, iconSize_, iconSize_, WHITENESS);
// create a bitmap for our use
HBITMAP bitmap = CreateCompatibleBitmap(context, iconSize_, iconSize_);
if (bitmap != NULL)
{
HBITMAP oldBitmap;
// select the bitmap with the buffer
oldBitmap = reinterpret_cast<HBITMAP>(SelectObject(buffer, bitmap));
if (oldBitmap != NULL)
{
// draw the icon
if (DrawIcon(buffer, 0, 0, icon_))
{
if (icon_ != NULL)
DestroyIcon(icon_);
ImageList_RemoveAll(imageList_);
if (ImageList_Add(imageList_, bitmap, NULL) != -1)
{
icon_ = ImageList_GetIcon(imageList_, 0, ILD_NORMAL);
if (icon_ != NULL)
ret = true;
}
}
SelectObject(buffer, oldBitmap);
}
DeleteObject(bitmap);
}
DeleteDC(buffer);
}
DeleteDC(context);
}
return ret;
}
何か案は?