Advertisement
Guest User

Untitled

a guest
Dec 1st, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.80 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <random>
  5. #include <chrono>
  6. #include <sstream>
  7.  
  8. #define ID_PRZYCISK1 501
  9. #define ID_PRZYCISK2 502
  10. #define ID_PRZYCISK3 503
  11. #define ID_PRZYCISK4 504
  12. #define ID_PRZYCISK5 505
  13. #define ID_PRZYCISK6 506
  14. #define ID_PRZYCISK7 507
  15. #define ID_PRZYCISK8 508
  16. #define ID_PRZYCISK9 509
  17. #define ID_PRZYCISK10 510
  18. #define ID_PRZYCISK11 511
  19. #define ID_PRZYCISK12 512
  20. #define ID_PRZYCISK13 513
  21. #define ID_PRZYCISK14 514
  22. #define ID_PRZYCISK15 515
  23. #define ID_PRZYCISK16 516
  24. #define ID_PRZYCISK17 517
  25. #define ID_PRZYCISK18 518
  26.  
  27.  
  28.  
  29. int tab[4][4];
  30.  
  31.  
  32. HWND g_hPrzycisk;
  33.  
  34. LPSTR NazwaKlasy = "Klasa Okienka";
  35. MSG Komunikat;
  36.  
  37. LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
  38.  
  39.  
  40. HWND hButton1, hButton2, hButton3, hButton4, hButton5, hButton6, hButton7, hButton8, hButton9, hButton10, hButton11, hButton12, hButton13, hButton14, hButton15, hButton16, hButton17, hButton18;
  41.  
  42.  
  43. int losowanie()
  44.   {
  45.    int Tab[4][4]={{1,1,2,2},{3,3,4,4},{5,5,6,6},{7,7,8,8}};
  46.    unsigned seed=std::chrono::system_clock::now().time_since_epoch().count();
  47.    std::shuffle(&Tab[0][0],&Tab[0][0]+16,std::default_random_engine(seed));
  48.    for(int y=0;y<4;++y,std::cout<<std::endl) for(int x=0;x<4;++x) std::cout<<' '<<Tab[y][x];
  49.    return 0;
  50.   }
  51.  
  52.  
  53.  
  54. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  55. {
  56.  
  57.  
  58.     losowanie();
  59. /*
  60. int tab[15];
  61.  
  62. tab[ 0 ] = 1;
  63. tab[ 1 ] = 2;
  64. tab[ 2 ] = 3;
  65. tab[ 3 ] = 4;
  66. tab[ 4 ] = 5;
  67. tab[ 5 ] = 6;
  68. tab[ 6 ] = 7;
  69. tab[ 7 ] = 8;
  70. tab[ 8 ] = 1;
  71. tab[ 9 ] = 2;
  72. tab[ 10 ] = 3;
  73. tab[ 11 ] = 4;
  74. tab[ 12 ] = 5;
  75. tab[ 13 ] = 6;
  76. tab[ 14 ] = 7;
  77. tab[ 15 ] = 8;
  78.  
  79. */
  80.     // WYPE£NIANIE STRUKTURY
  81.     WNDCLASSEX wc;
  82.  
  83.     wc.cbSize = sizeof( WNDCLASSEX );
  84.     wc.style = 0;
  85.     wc.lpfnWndProc = WndProc;
  86.     wc.cbClsExtra = 0;
  87.     wc.cbWndExtra = 0;
  88.     wc.hInstance = hInstance;
  89.     wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
  90.     wc.hCursor = LoadCursor( NULL, IDC_ARROW );
  91.     wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 1 );
  92.     wc.lpszMenuName = NULL;
  93.     wc.lpszClassName = NazwaKlasy;
  94.     wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
  95.  
  96.     // REJESTROWANIE KLASY OKNA
  97.     if( !RegisterClassEx( & wc ) )
  98.     {
  99.         MessageBox( NULL, "Wysoka Komisja odmawia rejestracji tego okna!", "Niestety...",
  100.         MB_ICONEXCLAMATION | MB_OK );
  101.         return 1;
  102.     }
  103.  
  104.     // TWORZENIE OKNA
  105.     HWND hwnd;
  106.  
  107.     hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, NazwaKlasy, "Gra w pamiec", WS_OVERLAPPEDWINDOW,
  108.     CW_USEDEFAULT, CW_USEDEFAULT, 900, 620, NULL, NULL, hInstance, NULL );
  109.  
  110.     if( hwnd == NULL )
  111.     {
  112.         MessageBox( NULL, "", "", MB_ICONEXCLAMATION );
  113.         return 1;
  114.     }
  115.  
  116.     ShowWindow( hwnd, nCmdShow ); // Poka¿ okienko...
  117.  
  118.     UpdateWindow( hwnd );
  119.  
  120. int a = 7;
  121.  
  122.  
  123. HWND hButton1 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "Nowa Gra", WS_CHILD | WS_VISIBLE |
  124. WS_BORDER, 700, 40, 150, 30, hwnd,( HMENU ) ID_PRZYCISK1, hInstance, NULL ),
  125. hButton3 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  126. WS_BORDER, 100, 50, 100, 100, hwnd,( HMENU ) ID_PRZYCISK3, hInstance, NULL );
  127. hButton4 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  128. WS_BORDER, 100, 155, 100, 100, hwnd,( HMENU ) ID_PRZYCISK4, hInstance, NULL );
  129. hButton5 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  130. WS_BORDER, 100, 260, 100, 100, hwnd,( HMENU ) ID_PRZYCISK5, hInstance, NULL );
  131. hButton6 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  132. WS_BORDER, 100, 365, 100, 100, hwnd,( HMENU ) ID_PRZYCISK6, hInstance, NULL );
  133. hButton7 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  134. WS_BORDER, 205, 50, 100, 100, hwnd,( HMENU ) ID_PRZYCISK7, hInstance, NULL );
  135. hButton8 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  136. WS_BORDER, 205, 155, 100, 100, hwnd,( HMENU ) ID_PRZYCISK8, hInstance, NULL );
  137. hButton9 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  138. WS_BORDER, 205, 260, 100, 100, hwnd,( HMENU ) ID_PRZYCISK9, hInstance, NULL );
  139. hButton10 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  140. WS_BORDER, 205, 365, 100, 100, hwnd,( HMENU ) ID_PRZYCISK10, hInstance, NULL );
  141. hButton11 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  142. WS_BORDER, 310, 50, 100, 100, hwnd,( HMENU ) ID_PRZYCISK11, hInstance, NULL );
  143. hButton12 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  144. WS_BORDER, 310, 155, 100, 100, hwnd,( HMENU ) ID_PRZYCISK12, hInstance, NULL );
  145. hButton13 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  146. WS_BORDER, 310, 260, 100, 100, hwnd,( HMENU ) ID_PRZYCISK13, hInstance, NULL );
  147. hButton14 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  148. WS_BORDER, 310, 365, 100, 100, hwnd,( HMENU ) ID_PRZYCISK14, hInstance, NULL );
  149. hButton15 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  150. WS_BORDER, 415, 50, 100, 100, hwnd,( HMENU ) ID_PRZYCISK15, hInstance, NULL );
  151. hButton16 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  152. WS_BORDER, 415, 155, 100, 100, hwnd,( HMENU ) ID_PRZYCISK16, hInstance, NULL );
  153. hButton17 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "", WS_CHILD | WS_VISIBLE |
  154. WS_BORDER, 415, 260, 100, 100, hwnd,( HMENU ) ID_PRZYCISK17, hInstance, NULL );
  155. hButton18 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON","", WS_CHILD | WS_VISIBLE |
  156. WS_BORDER, 415, 365, 100, 100, hwnd,( HMENU ) ID_PRZYCISK18, hInstance, NULL );
  157.  
  158.  
  159. HWND hStatic = CreateWindowEx( 0, "STATIC", NULL, WS_CHILD | WS_VISIBLE |
  160. SS_CENTER, 700, 120, 150, 50, hwnd, NULL, hInstance, NULL );  //czas gry
  161.  
  162. SetWindowText( hStatic, "Czas gry" );
  163.  
  164.     // Pêtla komunikatów
  165.     while( GetMessage( & Komunikat, NULL, 0, 0 ) )
  166.     {
  167.         TranslateMessage( & Komunikat );
  168.         DispatchMessage( & Komunikat );
  169.     }
  170.     return Komunikat.wParam;
  171. }
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178. // OBS£UGA ZDARZEÑ
  179. LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
  180. {
  181.     switch( msg )
  182.     {
  183.  
  184.         case WM_COMMAND:
  185.  
  186. {
  187.  
  188. switch(wParam)
  189.  
  190.         {
  191.             case ID_PRZYCISK1:
  192.                 losowanie();
  193.  
  194.             default:
  195.            if((ID_PRZYCISK3<=wParam)&&(wParam<=ID_PRZYCISK18))
  196.            {
  197.               char str[8];
  198.               int yx=wParam-ID_PRZYCISK3,y=yx/4,x=yx-4*y;
  199.               sprintf(str,"%d", tab[y][x]);
  200.               SetDlgItemText(hButton2,wParam,str);
  201.            }
  202.         }
  203.  
  204.  
  205. }
  206. break;
  207.  
  208.     case WM_CLOSE:
  209.         DestroyWindow( hwnd );
  210.         break;
  211.  
  212.     case WM_DESTROY:
  213.         PostQuitMessage( 0 );
  214.         break;
  215.  
  216.         default:
  217.         return DefWindowProc( hwnd, msg, wParam, lParam );
  218.     }
  219.  
  220.     return 0;
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement