0

看这两张图:

Windows 7的:

在此处输入图像描述

经验:

在此处输入图像描述

如您所见,XP 机箱上没有图像。

在这篇文章http://social.msdn.microsoft.com/Forums/da-DK/vcmfcatl/thread/6f9b1f03-0c67-4af4-a187-e135fdd1411c中,似乎PUSHBUTTON with BS_BITMAP style doesn't work on XP. 这是正确的吗?如果是,如何在 XP 上做类似的事情?


在资源脚本文件中,我设置了样式为 BS_BITMAP 的按钮,下面是与设置图像相关的代码:

static INT_PTR CALLBACK Dialog_Color_Proc(...)
{
    ....    
    case WM_INITDIALOG:
        ....
        SetColorDlgButtonColor(hDlg, IDC_SET_START_PAGE_BG, prefs->bgColor);
        ....
}

void SetColorDlgButtonColor(HWND hDlg, int nIDDlgItem, COLORREF color)
{
    HWND hButton = GetDlgItem(hDlg, nIDDlgItem);

    HDC hdc = GetDC(hButton);
    HDC memDC = CreateCompatibleDC(hdc);

    int dx = ClientRect(hButton).dx;
    int dy = ClientRect(hButton).dx;
    HBITMAP hMemBmp = CreateCompatibleBitmap(hdc, dx, dy);
    HBITMAP hOldBmp = (HBITMAP)SelectObject(memDC, hMemBmp);

    Rectangle(memDC, 0, 0, dx, dy);

    RECT rc;
    rc.left   = 0; 
    rc.top    = 0;
    rc.right  = dx;
    rc.bottom = dy;


    HBRUSH brush = CreateSolidBrush(color);
    FillRect(memDC, &rc, brush);
    SelectObject(memDC, hOldBmp);
    SendMessage(GetDlgItem(hDlg, nIDDlgItem), BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hMemBmp);
    DeleteObject(brush);
    DeleteObject(hMemBmp);
    DeleteObject(memDC);
}
4

0 回答 0