コード例 #1
0
LRESULT CALLBACK wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	LONG_PTR userdata;
	ID2D1HwndRenderTarget *rt = NULL;
	WINDOWPOS *wp = (WINDOWPOS *) lParam;
	RECT client;
	D2D1_SIZE_U size;

	userdata = GetWindowLongPtrW(hwnd, GWLP_USERDATA);
	if (userdata == 0) {
		if (uMsg == WM_CREATE)
			SetWindowLongPtrW(hwnd, GWLP_USERDATA, 1);
		return DefWindowProcW(hwnd, uMsg, wParam, lParam);
	}

	if (userdata == 1) {
		rt = mkRenderTarget(hwnd);
		if (rt == NULL) {
			PostQuitMessage(1);
			return DefWindowProcW(hwnd, uMsg, wParam, lParam);
		}
		SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) rt);
	} else
		rt = (ID2D1HwndRenderTarget *) userdata;

	switch (uMsg) {
	case WM_PAINT:
		switch (doPaint(rt)) {
		case S_OK:
			ValidateRect(hwnd, NULL);
			return 0;
		case D2DERR_RECREATE_TARGET:
			rt->Release();
			SetWindowLongPtrW(hwnd, GWLP_USERDATA, 1);
			return 0;
		}
		rt->Release();
		PostQuitMessage(1);
		break;
	case WM_WINDOWPOSCHANGED:
		if ((wp->flags & SWP_NOSIZE) != 0)
			break;
		GetClientRect(hwnd, &client);
		size.width = client.right - client.left;
		size.height = client.bottom - client.top;
		rt->Resize(&size);
		InvalidateRect(hwnd, NULL, TRUE);
		return 0;
	case WM_CLOSE:
		rt->Release();
		PostQuitMessage(0);
	}
	return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
コード例 #2
0
ファイル: winmain.cpp プロジェクト: nstoker/LearnWindowsGUI1
void MainWindow::Resize()
{
	if (pRenderTarget != NULL)
	{
		RECT rc;
		GetClientRect(m_hwnd, &rc);

		D2D1_SIZE_U size = D2D1::SizeU(rc.right, rc.bottom);

		pRenderTarget->Resize(size);
		CalculateLayout();
		InvalidateRect(m_hwnd, NULL, FALSE);
	}
}