我试图写的是,当一个复选框被选中的节目,显示在大面积屏幕的网格。我正在尝试使用BitBlt在WM_PAINT中执行此操作,并且我的显示函数肯定是使用正确的 bool(boolean) 值调用的。但是,它不会对窗口进行任何更改。我是在做一些愚蠢的事情,还是没有实际的方法来实现这一目标?如果无法实现,是否可以在不指定包含网格的另一组图像的情况下获得相似的结果?

void DisplayRoom(HWND hwnd, char TileList[][100], POINT pMaxDisplay, POINT pMinDisplay, HBITMAP ahbmTileset[], bool bDisplayBars)
{
HBITMAP hbmSprite, hbmMask;
BITMAP bm;
PAINTSTRUCT ps;
HINSTANCE hinNULL = GetModuleHandle(NULL);
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld;
POINT Position;
hbmSprite = LoadBitmap(hinNULL, MAKEINTRESOURCE(IDB_CLEAR_GROUND));
hbmOld = (HBITMAP)SelectObject(hdcMem, hbmSprite);
GetObject(hbmSprite, sizeof(bm), &bm);
for (int iii = pMinDisplay.x; iii < pMaxDisplay.x; iii++)
    for (int jjj = pMinDisplay.y; jjj < pMaxDisplay.y; jjj++)
    {
        switch(TileList[iii][jjj])
        {
        case 'g':
            hbmSprite = ahbmTileset[0];
            break;
        case 'd':
            hbmSprite = ahbmTileset[1];
            break;
        case 'i':
            hbmSprite = ahbmTileset[2];
            break;
        case 'l':
            hbmSprite = ahbmTileset[3];
            break;
        }
                    assert(hbmSprite != NULL);
        SelectObject(hdcMem, hbmSprite);
        BitBlt(hdc, (iii - pMinDisplay.x) * 34 + 90, (jjj - pMinDisplay.y) * 34 + 60, 34, 34, hdcMem, 0, 0, SRCCOPY);
    }
DeleteDC(hdcMem);
EndPaint(hwnd, &ps);
if (bDisplayBars)
{
    HDC hdc = BeginPaint(hwnd, &ps);
    HDC hdcMem = CreateCompatibleDC(hdc);
    hbmSprite = LoadBitmap(hinNULL, MAKEINTRESOURCE(IDB_GRID));
            assert(hbmSprite != NULL);
    hbmMask = CreateBitmapMask(hbmSprite, RGB(0,0,0));
    for (int iii = pMinDisplay.x; iii < pMaxDisplay.x; iii++)
        for (int jjj = pMinDisplay.y; jjj < pMaxDisplay.y; jjj++)
        {
            SelectObject(hdcMem, hbmMask);
            BitBlt(hdc, (iii - pMinDisplay.x) * 34 + 90, (jjj - pMinDisplay.y) * 34 + 60, 34, 34, hdcMem, 0, 0, SRCAND);
            SelectObject(hdcMem, hbmSprite);
            BitBlt(hdc, (iii - pMinDisplay.x) * 34 + 90, (jjj - pMinDisplay.y) * 34 + 60, 34, 34, hdcMem, 0, 0, SRCPAINT);
        }
    DeleteDC (hdcMem);
    EndPaint(hwnd, &ps);
}
}

对话过程如下所示。
BOOL CALLBACK CreateRoom(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
static char achTileDetails[100][100];
static POINT pDimensions, pMonsterLocations, pMinDisplay, pMaxDisplay;
static HBITMAP ahbmTileset[4];
static bool bShowBars;
switch(Message)
{
case WM_INITDIALOG:
    SetFocus(hwnd);
    for (int iii = 0; iii < 100; iii++)
        for(int jjj = 0; jjj < 100; jjj++)
            achTileDetails[iii][jjj] = 'g';
    pDimensions.x = 20;
    pDimensions.y = 10;
    pMinDisplay.x = 0;
    pMinDisplay.y = 0;
    pMaxDisplay.x = 20;
    pMaxDisplay.y = 10;
    for (int iii = 0; iii < 4; iii++)
        ahbmTileset[iii] = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_CLEAR_GROUND + iii));
    return TRUE;
case WM_PAINT:
    DisplayRoom(hwnd, achTileDetails, pMaxDisplay, pMinDisplay, ahbmTileset, bShowBars);
    break;
case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    case IDCANCEL:
        EndDialog(hwnd, IDCANCEL);
        break;
    case IDC_DISPLAY_GRID:
        switch(HIWORD(wParam))
        {
        case BN_CLICKED:
            bShowBars = SendMessage(GetDlgItem(hwnd, IDC_DISPLAY_GRID), BM_GETCHECK, 0, 0);
            InvalidateRect(hwnd, NULL, TRUE);
            UpdateWindow(hwnd);
            break;
        }
        break;
    }
    break;
case WM_LBUTTONDOWN:

    break;
default:
    return FALSE;
}
}

最佳答案

我看到的主要问题是您两次调用了BeginPaintEndPaint。在完成任何绘制之前,只应执行一次BeginPaint,而在完成所有绘制之后,则应执行EndPaint

可能还有其他问题,这些东西很难完全正确。

08-04 11:53