»Ë»Ñ Æ÷·³
°³¹ßÀÚÆ÷·³ ÀÔ´Ï´Ù.
  • ºÏ¸¶Å© ¾ÆÀÌÄÜ

api TIMER ¸ØÃߴ¹ý? Áú¹®µå¸³´Ï´Ù3

  • ¿¤¸Þ
  • µî·ÏÀÏ 2013-05-20 17:27
  • Á¶È¸¼ö 242
#include


LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg,
                                                  WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                                   LPTSTR 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 msg.wParam;
}


LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)    
{
        HDC hdc;
        PAINTSTRUCT ps;
        static int x = 20, y = 20;
        static RECT rect;


        switch (iMsg)
        {
        case WM_CREATE:
                break;

        case WM_PAINT:
                hdc=BeginPaint(hwnd,&ps);

                // À­ÁÙ
                Rectangle(hdc, 0, 0, 20, 20);
                Rectangle(hdc, 20, 0, 40, 20);
                Rectangle(hdc, 40, 0, 60, 20);
                Rectangle(hdc, 60, 0, 80, 20);
                Rectangle(hdc, 80, 0, 100, 20);
                Rectangle(hdc, 100, 0, 120, 20);
                Rectangle(hdc, 120, 0, 140, 20);
                Rectangle(hdc, 140, 0, 160, 20);
                Rectangle(hdc, 160, 0, 180, 20);
                Rectangle(hdc, 180, 0, 200, 20);
                Rectangle(hdc, 200, 0, 220, 20);
                Rectangle(hdc, 220, 0, 240, 20);
                Rectangle(hdc, 240, 0, 260, 20);
                Rectangle(hdc, 260, 0, 280, 20);
                Rectangle(hdc, 280, 0, 300, 20);
                Rectangle(hdc, 300, 0, 320, 20);
                Rectangle(hdc, 320, 0, 340, 20);
                Rectangle(hdc, 340, 0, 360, 20);
                Rectangle(hdc, 360, 0, 380, 20);
                Rectangle(hdc, 380, 0, 400, 20);

                // ¿ÞÂÊÁÙ
                Rectangle(hdc, 0, 0, 20, 20);
                Rectangle(hdc, 0, 20, 20, 40);
                Rectangle(hdc, 0, 40, 20, 60);
                Rectangle(hdc, 0, 60, 20, 80);
                Rectangle(hdc, 0, 80, 20, 100);
                Rectangle(hdc, 0, 100, 20, 120);
                Rectangle(hdc, 0, 120, 20, 140);
                Rectangle(hdc, 0, 140, 20, 160);
                Rectangle(hdc, 0, 160, 20, 180);
                Rectangle(hdc, 0, 180, 20, 200);
                Rectangle(hdc, 0, 200, 20, 220);
                Rectangle(hdc, 0, 220, 20, 240);
                Rectangle(hdc, 0, 240, 20, 260);
                Rectangle(hdc, 0, 260, 20, 280);
                Rectangle(hdc, 0, 280, 20, 300);
                Rectangle(hdc, 0, 300, 20, 320);
                Rectangle(hdc, 0, 320, 20, 340);
                Rectangle(hdc, 0, 340, 20, 360);
                Rectangle(hdc, 0, 360, 20, 380);
                Rectangle(hdc, 0, 380, 20, 400);

                // ¾Æ·§ÁÙ
                Rectangle(hdc, 0, 380, 20, 400);
                Rectangle(hdc, 20, 380, 40, 400);
                Rectangle(hdc, 40, 380, 60, 400);
                Rectangle(hdc, 60, 380, 80, 400);
                Rectangle(hdc, 80, 380, 100, 400);
                Rectangle(hdc, 100, 380, 120, 400);
                Rectangle(hdc, 120, 380, 140, 400);
                Rectangle(hdc, 140, 380, 160, 400);
                Rectangle(hdc, 160, 380, 180, 400);
                Rectangle(hdc, 180, 380, 200, 400);
                Rectangle(hdc, 200, 380, 220, 400);
                Rectangle(hdc, 220, 380, 240, 400);
                Rectangle(hdc, 240, 380, 260, 400);
                Rectangle(hdc, 260, 380, 280, 400);
                Rectangle(hdc, 280, 380, 300, 400);
                Rectangle(hdc, 300, 380, 320, 400);
                Rectangle(hdc, 320, 380, 340, 400);
                Rectangle(hdc, 340, 380, 360, 400);
                Rectangle(hdc, 360, 380, 380, 400);
                Rectangle(hdc, 380, 380, 400, 400);

                // ¿À¸¥ÂÊÁÙ
                Rectangle(hdc, 380, 0, 400, 20);
                Rectangle(hdc, 380, 20, 400, 40);
                Rectangle(hdc, 380, 40, 400, 60);
                Rectangle(hdc, 380, 60, 400, 80);
                Rectangle(hdc, 380, 80, 400, 100);
                Rectangle(hdc, 380, 100, 400, 120);
                Rectangle(hdc, 380, 120, 400, 140);
                Rectangle(hdc, 380, 140, 400, 160);
                Rectangle(hdc, 380, 160, 400, 180);
                Rectangle(hdc, 380, 180, 400, 200);
                Rectangle(hdc, 380, 200, 400, 220);
                Rectangle(hdc, 380, 220, 400, 240);
                Rectangle(hdc, 380, 240, 400, 260);
                Rectangle(hdc, 380, 260, 400, 280);
                Rectangle(hdc, 380, 280, 400, 300);
                Rectangle(hdc, 380, 300, 400, 320);
                Rectangle(hdc, 380, 320, 400, 340);
                Rectangle(hdc, 380, 340, 400, 360);
                Rectangle(hdc, 380, 360, 400, 380);
                Rectangle(hdc, 380, 380, 400, 400);

                Ellipse(hdc, x, y, x+20, y+20);

                rect.right = 380;
                rect.left = 0;
                rect.bottom = 380;
                rect.top = 0;

                EndPaint(hwnd,&ps);
                break;

        case WM_KEYDOWN:
                if (wParam == VK_RIGHT)
                {
                        SetTimer(hwnd, 1, 500, NULL);
                        x += 20;
                        if (x + 20 > rect.right) x -= 20;

                }

                if (wParam == VK_LEFT)
                {
                        SetTimer(hwnd, 2, 500, NULL);
                        x -= 20;
                        if (x - 20 < rect.left) x += 20;<br />                 }


                if (wParam == VK_UP)
                {
                        SetTimer(hwnd, 3, 500, NULL);
                        y -= 20;
                        if (y - 20 < rect.top) y += 20;<br />                 }

                if (wParam == VK_DOWN)
                {
                        SetTimer(hwnd, 4, 500, NULL);
                        y += 20;
                        if (y + 20 > rect.bottom) y -= 20;
                }

                InvalidateRgn(hwnd, NULL, TRUE);
                break;

        case WM_TIMER:
                switch(wParam)
                {
                case 1:
                        x += 20;
                        if (x + 20 > rect.right) x -= 20;
                        break;
                case 2:
                        x -= 20;
                        if (x - 20 < rect.left) x += 20;<br />                         break;
                case 3:
                        y -= 20;
                        if (y - 20 < rect.top) y += 20;<br />                         break;
                case 4:
                        y += 20;
                        if (y + 20 > rect.bottom) y -= 20;
                        break;
                }
                InvalidateRgn(hwnd, NULL, TRUE);
                return 0;


        case WM_DESTROY:
                KillTimer(hwnd, 1);
                KillTimer(hwnd, 2);
                KillTimer(hwnd, 3);
                KillTimer(hwnd, 4);
                PostQuitMessage (0) ;
                break;

        }
        return DefWindowProc (hwnd, iMsg, wParam, lParam);
}

ÀÌ·¸°Ô ¼Ò½º¸¦ ­´Âµ¥

> ¹æÇâÅ°¸¦ ´­¸®¸é ¼³Á¤ÇÑ°÷±îÁö Âß°¡¼­ ¸ØÃߴµ¥
< ¹æÇâÅ°¸¦ ´­¸®¸é >< °°ÀÌ Çؼ­ Á¦ÀÚ¸®¿¡ ¸ØÃߴµ¥ ¾î¶»°Ô ÇØ°áÇØ¾ß µÇ³ª¿ä?<!--"<-->

0
ÃßõÇϱ⠴ٸ¥ÀÇ°ß 0
|
°øÀ¯¹öÆ°

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¼Ò´Ð´Þ·á

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¿¤¸Þ

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 â©Øü¡£
  • ¾Ë¸² ¿å¼³, »óó ÁÙ ¼ö ÀÖ´Â ¾ÇÇÃÀº »ï°¡ÁÖ¼¼¿ä.
©¹æ »çÁø  
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û ¸ñ·Ïº¸±â