Silviyaa

Untitled

Apr 11th, 2021
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.51 KB | None | 0 0
  1. INT_PTR CALLBACK MathTest(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  2. {
  3.     int random1 = 0;
  4.     int random2 = 0;
  5.     int random3 = 0;
  6.    // string a = "";
  7.     int a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
  8.     int b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
  9.     int c = GetDlgItemInt(hDlg, IDC_C, NULL, true);
  10.     int Correct = GetDlgItemInt(hDlg, IDC_CORRECT, NULL, true);
  11.     int Wrong = GetDlgItemInt(hDlg, IDC_WRONG, NULL, true);
  12.     char MathSymbol{};
  13.     char Txt[20];
  14.     UNREFERENCED_PARAMETER(lParam);
  15.     switch (message)
  16.     {
  17.     case WM_INITDIALOG:
  18.         CheckDlgButton(hDlg, IDC_PLUS, BST_CHECKED);
  19.  
  20.         CheckDlgButton(hDlg, IDC_1_20, BST_CHECKED);
  21.  
  22.         srand(time(0));
  23.         return (INT_PTR)TRUE;
  24.  
  25.     case WM_COMMAND:
  26.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  27.         {
  28.             EndDialog(hDlg, LOWORD(wParam));
  29.             return (INT_PTR)TRUE;
  30.         }
  31.         else if (LOWORD(wParam) == IDC_PLUS) {
  32.             if (IsDlgButtonChecked(hDlg, IDC_1_20)) {
  33.             int a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
  34.             int b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
  35.             int c = GetDlgItemInt(hDlg, IDC_C, NULL, true);
  36.             SetDlgItemInt(hDlg, IDC_LIST, a + b + c,true);
  37.         }
  38.         }
  39.         else if (LOWORD(wParam) == IDC_RANDOM) {
  40.             srand(time(NULL));
  41.             if (IsDlgButtonChecked(hDlg, IDC_1_20)) {
  42.                  random1 = rand() % (20 + 1 - 0) + 0;
  43.                  SetDlgItemInt(hDlg, IDC_A, random1, true);
  44.                 random2 = rand() % (20 + 1 - 0) + 0;
  45.                 SetDlgItemInt(hDlg, IDC_B, random2, true);
  46.                 random3 = rand() % (20 + 1 - 0) + 0;
  47.                 SetDlgItemInt(hDlg, IDC_C, random3, true);
  48.                 // int a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
  49.                //int b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
  50.             //  int c = GetDlgItemInt(hDlg, IDC_C, NULL, true);
  51.             }else if (IsDlgButtonChecked(hDlg, IDC_21_50)) {
  52.                 random1 = rand() % (50 + 1 - 21) + 21;
  53.                 SetDlgItemInt(hDlg, IDC_A, random1, true);
  54.                 random2 = rand() % (50 + 1 - 21) + 21;
  55.                 SetDlgItemInt(hDlg, IDC_B, random2, true);
  56.                 random3 = rand() % (50 + 1 - 21) + 21;
  57.                 SetDlgItemInt(hDlg, IDC_C, random3, true);
  58.             }
  59.             else if (IsDlgButtonChecked(hDlg, IDC_51_100)) {
  60.                 random1 = rand() % (100 + 1 - 51) + 51;
  61.                 SetDlgItemInt(hDlg, IDC_A, random1, true);
  62.                 random2 = rand() % (100 + 1 - 51) + 51;
  63.                 SetDlgItemInt(hDlg, IDC_B, random2, true);
  64.                 random3 = rand() % (100 + 1 - 51) + 51;
  65.                 SetDlgItemInt(hDlg, IDC_C, random3, true);
  66.             }
  67.             break;
  68.         }
  69.         else if (LOWORD(wParam) == IDC_FINISH) {
  70.  
  71.            
  72.             a = (double)Correct / (Correct + Wrong) * 100;
  73.            
  74.             b = (double)Correct / (Correct + Wrong) * 100;
  75.             c = (double)Correct / (Correct + Wrong) * 100;
  76.  
  77.            /*
  78.             if(IsDlgButtonChecked(hDlg, IDC_PLUS) == true){
  79.  
  80.             }
  81.             else if (IsDlgButtonChecked(hDlg, IDC_MINUS) == true) {
  82.  
  83.             }
  84.             else if (IsDlgButtonChecked(hDlg, IDC_UMNOJ) == true) {
  85.  
  86.             }
  87.             else if (IsDlgButtonChecked(hDlg, IDC_DEL) == true) {
  88.  
  89.             }
  90.  
  91.            
  92.             GetDlgItemText(hDlg, IDC_A,(LPWSTR)aTxt, 20);
  93.             SendDlgItemMessage(hDlg, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)aTxt);
  94.  
  95.      
  96.             if (IsDlgButtonChecked(hDlg, IDC_PLUS) == true) {
  97.                 MathSymbol = '+';
  98.             }else if (IsDlgButtonChecked(hDlg, IDC_MINUS) == true) {
  99.                 MathSymbol = '-';
  100.             }else  if (IsDlgButtonChecked(hDlg, IDC_UMNOJ) == true) {
  101.                 MathSymbol = '*';
  102.             }else  if (IsDlgButtonChecked(hDlg, IDC_DEL) == true) {
  103.                 MathSymbol = '/';
  104.             }
  105.  
  106.             char bTxt[20];
  107.             GetDlgItemText(hDlg, IDC_B, (LPWSTR)bTxt, 20);
  108.             SendDlgItemMessage(hDlg, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)bTxt);
  109.  
  110.             if (IsDlgButtonChecked(hDlg, IDC_PLUS) == true) {
  111.                 MathSymbol = '+';
  112.             }
  113.             else if (IsDlgButtonChecked(hDlg, IDC_MINUS) == true) {
  114.                 MathSymbol = '-';
  115.             }
  116.             else  if (IsDlgButtonChecked(hDlg, IDC_UMNOJ) == true) {
  117.                 MathSymbol = '*';
  118.             }
  119.             else  if (IsDlgButtonChecked(hDlg, IDC_DEL) == true) {
  120.                 MathSymbol = '/';
  121.             }
  122.  
  123.             char cTxt[20];
  124.             GetDlgItemText(hDlg, IDC_C, (LPWSTR)cTxt, 20);
  125.             SendDlgItemMessage(hDlg, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)cTxt);
  126.  
  127.          
  128.             if (IsDlgButtonChecked(hDlg, IDC_PLUS) == true) {
  129.                 MathSymbol = '+';
  130.             }
  131.             else if (IsDlgButtonChecked(hDlg, IDC_MINUS) == true) {
  132.                 MathSymbol = '-';
  133.             }
  134.             else  if (IsDlgButtonChecked(hDlg, IDC_UMNOJ) == true) {
  135.                 MathSymbol = '*';
  136.             }
  137.             else  if (IsDlgButtonChecked(hDlg, IDC_DEL) == true) {
  138.                 MathSymbol = '/';
  139.             }*/
  140.         }
  141.         else if (LOWORD(wParam) == IDC_CLEAR) {
  142.         SetDlgItemText(hDlg, IDC_A, 0);
  143.         SetDlgItemText(hDlg, IDC_B, 0);
  144.         SetDlgItemText(hDlg, IDC_C, 0);
  145.         break;
  146.         }
  147.         else if (LOWORD(wParam) == IDC_CHECK) {
  148.         int a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
  149.         int b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
  150.         int c = GetDlgItemInt(hDlg, IDC_C, NULL, true);
  151.         if ((a + b) == c || (a - b) == c || (a * b) == c || (a / b) == c) {
  152.             Correct++;
  153.             SetDlgItemInt(hDlg, IDC_CORRECT, Correct, true);
  154.         }
  155.         else {
  156.             Wrong++;
  157.             SetDlgItemInt(hDlg, IDC_WRONG,Wrong, true);
  158.         }
  159.         if (IsDlgButtonChecked(hDlg, IDC_PLUS) == true) {
  160.             MathSymbol = '+';
  161.         }
  162.         else if (IsDlgButtonChecked(hDlg, IDC_MINUS) == true) {
  163.             MathSymbol = '-';
  164.         }
  165.         else  if (IsDlgButtonChecked(hDlg, IDC_UMNOJ) == true) {
  166.             MathSymbol = '*';
  167.         }
  168.         else  if (IsDlgButtonChecked(hDlg, IDC_DEL) == true) {
  169.             MathSymbol = '/';
  170.         }
  171.        string Txt = to_string(a) + MathSymbol + to_string(b) + '=' + to_string(c);
  172.  
  173.         }
  174.  
  175.         break;
  176.     }
  177.     return (INT_PTR)FALSE;
  178. }
Advertisement
Add Comment
Please, Sign In to add comment