// // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); POINTS mouse = MAKEPOINTS(lParam); switch (message) { case WM_CREATE: box.top = 100; box.bottom = 200; box.left = 100; box.right = 200; clock.setPosition(150, 150, 250, 250); pile.setPosition(100, 50, 120, 150); pile.setValue(60); pile.setChange(-500); pile.setCompLarger(false); break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: { hdc = BeginPaint(hWnd, &ps); #ifdef CLOCK clock.draw(hdc); #endif #ifdef PILE pile.draw(hdc); //Rectangle(hdc, 100, 50, 70, 200); #endif #ifdef BOX RECT rt; GetClientRect(hWnd, &rt); HPEN pen = CreatePen(PS_SOLID, 4, RGB(0,0,0)); HPEN oldPen = (HPEN)SelectObject(hdc, pen); HBRUSH brush; HBRUSH original_brush; brush = CreateSolidBrush(RGB(250,245,100)); original_brush = (HBRUSH)SelectObject(hdc, brush); Rectangle(hdc, box.left, box.top, box.right, box.bottom); SelectObject (hdc, original_brush); DeleteObject (brush); SelectObject (hdc, oldPen); DeleteObject (pen); #endif EndPaint(hWnd, &ps); } break; case WM_LBUTTONDOWN: #ifdef CLOCK clock.start(hWnd, 2); #endif #ifdef BOX SetTimer(hWnd, // handle to main window 1001, // timer identifier 25, // 0.01-second interval (TIMERPROC) MyTimerProc); // timer callback #endif break; case WM_RBUTTONDOWN: box.left = mouse.x; box.top = mouse.y; box.right = box.left + 5; box.bottom = box.top + 5; InvalidateRect(hWnd, NULL, TRUE); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }