LRESULT CALLBACK WndProc()

in cpp/HelloComposition/HelloComposition/HelloComposition.cpp [128:183]


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_CREATE:
	{
		compHost->Initialize(hWnd);
		srand(time(nullptr));

		CreateWindow(TEXT("button"), TEXT("Add element"),
			WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
			12, 12, 100, 50,
			hWnd, (HMENU)BTN_ADD, nullptr, nullptr);
	}
	break;
	case WM_COMMAND:
	{
		int wmId = LOWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		case BTN_ADD: // addButton click
		{
			double size = (double)(rand() % 150 + 50);
			double x = (double)(rand() % 600);
			double y = (double)(rand() % 200);
			compHost->AddElement(size, x, y);
			break;
		}
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
	}
	break;
	case WM_PAINT:
	{
		PAINTSTRUCT ps;
		HDC hdc = BeginPaint(hWnd, &ps);
		// TODO: Add any drawing code that uses hdc here...
		EndPaint(hWnd, &ps);
	}
	break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}