new_year



  • // new_year: main.cpp --- MagiC Creating
    #define UNICODE
    
    #include <windows.h>
    
    #include <cstdlib>
    #include <ctime>
    
    // ---------------------------------------------------------------------------------------------
    
    const int NEW_YEAR_TIMER = 123;
    
    struct NEW_YEAR
    {
        int x,y;
        COLORREF color;
    
        int vx,vy;
    };
    
    // ---------------------------------------------------------------------------------------------
    
    LRESULT CALLBACK MainProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
    
    // ---------------------------------------------------------------------------------------------
    
    HINSTANCE hInst;
    NEW_YEAR njArray[20];
    
    // ---------------------------------------------------------------------------------------------
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
    {
        hInst = hInstance;
    
        WNDCLASSEX main;
        main.cbSize         = sizeof(main);
        main.cbClsExtra     = 0;
        main.cbWndExtra     = 0;
        main.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);
        main.hCursor        = LoadCursor(0,IDC_ARROW);
        main.hIcon          = LoadIcon(0,IDI_APPLICATION);
        main.hIconSm        = LoadIcon(0,IDI_APPLICATION);
        main.hInstance      = hInst;
        main.lpfnWndProc    = MainProc;
        main.lpszClassName  = TEXT("new_year_class");
        main.lpszMenuName   = 0;
        main.style          = CS_HREDRAW | CS_VREDRAW;
        if(!RegisterClassEx(&main))
        {
            MessageBox(0,TEXT("Konnte Fensterklasse nicht registieren!"),TEXT("new_year"),MB_OK | MB_ICONSTOP);
            return 1;
        }
    
        HWND hMainWnd = CreateWindowEx(0,TEXT("new_year_class"),TEXT("new_year"),WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,300,300,0,0,hInst,0);
        ShowWindow(hMainWnd,nShowCmd);
        UpdateWindow(hMainWnd);
    
        MSG msgMain;
        while(GetMessage(&msgMain,0,0,0))
        {
            TranslateMessage(&msgMain);
            DispatchMessage(&msgMain);
        }
    
        return msgMain.wParam;
    }
    
    // ---------------------------------------------------------------------------------------------
    
    LRESULT CALLBACK MainProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
        static RECT rcClient;
    
        switch(uMsg)
        {
    
        case WM_TIMER:
            {
                if(wParam == NEW_YEAR_TIMER)
                {
                    for(int i = 0;i < 20;i++)
                    {
                        if(njArray[i].x < 0 || njArray[i].x > (rcClient.right - rcClient.left - 120))
                        {
                            njArray[i].vx = -njArray[i].vx;
                        }
                        if(njArray[i].y < 0 || njArray[i].y > (rcClient.bottom - rcClient.top - 20))
                        {
                            njArray[i].vy = -njArray[i].vy;
                        }
    
                        njArray[i].x += njArray[i].vx;
                        njArray[i].y += njArray[i].vy;
                    }
    
                    InvalidateRect(hWnd,0,TRUE);
                }
                return 0;
            } break;
    
        case WM_PAINT:
            {
                PAINTSTRUCT ps;
                HDC hDC = BeginPaint(hWnd,&ps);
    
                SetBkMode(hDC,TRANSPARENT);
    
                for(int i = 0;i < 20;i++)
                {
                    SetTextColor(hDC,njArray[i].color);
                    TextOut(hDC,njArray[i].x,njArray[i].y,TEXT("Happy New Year!!"),16);
                }
    
                EndPaint(hWnd,&ps);
                return 0;
            } break;
    
        case WM_CREATE:
            {
                srand((unsigned) time(0));
                SetTimer(hWnd,NEW_YEAR_TIMER,100,0);
    
                GetClientRect(hWnd,&rcClient);
    
                for(int i = 0;i < 20;i++)
                {
                    njArray[i].x = rand() % (rcClient.right - rcClient.left - 120);
                    njArray[i].y = rand() % (rcClient.bottom - rcClient.top - 20);
                    njArray[i].color = RGB(rand() % 255,rand() % 255,rand() % 255);
    
                    njArray[i].vx = -5 + (rand() % 11);
                    njArray[i].vy = -5 + (rand() % 11);
                }
                return 0;
            } break;
    
        case WM_DESTROY:
            {
                KillTimer(hWnd,NEW_YEAR_TIMER);
                PostQuitMessage(0);
                return 0;
            } break;
    
        }
    
        return DefWindowProc(hWnd,uMsg,wParam,lParam);
    }
    

    cya 🙂



  • uuuuuuuu schön 🙂



  • @Magic,

    auch Dir ein frohes neues Jahr. Sehr schön, Deine Anwendung. 🙂

    Viele Grüße

    Oliver



  • Danke, euch allen ein gutes neues Jahr :).

    cya 🙂



  • Wow Magic!!! Geiles Teil! Werd mir gleich mal reinziehen, wie du das gemacht hast.



  • Ooch, ist doch nix besonderes :D. Ich hab das früher auch immer geproggt, wie meine Mutter nicht aufhören wollte zu telefonieren und ich ins Internet wollte, nur halt mit nem anderen Text ("Hör auf zu telefonieren!") :D.

    cya 🙂



  • lol 😃



  • Jo, da hatten wir noch'n 56K Modem... 🙂

    cya 🙂



  • *PUSH* 😃



  • Mir war gar nicht bewusst, was für alte Beiträge hier archiviert sind. 🙂



  • 16 Fehler, 4 Warnungen
    Fürs neue Jahr wünsch ich mir einen neuen Compiler!
    Aber sieht bestimmt nett aus 😉 ! Also euch allen n jutes Neues!


Anmelden zum Antworten