윈도우 프로그래밍하는데 이거 컴퓨터에 문제 심각하게 생기나요??
제가 코드를
#include
#include
#include
#include
#include
#include
HINSTANCE g_hInst;
LPCTSTR lpszClass = L"Window Class Name";
LPCTSTR lpszWindowName = L"Window Programming LAb";
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wPARAM, LPARAM lParam);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASSEX WndClass;
g_hInst = hInstance;
WndClass.cbSize = sizeof(WndClass);
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = (WNDPROC)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 = lpszClass;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&WndClass);
hWnd = CreateWindow(lpszClass, lpszWindowName, WS_OVERLAPPEDWINDOW, 0, 0, 1400, 1000, NULL, (HMENU)NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&Message, 0, 0, 0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hdc;
static POINT xypos[8] = { {0,400},{200,500}, // 1번 버스 01
{1000,600},{800,500}, // 2번 버스 23
{600,0},{500,200}, // 3번 버스 45
{400,1000},{500,800}}; // 4번 버스 67
static POINT xypos_sub[8] = { {0,400},{0,500}, // 1번 버스
{1000,600},{1000,500}, // 2번 버스
{600,0},{500,0}, // 3번 버스
{400,1000},{500,1000}}; // 4번 버스
static POINT xypos_human;
HBRUSH blueBrush = CreateSolidBrush(RGB(0, 0, 255));
HBRUSH yelloBrush = CreateSolidBrush(RGB(255, 255, 0));
HBRUSH greenBrush = CreateSolidBrush(RGB(0, 255, 0));
HBRUSH redBrush = CreateSolidBrush(RGB(255, 0, 0));
HBRUSH oldBrush;
static RECT rect[4] = {
{xypos[0].x, xypos[0].y, xypos[1].x, xypos[1].y},
{xypos[2].x, xypos[2].y, xypos[3].x, xypos[3].y},
{xypos[4].x, xypos[4].y, xypos[5].x, xypos[5].y},
{xypos[6].x, xypos[6].y, xypos[7].x, xypos[7].y}
};
static RECT temp;
static int xpos[2] = { 700, 700 };
static int ypos[2] = { 400 ,500 };
// 1번버스 xypos 01 2번버스 23 3번 버스 45 4번 버스 56
switch (iMessage) {
case WM_CREATE:
SetTimer(hWnd, 1, 20, NULL);
SetTimer(hWnd, 2, 50, NULL);
SetTimer(hWnd, 3, 40, NULL);
SetTimer(hWnd, 4, 30, NULL);
break;
case WM_CHAR:
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
Rectangle(hdc, 0, 0, 400, 400);
Rectangle(hdc, 600, 0, 1000, 400);
Rectangle(hdc, 0, 600, 400, 1000);
Rectangle(hdc, 600, 600, 1000, 1000);
Rectangle(hdc, 400, 400, 600, 600);
Rectangle(hdc, 1200, 0, 1400, 300);
oldBrush = (HBRUSH)SelectObject(hdc, greenBrush);
Ellipse(hdc,1250,0,1350,100);
SelectObject(hdc, oldBrush);
oldBrush = (HBRUSH)SelectObject(hdc, yelloBrush);
Ellipse(hdc,1250,100,1350,200);
SelectObject(hdc, oldBrush);
oldBrush = (HBRUSH)SelectObject(hdc, redBrush);
Ellipse(hdc, 1250, 200, 1350, 300);
SelectObject(hdc, oldBrush);
MoveToEx(hdc, 500, 0, NULL);
LineTo(hdc, 500, 1000);
MoveToEx(hdc, 0, 500, NULL);
LineTo(hdc, 1000, 500);
oldBrush = (HBRUSH)SelectObject(hdc, blueBrush); // 새로운 브러시 선택하기
Rectangle(hdc, xypos[0].x, xypos[0].y, xypos[1].x, xypos[1].y);
Rectangle(hdc, xypos[2].x, xypos[2].y, xypos[3].x, xypos[3].y);
Rectangle(hdc, xypos[4].x, xypos[4].y, xypos[5].x, xypos[5].y);
Rectangle(hdc, xypos[6].x, xypos[6].y, xypos[7].x, xypos[7].y);
Rectangle(hdc, xypos_sub[0].x, xypos_sub[0].y, xypos_sub[1].x, xypos_sub[1].y);
Rectangle(hdc, xypos_sub[2].x, xypos_sub[2].y, xypos_sub[3].x, xypos_sub[3].y);
Rectangle(hdc, xypos_sub[4].x, xypos_sub[4].y, xypos_sub[5].x, xypos_sub[5].y);
Rectangle(hdc, xypos_sub[6].x, xypos_sub[6].y, xypos_sub[7].x, xypos_sub[7].y);
SelectObject(hdc, oldBrush);
DeleteObject(blueBrush);
DeleteObject(yelloBrush);
DeleteObject(redBrush);
DeleteObject(greenBrush);
EndPaint(hWnd, &ps);
break;
case WM_TIMER:
switch (wParam) {
case 1: // 1번 버스;
if (xypos[1].x < 1000 && xypos[0].x < 1000) {
xypos[0].x += 5;
xypos[1].x += 5;
}
else if (xypos[0].x < 1000 && xypos[1].x == 1000) {
xypos[0].x += 5;
xypos_sub[1].x += 5;
}
else if (xypos[1].x == 1000 && xypos[0].x == 1000) {
xypos_sub[1].x = 0;
xypos[0].x = 0;
xypos[1].x = 200;
}
else if (IntersectRect(&temp, &rect[0], &rect[2]) || IntersectRect(&temp, &rect[0], &rect[3])) {
SetTimer(hWnd, 1, 10000, NULL);
}
else {
SetTimer(hWnd, 1, 20, NULL);
}
break;
case 2: // 2번 버스
if (xypos[3].x > 0 && xypos[2].x > 0) {
xypos[2].x -= 5;
xypos[3].x -= 5;
}
else if (xypos[2].x > 0 && xypos[3].x == 0) {
xypos[2].x -= 5;
xypos_sub[3].x -= 5;
}
else if (xypos[2].x == 0 && xypos[3].x == 0) {
xypos_sub[3].x = 1000;
xypos[2].x = 1000;
xypos[3].x = 800;
}
break;
case 3:
if (xypos[4].y < 1000 && xypos[5].y < 1000) {
xypos[4].y += 5;
xypos[5].y += 5;
}
else if (xypos[4].y < 1000 && xypos[5].y == 1000) {
xypos[4].y += 5;
xypos_sub[5].y += 5;
}
else if (xypos[4].y == 1000 && xypos[5].y == 1000) {
xypos_sub[5].y = 0;
xypos[4].y = 0;
xypos[5].y = 200;
}
break;
case 4:
if (xypos[6].y > 0 && xypos[7].y > 0) {
xypos[6].y -= 5;
xypos[7].y -= 5;
}
else if (xypos[6].y > 0 && xypos[7].y == 0) {
xypos[6].y -= 5;
xypos_sub[7].y -= 5;
}
else if (xypos[6].y == 0 && xypos[7].y == 0) {
xypos_sub[7].y = 1000;
xypos[6].y = 1000;
xypos[7].y = 800;
}
break;
}
InvalidateRgn(hWnd, NULL, TRUE);
break;
case WM_LBUTTONDOWN:
\
if ((HIWORD(lParam) > 0 && HIWORD(lParam) < 100) && (LOWORD(lParam) > 1250 && LOWORD(lParam) < 1350)) {
}
else if ((HIWORD(lParam) > 100 && HIWORD(lParam) < 200) && (LOWORD(lParam) > 1250 && LOWORD(lParam) < 1350)) {
}
else if ((HIWORD(lParam) > 200 && HIWORD(lParam) < 300) && (LOWORD(lParam) > 1250 && LOWORD(lParam) < 1350)) {
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}
짰는데 제가 실수로 killtimer가 작성된줄알고 과제를 하다가 걱정없이 그냥 컴퓨터를 켜놓고 자버렸네요 killtimer 안쓰면 메모리누수가 심하게 난다는데 killtimer 없는거 보고 바로 컴퓨터 다시시작 눌렀네요.. 이거 많이 심각할까요?
댓글 달기