Den tanke gjorde jeg mig, men jeg håbede, svaret var et andet. Men nu har jeg gjort, så mine bitmaps kun bliver loaded én gang. Udover det har jeg forsøgt at skåne WM_PAINT så meget som muligt, ved at give den så lidt arbejde som muligt.
WM_PAINT:
case WM_PAINT:
hdcMask = BeginPaint (Window, &ps);
hdcMaskMem = CreateCompatibleDC (0);
hdcCharMem = CreateCompatibleDC (0);
SelectObject (hdcMaskMem, mask);
SelectObject (hdcCharMem, character);
BitBlt (hdcMask, CharX, CharY, bmMask.bmWidth, bmMask.bmHeight, hdcMaskMem, 0, 0, SRCAND);
BitBlt (hdcMask, CharX, CharY + 5, bmChar.bmWidth, bmChar.bmHeight, hdcCharMem, 0, 0, SRCPAINT);
DeleteDC (hdcMaskMem);
DeleteDC (hdcCharMem);
EndPaint (Window, &ps);
break;
Hele min Windows-procedure:
#include "wndproc.hpp"
LRESULT CALLBACK WndProc
(
HWND Window,
UINT Message,
WPARAM wParam,
LPARAM lParam
)
{
static PAINTSTRUCT ps;
static HDC hdcMask, hdcMaskMem, hdcChar, hdcCharMem;
static HBITMAP mask, character;
static BITMAP bmMask, bmChar;
static int CharX, CharY;
switch (Message)
{
case WM_CREATE:
CharX = 100;
CharY = 100;
mask = LoadBitmap ((HINSTANCE) GetWindowLong (Window, GWL_HINSTANCE), TEXT ("MASK_FRONT"));
character = LoadBitmap ((HINSTANCE) GetWindowLong (Window, GWL_HINSTANCE), TEXT ("CHAR_FRONT"));
GetObject (mask, sizeof (BITMAP), &bmMask);
GetObject (character, sizeof (BITMAP), &bmChar);
break;
case WM_PAINT:
hdcMask = BeginPaint (Window, &ps);
hdcMaskMem = CreateCompatibleDC (0);
hdcCharMem = CreateCompatibleDC (0);
SelectObject (hdcMaskMem, mask);
SelectObject (hdcCharMem, character);
BitBlt (hdcMask, CharX, CharY, bmMask.bmWidth, bmMask.bmHeight, hdcMaskMem, 0, 0, SRCAND);
BitBlt (hdcMask, CharX, CharY + 5, bmChar.bmWidth, bmChar.bmHeight, hdcCharMem, 0, 0, SRCPAINT);
DeleteDC (hdcMaskMem);
DeleteDC (hdcCharMem);
EndPaint (Window, &ps);
break;
case WM_KEYDOWN:
switch (wParam)
{
case VK_UP: // Move character up
CharY--;
InvalidateRect (Window, NULL, TRUE);
break;
case VK_DOWN: // Move character down
CharY++;
InvalidateRect (Window, NULL, TRUE);
break;
case VK_ESCAPE:
PostQuitMessage (0);
break;
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (Window, Message, wParam, lParam);
}
}