윈도우 프로그래밍하는데 이거 컴퓨터에 문제 심각하게 생기나요??

seungdam의 이미지

제가 코드를
#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 없는거 보고 바로 컴퓨터 다시시작 눌렀네요.. 이거 많이 심각할까요?

세벌의 이미지

code 태그를 쓰시오

jick의 이미지

혹시 메모리가 무슨 쿠키 같은 거라서 프로그램을 계속 켜놓으면 메모리를 우적우적 먹어서 메모리가 없어진다고 생각하시는 건 아니죠?

컴퓨터를 다시 시작할 필요도 없고 그냥 해당 프로그램만 죽이면 보통 아무 문제 없습니다. OS가 알아서 다 자원 환수하고 다 해줍니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.