{I+=codeWee;}
[C++] Win32: Double Buffering Sample Code
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
	HDC hdc, memDC, memDCBack;
	PAINTSTRUCT ps;

	static HBITMAP hBmp, hBmpBack;
	static int yPos = 0;
	static RECT rect;

	switch(iMsg)
	{
	case WM_CREATE:
		hBmpBack = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance, MAKEINTRESOURCE(IDB_BITMAP1));
		yPos = 0;
		SetTimer(hwnd, 0, 10, NULL);
		break;
	case WM_SIZE:
		GetClientRect(hwnd, &rect);
		break;
	case WM_TIMER:
		yPos+=2;

		hdc = GetDC(hwnd);
		if(hBmp == NULL)
			hBmp = CreateCompatibleBitmap(hdc, rect.right, rect.bottom);
		memDC = CreateCompatibleDC(hdc);
		memDCBack = CreateCompatibleDC(memDC);

		SelectObject(memDC, hBmp);
		SelectObject(memDCBack, hBmpBack);

		BitBlt(memDC, 0, 0, rect.right, rect.bottom, NULL, 0, 0, WHITENESS);
		BitBlt(memDC, 0, 0, 1024, 384, memDCBack, 0, 0, SRCCOPY);

		SetBkMode(memDC, TRANSPARENT);
		TextOut(memDC, 10, yPos, _T("HelloWorld"), 10);	

		DeleteDC(memDC);
		DeleteDC(memDCBack);

		ReleaseDC(hwnd, hdc);

		InvalidateRgn(hwnd, NULL, false);
		break;
	case WM_PAINT:
		hdc = BeginPaint(hwnd, &ps);

		memDC = CreateCompatibleDC(hdc);
		SelectObject(memDC, hBmp);
		BitBlt(hdc, 0, 0, rect.right, rect.bottom, memDC, 0, 0, SRCCOPY);

		DeleteDC(memDC);
		EndPaint(hwnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	}

	return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
HTML | PHP | C++ | DirectX11 | Javascript | C# | HTML5 | ASP | SQL | General | CSS | Oculus Rift | Unity3d | Virtools SDK | Tip | NSIS | PowerShell | node.js | Web API | RTSP | All
Copyright© 2016 CodeWee.com All rights reserved.