Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "Platki_sniegu.h"
- #include <Windows.h>
- #include "stdio.h"
- #include <list>
- #include <ctime>
- using namespace std;
- #define SZE 100
- #define WYS 80
- TCHAR Class_Name[] = TEXT("OKNO_TEST");
- MSG Komunikat;
- int zmienna = 0;
- char ilosc[128];
- HINSTANCE *hInst;
- HWND okno1;
- int roztopy=0;
- const WORD ID_TIMER = 1;
- RECT WymiaryOkna;
- int licznik = 0;
- int index = 0;
- int level = 0;
- HBRUSH tlo, platek_srodek;
- HPEN obrys;
- int inc = 0;
- RECT tablica[1000];
- void DodajPlatek(int idx)
- {
- RECT temp;
- temp.left = rand() % 800+50; // (rand() % 98) + WymiaryOkna.right/100
- temp.top = 30;
- temp.right = temp.left + 30;
- temp.bottom = 60;
- tablica[idx] = temp;
- }
- void WarstawNizej(int idx)
- {
- for (int i = 0; i < idx - 1; i++)
- {
- int random = rand() % 30;
- RECT temp = tablica[i];
- if (temp.bottom + 30 < (WymiaryOkna.bottom - (i * 2)) )
- {
- if (rand() % 2)
- {
- temp.left -= random;
- temp.right -= random;
- }
- else
- {
- temp.left += random;
- temp.right +=random;
- }
- temp.top += 30;
- temp.bottom += 30;
- }
- tablica[i] = temp;
- }
- }
- void Roztop(int roztopy) {
- for (int i = roztopy - 10; i < roztopy; i++)
- {
- RECT temp = tablica[i];
- temp.left = 0;
- temp.right = 0;
- temp.top = 0;
- temp.bottom = 0;
- tablica[i] = temp;
- }
- }
- void Rysuj(int idx) {
- HDC hdc = GetDC(okno1);
- FillRect(hdc, &WymiaryOkna, tlo);
- Ellipse(hdc, 60, 60, 30, 30);
- SelectObject(hdc, platek_srodek);
- for (int i = 0; i < idx; i++)
- {
- Rectangle(hdc, tablica[i].left, tablica[i].top, tablica[i].right, tablica[i].bottom);
- }
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- GetClientRect(hwnd, &WymiaryOkna);
- switch (msg) {
- case WM_CREATE:
- {
- SetTimer(hwnd, 1, 100, NULL);
- tlo = CreateSolidBrush(RGB(128, 0, 128));
- platek_srodek = CreateSolidBrush(RGB(115 , 215 , 215));
- obrys = CreatePen(PS_SOLID, 3, RGB(0, 20, 222));
- }
- case WM_TIMER:
- licznik++;
- DodajPlatek(index);
- WarstawNizej(index);
- if (licznik == 9)
- {
- licznik = 0;
- roztopy++;
- }
- if (inc == 99)
- {
- Roztop(roztopy);
- inc = 0;
- }
- Rysuj(index);
- index++;
- break;
- case WM_LBUTTONDOWN:
- KillTimer(hwnd, ID_TIMER);
- licznik = 0;
- level = 0;
- index = 0;
- SetTimer(hwnd, 1, 100, NULL);
- break;
- case WM_CLOSE:
- if ((MessageBox(hwnd, TEXT("Czy chcesz wyłączyć okno ?"), TEXT("Pytanie"), MB_OKCANCEL)) == IDOK)
- DestroyWindow(hwnd);
- else break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProcW(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- hInst = &hInstance;
- WNDCLASSEX window;
- window.cbClsExtra = NULL;
- window.cbSize = sizeof(WNDCLASSEX);
- window.cbWndExtra = NULL;
- window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- window.hCursor = LoadCursor(*hInst, IDC_ARROW);
- window.hIcon = LoadIcon(*hInst, IDI_APPLICATION);
- window.hIconSm = NULL;
- window.hInstance = *hInst;
- window.lpfnWndProc = WndProc;
- window.lpszClassName = Class_Name;
- window.lpszMenuName = 0;
- window.style = NULL;
- if (!RegisterClassEx(&window)) {
- MessageBox(NULL, TEXT("Zarejestrowanie klasy nieudane! =("), TEXT("WARNING"), MB_OK | MB_ICONWARNING);
- return 1;
- }
- okno1 = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, TEXT("Okno 1"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1000, 800, NULL, NULL, *hInst, NULL);
- if (okno1 == NULL) {
- MessageBox(NULL, TEXT("Stworzenie okna nieudane! =("), TEXT("WARNING"), MB_OK | MB_ICONWARNING);
- return 2;
- }
- ShowWindow(okno1, nCmdShow);
- UpdateWindow(okno1);
- while (GetMessage(&Komunikat, NULL, 0, 0)) {
- TranslateMessage(&Komunikat);
- DispatchMessage(&Komunikat);
- }
- UnregisterClass(Class_Name, *hInst);
- return Komunikat.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement