ここにいくつかのコードがあります:
PAINTSTRUCT ps;
HDC hidden = CreateCompatibleDC(NULL);
HBITMAP hiddenbmp = CreateBitmap(288,288,1,24,NULL);
HBITMAP hiddenold = (HBITMAP)SelectObject(hidden,hiddenbmp);
HDC other = GetDC(NULL);
HDC otherhdc = CreateCompatibleDC(other);
HBITMAP sprites;
if (color)
sprites = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_COLOR_SPRITES));
else sprites = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BLACKWHITE_SPRITES));
HBITMAP otherold = (HBITMAP)SelectObject(otherhdc, sprites);
// Find x and y coordinate for the top left of the visible screen
int x = game.Player_x, y = game.Player_y, ypos = 0;
if (x < 4) x = 4;
if (x > 27) x = 27;
if (y < 4) y = 4;
if (y > 27) y = 27;
if (modx == -100) modx = x; // modx and mody are initialized to -100
else x = modx;
if (mody == -100) mody = y;
else y = mody;
x -= 4;
y -= 4;
// Draw lower layer
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if (game.Layer_Two[x + i][y + j] != 0)
{
int xpos = game.get_pos(game.Layer_Two[x + i][y + j], ypos, false);
BitBlt(hidden, (i * 32), (j * 32), 32, 32, otherhdc, xpos, ypos, SRCCOPY);
}
}
}
// Draw upper layer
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if ((game.Layer_Two[x + i][y + j] != 0 && game.Layer_One[x + i][y + j] >= 64 && game.Layer_One[x + i][y + j] <= 111))
{
int xpos = game.get_pos(game.Layer_One[x + i][y + j], ypos, true);
TransparentBlt(hidden, (i * 32), (j * 32), 32, 32, otherhdc, xpos, ypos, 32, 32, RGB(255, 255, 255));
} else {
int xpos = game.get_pos(game.Layer_One[x + i][y + j], ypos, false);
BitBlt(hidden, (i * 32), (j * 32), 32, 32, otherhdc, xpos, ypos, SRCCOPY);
}
}
}
// Draw the compiled image to the main window
HDC hdc = GetDC(hWnd);
BitBlt(hdc, 32, 32, 288, 288, hidden, 0, 0, SRCCOPY);
SelectObject(hidden,hiddenold);
DeleteDC(hidden);
DeleteObject(hiddenbmp);
SelectObject(other,otherold);
DeleteObject(other);
DeleteDC(otherhdc);
ReleaseDC(hWnd, hdc);
これは DrawMap() と呼ばれる関数にあります。この関数は、ご存知のとおり、マップ (9 x 9、32 x 32 ピクセルのタイルの 2 つのレイヤーで構成されています) を描画します。私がやろうとしているのは、オフスクリーン (つまり、見えない) DC で 9 x 9 のタイルをコンパイルし、それをメイン ウィンドウに一度にレンダリングして、タイルが実際の方法で描画されているのを見ることができないようにすることです。左から右、上から下。このコードでは、メイン ウィンドウには何も描画されません。
さらに奇妙なことに、「他の」hdc のみを使用してみました (「非表示」の hdc ではなく、「otherhdc」を非表示にするつもりでしたが)。ソース hdc として「otherhdc」を使用し、宛先 hdc として「other」を使用して、35、48、および 51 行目に BitBlt() および TransparentBlt() 関数を配置しました。次に、56 行目で「その他」が「hdc」(hWnd の DC) にコピーされました。実際の物理画面では 0, 0)。変。基本的にはそれを目指していると思いますが、「その他」が描かれていることを除けば。
これは頻繁に使用されるため、効率を最大化するために DC などのデストラクタを関数内で呼び出すのではなく、アプリケーションの最後に (つまり 1 回だけ) 呼び出す必要があることを認識しています。機能をよりよく理解するためにそれらを含めました。