LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: { hdc = GetDC(hWnd); GetClientRect(hWnd,&rect); int ret = SetTimer(hWnd, TIMER_ID, 5, NULL); initFigures(); break; } case WM_PAINT: { BeginPaint(hWnd, &ps); Paint(hWnd, &ps); EndPaint(hWnd, &ps); } break; case WM_LBUTTONDOWN: { Figure *figure; figure = new Figure(rand()%rect.right, rand()%rect.bottom, 100, 100); figure->setCircle(false); figure->setDir(rand()%4); figure->setVelocity(rand()%8 + 1); figure->setColor(rand()%250, rand()%250, rand()%250); vec.push_back(*figure); vectorSize++; break; } case WM_MOUSEWHEEL : { int deltaZ = (short) HIWORD(wParam); if(deltaZ > 0) { velocity += 2; }else { if(velocity > 0) velocity -= 2; } break; } case WM_TIMER: { InvalidateRect(hWnd, &rect, FALSE); } break; case WM_DESTROY: { KillTimer(hWnd, TIMER_ID); PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, msg, wParam, lParam); }
void initFigures() { srand(time(NULL)); Figure *figure; for(int i = 0; i < vectorSize; i++) { figure = new Figure(rand()%rect.right, rand()%rect.bottom, 50, 50); figure->setCircle(false); figure->setDir(rand()%4); figure->setVelocity(rand()%1 + 1); figure->setColor(rand()%250, rand()%250, rand()%250); figure->setCircle(true); vec.push_back(*figure); } }