-
반응형#include <windows.h>LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,WPARAM wParam, LPARAM lParam);void CALLBACK TimerProc(HWND hwnd, UINT msg, UINT id, DWORD time);void DrawCircle(HDC hdc, POINT pt){Ellipse(hdc, pt.x - 10, pt.y - 10, pt.x + 10, pt.y + 10);}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpszCmdLine, int nCmdShow){HWND hwnd;MSG msg;WNDCLASS WndClass;WndClass.style = CS_HREDRAW | CS_VREDRAW;WndClass.lpfnWndProc = WndProc;WndClass.cbClsExtra = 0;WndClass.cbWndExtra = 0;WndClass.hInstance = hInstance;WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);WndClass.lpszMenuName = NULL;WndClass.lpszClassName = "Window Class Name";RegisterClass(&WndClass);hwnd = CreateWindow("Window Class Name","Window Title Name",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd, nCmdShow);UpdateWindow(hwnd);while (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}return (int)msg.wParam;}LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,WPARAM wParam, LPARAM lParam){HDC hdc;PAINTSTRUCT ps;static bool bTimer = false;static RECT client_rect;static POINT circle;static int x_increase;static int y_increase;switch (iMsg){case WM_CREATE:srand(GetTickCount());break;case WM_TIMER:{circle.x += x_increase;circle.y += y_increase;if (circle.x <= 0 || circle.x >= client_rect.right)x_increase = -x_increase;if (circle.y <= 0 || circle.y >= client_rect.bottom)y_increase = -y_increase;InvalidateRect(hwnd, NULL, TRUE);}break;case WM_SIZE:GetClientRect(hwnd, &client_rect);circle.x = LOWORD(lParam) / 2;circle.y = HIWORD(lParam) / 2;break;case WM_LBUTTONDOWN:{if (bTimer == false){if (rand() % 2)//렌드가 홀수면 양수{x_increase = rand() % 10;}else//렌드가 짝수면 음수{x_increase = -rand() % 10;}if (rand() % 2)//렌드가 홀수면 양수{y_increase = rand() % 10;}else//렌드가 짝수면 음수{y_increase = -rand() % 10;}SetTimer(hwnd, 1, 1, NULL);}else{KillTimer(hwnd, 1);}bTimer ^= true;}break;case WM_PAINT:hdc = BeginPaint(hwnd, &ps);DrawCircle(hdc, circle);EndPaint(hwnd, &ps);break;case WM_DESTROY:PostQuitMessage(0);break;}return DefWindowProc(hwnd, iMsg, wParam, lParam);}반응형
'C++' 카테고리의 다른 글
C++ 미니 방탈출 (0) 2018.07.04 C++ 전화번호부 만들기 (0) 2017.11.17 댓글