Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <iostream>
- #include <algorithm>
- #include <random>
- #include <chrono>
- #include <sstream>
- #define ID_PRZYCISK1 501
- #define ID_PRZYCISK2 502
- #define ID_PRZYCISK3 503
- #define ID_PRZYCISK4 504
- #define ID_PRZYCISK5 505
- #define ID_PRZYCISK6 506
- #define ID_PRZYCISK7 507
- #define ID_PRZYCISK8 508
- #define ID_PRZYCISK9 509
- #define ID_PRZYCISK10 510
- #define ID_PRZYCISK11 511
- #define ID_PRZYCISK12 512
- #define ID_PRZYCISK13 513
- #define ID_PRZYCISK14 514
- #define ID_PRZYCISK15 515
- #define ID_PRZYCISK16 516
- #define ID_PRZYCISK17 517
- #define ID_PRZYCISK18 518
- int tab[4][4];
- HWND g_hPrzycisk;
- LPSTR NazwaKlasy = "Klasa Okienka";
- MSG Komunikat;
- LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
- HWND hButton1, hButton2, hButton3, hButton4, hButton5, hButton6, hButton7, hButton8, hButton9, hButton10, hButton11, hButton12, hButton13, hButton14, hButton15, hButton16, hButton17, hButton18;
- int losowanie()
- {
- int tab[4][4]={{1,1,2,2},{3,3,4,4},{5,5,6,6},{7,7,8,8}};
- unsigned seed=std::chrono::system_clock::now().time_since_epoch().count();
- std::shuffle(&tab[0][0],&tab[0][0]+16,std::default_random_engine(seed));
- for(int y=0;y<4;++y,std::cout<<std::endl) for(int x=0;x<4;++x) std::cout<<' '<<tab[y][x];
- return 0;
- }
- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
- {
- losowanie();
- /*
- int tab[15];
- tab[ 0 ] = 1;
- tab[ 1 ] = 2;
- tab[ 2 ] = 3;
- tab[ 3 ] = 4;
- tab[ 4 ] = 5;
- tab[ 5 ] = 6;
- tab[ 6 ] = 7;
- tab[ 7 ] = 8;
- tab[ 8 ] = 1;
- tab[ 9 ] = 2;
- tab[ 10 ] = 3;
- tab[ 11 ] = 4;
- tab[ 12 ] = 5;
- tab[ 13 ] = 6;
- tab[ 14 ] = 7;
- tab[ 15 ] = 8;
- */
- // WYPE£NIANIE STRUKTURY
- WNDCLASSEX wc;
- wc.cbSize = sizeof( WNDCLASSEX );
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
- wc.hCursor = LoadCursor( NULL, IDC_ARROW );
- wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 1 );
- wc.lpszMenuName = NULL;
- wc.lpszClassName = NazwaKlasy;
- wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
- // REJESTROWANIE KLASY OKNA
- if( !RegisterClassEx( & wc ) )
- {
- MessageBox( NULL, "Wysoka Komisja odmawia rejestracji tego okna!", "Niestety...",
- MB_ICONEXCLAMATION | MB_OK );
- return 1;
- }
- // TWORZENIE OKNA
- HWND hwnd;
- hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, NazwaKlasy, "Gra w pamiec", WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 900, 620, NULL, NULL, hInstance, NULL );
- if( hwnd == NULL )
- {
- MessageBox( NULL, "", "", MB_ICONEXCLAMATION );
- return 1;
- }
- ShowWindow( hwnd, nCmdShow ); // Poka¿ okienko...
- UpdateWindow( hwnd );
- int a = 7;
- HWND hButton1 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "Nowa Gra", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 700, 40, 150, 30, hwnd,( HMENU ) ID_PRZYCISK1, hInstance, NULL ),
- hButton3 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 100, 50, 100, 100, hwnd,( HMENU ) ID_PRZYCISK3, hInstance, NULL );
- hButton4 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 100, 155, 100, 100, hwnd,( HMENU ) ID_PRZYCISK4, hInstance, NULL );
- hButton5 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 100, 260, 100, 100, hwnd,( HMENU ) ID_PRZYCISK5, hInstance, NULL );
- hButton6 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 100, 365, 100, 100, hwnd,( HMENU ) ID_PRZYCISK6, hInstance, NULL );
- hButton7 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 205, 50, 100, 100, hwnd,( HMENU ) ID_PRZYCISK7, hInstance, NULL );
- hButton8 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 205, 155, 100, 100, hwnd,( HMENU ) ID_PRZYCISK8, hInstance, NULL );
- hButton9 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 205, 260, 100, 100, hwnd,( HMENU ) ID_PRZYCISK9, hInstance, NULL );
- hButton10 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 205, 365, 100, 100, hwnd,( HMENU ) ID_PRZYCISK10, hInstance, NULL );
- hButton11 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 310, 50, 100, 100, hwnd,( HMENU ) ID_PRZYCISK11, hInstance, NULL );
- hButton12 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 310, 155, 100, 100, hwnd,( HMENU ) ID_PRZYCISK12, hInstance, NULL );
- hButton13 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 310, 260, 100, 100, hwnd,( HMENU ) ID_PRZYCISK13, hInstance, NULL );
- hButton14 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 310, 365, 100, 100, hwnd,( HMENU ) ID_PRZYCISK14, hInstance, NULL );
- hButton15 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 415, 50, 100, 100, hwnd,( HMENU ) ID_PRZYCISK15, hInstance, NULL );
- hButton16 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 415, 155, 100, 100, hwnd,( HMENU ) ID_PRZYCISK16, hInstance, NULL );
- hButton17 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 415, 260, 100, 100, hwnd,( HMENU ) ID_PRZYCISK17, hInstance, NULL );
- hButton18 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON","", WS_CHILD | WS_VISIBLE |
- WS_BORDER, 415, 365, 100, 100, hwnd,( HMENU ) ID_PRZYCISK18, hInstance, NULL );
- HWND hStatic = CreateWindowEx( 0, "STATIC", NULL, WS_CHILD | WS_VISIBLE |
- SS_CENTER, 700, 120, 150, 50, hwnd, NULL, hInstance, NULL ); //czas gry
- SetWindowText( hStatic, "Czas gry" );
- // Pêtla komunikatów
- while( GetMessage( & Komunikat, NULL, 0, 0 ) )
- {
- TranslateMessage( & Komunikat );
- DispatchMessage( & Komunikat );
- }
- return Komunikat.wParam;
- }
- // OBS£UGA ZDARZEÑ
- LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
- {
- switch( msg )
- {
- case WM_COMMAND:
- {
- switch(wParam)
- {
- case ID_PRZYCISK1:
- losowanie();
- default:
- if((ID_PRZYCISK3<=wParam)&&(wParam<=ID_PRZYCISK18))
- {
- char str[8];
- int yx=wParam-ID_PRZYCISK3,y=yx/4,x=yx-4*y;
- sprintf(str,"%d", tab[x][y]);
- SetDlgItemText(hwnd,wParam,str);
- }
- }
- }
- break;
- case WM_CLOSE:
- DestroyWindow( hwnd );
- break;
- case WM_DESTROY:
- PostQuitMessage( 0 );
- break;
- default:
- return DefWindowProc( hwnd, msg, wParam, lParam );
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement