Note that there are some explanatory texts on larger screens.

plurals
  1. POBitBlt two images atop one another
    primarykey
    data
    text
    <p>I am attempting to write a program that, when a checkbox is ticked, displays a grid over a large area of the screen. I'm attempting to do this in WM_PAINT using BitBlt, and my display function is definitely called with the right boolean value. However, it doesn't make any change to the window. Am I doing something stupid, or is there no practical way of achieving this? If this is unachievable, is there any way of getting similar results without specifying a different set of images containing the grid?</p> <pre><code>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, &amp;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), &amp;bm); for (int iii = pMinDisplay.x; iii &lt; pMaxDisplay.x; iii++) for (int jjj = pMinDisplay.y; jjj &lt; 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, &amp;ps); if (bDisplayBars) { HDC hdc = BeginPaint(hwnd, &amp;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 &lt; pMaxDisplay.x; iii++) for (int jjj = pMinDisplay.y; jjj &lt; 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, &amp;ps); } } </code></pre> <p>The dialog procedure is shown below.</p> <pre><code>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 &lt; 100; iii++) for(int jjj = 0; jjj &lt; 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 &lt; 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; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload