Advertisement
Guest User

Untitled

a guest
May 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.78 KB | None | 0 0
  1. #include <windows.h>
  2. HINSTANCE hInst;    
  3. LPCTSTR szWindowClass = "QWERTY";
  4. LPCTSTR szChildClass = "QWERTY2";
  5. LPCTSTR szTitle = "ЛАБА8", childTitle = "ОШИБКА";
  6. WNDCLASSEX wcex, wcex1;
  7. ATOM MyRegisterClass(HINSTANCE hInstance);
  8. BOOL InitInstance(HINSTANCE, int);
  9. void RegisterChild(HINSTANCE hInstance);
  10. BOOL InitChild(HINSTANCE hInstance);
  11. LRESULT CALLBACK ChildProc(HWND childWnd, UINT message, WPARAM wParam, LPARAM lParam);
  12. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  13.  
  14. char var_dbl[8][32];
  15. int var[8];
  16.  
  17. HWND childWnd, hWnd, button1, button2, text1, text2, text3, text4, text5;
  18. char str1[100], str2[100], str3[100], str4[100], str5[100];
  19. char *p1 = str1, *p2 = str2, *p3 = str3, *p4 = str4, *p5 = str5;
  20. bool check1 = true, check2 = true, check3 = true, check4 = true, check5 = true;
  21. int a, b, n1, n2, fib;
  22. int sum = 0, fact  = 1, n_fib = 0;
  23.  
  24. void IsDigit(char *p, char str[100], bool check)
  25. {
  26.     while (*p)
  27.     {
  28.         if (!isdigit(*p++))
  29.         {
  30.             check = false;
  31.             break;
  32.         }
  33.     }
  34.     p = str;
  35. }
  36.  
  37. void bin_to_char(int x, char *str)
  38. {
  39.     int sq[32];
  40.     _asm
  41.     {
  42.         mov eax, x
  43.         mov ebx, 2
  44.         mov ecx, 32
  45.         mov edx, 0
  46.         mov esi, 124
  47.         cycle:
  48.         div ebx
  49.             mov sq[esi], edx
  50.             mov edx, 0
  51.             cmp eax, 0
  52.             jz zero
  53.             sub esi, 4
  54.             loop cycle
  55.             zero :
  56.         sub ecx, 1
  57.             cycle1 :
  58.             sub esi, 4
  59.             mov sq[esi], 0
  60.             loop cycle1
  61.     }
  62.     for (int i = 0; i < 32; i++)
  63.     {
  64.         _itoa(sq[i], (str + i)/*&var_dbl[j][i]*/, 10);
  65.     }
  66. }
  67.  
  68. void ConvertAllReg()
  69. {
  70.     for (int i = 0; i < 8; i++)
  71.     {
  72.         bin_to_char(var[i], &var_dbl[i][0]);
  73.     }
  74. }
  75.  
  76. void OutPutReg(HDC hdc, int x, int &y)
  77. {
  78.     ConvertAllReg();
  79.     int yy = y;
  80.     TextOut(hdc, x, y, "eax = ", 7); y += 20;
  81.     TextOut(hdc, x, y, "edx = ", 7); y += 20;
  82.     TextOut(hdc, x, y, "ecx = ", 7); y += 20;
  83.     TextOut(hdc, x, y, "ebx = ", 7); y += 20;
  84.     TextOut(hdc, x, y, "ebp = ", 7); y += 20;
  85.     TextOut(hdc, x, y, "esi = ", 7); y += 20;
  86.     TextOut(hdc, x, y, "edi = ", 7); y += 20;
  87.     TextOut(hdc, x, y, "esp = ", 7);
  88.     x += 40;
  89.     y = yy;
  90.     for (int i = 0; i < 8; i++)
  91.     {
  92.         TextOut(hdc, x, y, var_dbl[i], 32);
  93.         y += 20;
  94.     }
  95. }
  96.  
  97. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  98. {
  99.     MSG msg;
  100.    
  101.     MyRegisterClass(hInstance);
  102.  
  103.     if (!InitInstance(hInstance, nCmdShow))
  104.     {
  105.         return FALSE;
  106.     }
  107.     RegisterChild(hInstance);
  108.  
  109.     while (GetMessage(&msg, NULL, 0, 0))
  110.     {
  111.         TranslateMessage(&msg);
  112.         DispatchMessage(&msg);
  113.     }
  114.     return msg.wParam;
  115. }
  116.  
  117. ATOM MyRegisterClass(HINSTANCE hInstance)
  118. {
  119.     wcex.cbSize = sizeof(WNDCLASSEX);
  120.     wcex.style = CS_HREDRAW | CS_VREDRAW;
  121.     wcex.lpfnWndProc = (WNDPROC)WndProc;
  122.     wcex.cbClsExtra = 0;
  123.     wcex.cbWndExtra = 0;
  124.     wcex.hInstance = hInstance;
  125.     wcex.hIcon = LoadIcon(NULL, IDI_INFORMATION);
  126.     wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  127.     wcex.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
  128.     wcex.lpszMenuName = NULL;
  129.     wcex.lpszClassName = szWindowClass;
  130.     wcex.hIconSm = NULL;
  131.     return RegisterClassEx(&wcex);
  132. }
  133.  
  134. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  135. {
  136.     hInst = hInstance;
  137.     hWnd = CreateWindow(szWindowClass,
  138.         szTitle,
  139.         WS_OVERLAPPEDWINDOW,
  140.         CW_USEDEFAULT,
  141.         CW_USEDEFAULT,
  142.         1300,
  143.         600,
  144.         NULL,
  145.         NULL,
  146.         hInstance,
  147.         NULL);
  148.     button1 = CreateWindow("button", "Execute", WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 10, 170, 100, 50, hWnd, (HMENU)0001, NULL, NULL);
  149.     text1 = CreateWindow("edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 45, 10, 100, 20, hWnd, (HMENU)0010, NULL, NULL);
  150.     text2 = CreateWindow("edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 45, 35, 100, 20, hWnd, (HMENU)0100, NULL, NULL);
  151.     text3 = CreateWindow("edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 45, 60, 100, 20, hWnd, (HMENU)0011, NULL, NULL);
  152.     text4 = CreateWindow("edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 45, 85, 100, 20, hWnd, (HMENU)0111, NULL, NULL);
  153.     text5 = CreateWindow("edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 10, 130, 100, 20, hWnd, (HMENU)1111, NULL, NULL);
  154.     if (!hWnd)
  155.     {
  156.         return FALSE;
  157.     }
  158.     ShowWindow(hWnd, nCmdShow);
  159.     UpdateWindow(hWnd);
  160.     return TRUE;
  161. }
  162.  
  163. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  164. {
  165.     PAINTSTRUCT ps;
  166.     static DWORD dwCharX;
  167.     static DWORD dwCharY;
  168.     TEXTMETRIC tm;
  169.     HDC hdc = GetDC(hWnd);
  170.     switch (message)
  171.     {
  172.     case WM_COMMAND:
  173.         {
  174.             switch (LOWORD(wParam))
  175.             {
  176.             case 0001:
  177.                 switch (HIWORD(wParam))
  178.                 {
  179.                 case BN_CLICKED:
  180.                     int stat1 = GetWindowText(text1, str1, 100); IsDigit(p1, str1, check1);
  181.                     int stat2 = GetWindowText(text2, str2, 100); IsDigit(p2, str2, check2);
  182.                     int stat3 = GetWindowText(text3, str3, 100); IsDigit(p3, str3, check3);
  183.                     int stat4 = GetWindowText(text4, str4, 100); IsDigit(p4, str4, check4);
  184.                     int stat5 = GetWindowText(text5, str5, 100); IsDigit(p5, str5, check5);
  185.            
  186.                     if (check1 && check2 && check3 && check4 && check5)
  187.                     {
  188.                         a = atoi(str1); b = atoi(str2);
  189.                         n1 = atoi(str3); n2 = atoi(str4); fib = atoi(str5);
  190.                     }
  191.                     else
  192.                     {
  193.                         if (!InitChild(hInst))
  194.                         {
  195.                             return FALSE;
  196.                         }
  197.                         ShowWindow(childWnd, SW_SHOW);
  198.                     }
  199.                     check1 = true;
  200.                     check2 = true;
  201.                     check3 = true;
  202.                     check4 = true;
  203.                     check5 = true;
  204.                     __asm
  205.                     {
  206.                         mov var[0], eax
  207.                         mov var[4], edx
  208.                         mov var[8], ecx
  209.                         mov var[12], ebx
  210.                         mov var[16], ebp
  211.                         mov var[20], esi
  212.                         mov var[24], edi
  213.                         mov var[28], esp
  214.                     }
  215.                     InvalidateRect(hWnd, NULL, NULL);
  216.                     int x = 155, y = 10;
  217.                     TextOut(hdc, x, y, "До операций : ", 15); y = 35;
  218.                     OutPutReg(hdc, x, y);
  219.                     y += 15;
  220.                     __asm
  221.                     {
  222.                     mov eax, a
  223.                     mov edx, b
  224.                     and eax, edx
  225.                     mov var[0], eax
  226.                     mov var[4], edx
  227.                     mov var[8], ecx
  228.                     mov var[12], ebx
  229.                     mov var[16], ebp
  230.                     mov var[20], esi
  231.                     mov var[24], edi
  232.                     mov var[28], esp
  233.                     }
  234.                     TextOut(hdc, x, y, "После коньюнкции : ", 20); y += 20;
  235.                     OutPutReg(hdc, x, y);
  236.  
  237.                     __asm
  238.                     {
  239.                     mov eax, a
  240.                     mov edx, b
  241.                     or eax, edx
  242.                     mov var[0], eax
  243.                     mov var[4], edx
  244.                     mov var[8], ecx
  245.                     mov var[12], ebx
  246.                     mov var[16], ebp
  247.                     mov var[20], esi
  248.                     mov var[24], edi
  249.                     mov var[28], esp
  250.                     }
  251.                     x = 500; y = 10;
  252.                     TextOut(hdc, x, y, "После дизьюнкции : ", 20); y = 35;
  253.                     OutPutReg(hdc, x, y);
  254.                     y += 15;
  255.  
  256.                     __asm
  257.                     {
  258.                     mov eax, a
  259.                     mov edx, b
  260.                     xor eax, edx
  261.                     mov var[0], eax
  262.                     mov var[4], edx
  263.                     mov var[8], ecx
  264.                     mov var[12], ebx
  265.                     mov var[16], ebp
  266.                     mov var[20], esi
  267.                     mov var[24], edi
  268.                     mov var[28], esp
  269.                     }
  270.                     TextOut(hdc, x, y, "После сложения по модулю 2 : ", 30); y += 20;
  271.                     OutPutReg(hdc, x, y);
  272.                     x = 820; y = 10;
  273.                     TextOut(hdc, x, y, "Сумма от 1 до N1 : ", 20); y += 20;
  274.                     _asm
  275.                     {
  276.                         mov ebx, 0
  277.                         mov ecx, n1
  278.                         summa :
  279.                             add ebx, ecx
  280.                         loop summa
  281.                         mov sum, ebx
  282.                     }
  283.                     _itoa(sum, p3, 10);
  284.                     TextOut(hdc, x, y, str3, 10);
  285.                     y += 30;
  286.                     TextOut(hdc, x, y, "Факториал числа N2 : ", 22);
  287.                     _asm
  288.                     {
  289.                         mov ecx, n2
  290.                         mov eax, fact
  291.                         factorial :
  292.                         mul ecx
  293.                             loop factorial
  294.                             mov fact, eax
  295.                     }
  296.                     y += 20;
  297.                     _itoa(fact, p4, 10);
  298.                     TextOut(hdc, x, y, str4, 10);
  299.                     y += 30;
  300.                     TextOut(hdc, x, y, "N-ое число Фибоначчи : ", 24);
  301.                     _asm
  302.                     {
  303.                         mov eax, 1
  304.                         mov ebx, 0
  305.                         mov ecx, fib
  306.                         sub ecx, 2
  307.                         fibonachi :
  308.                             mov edx, eax
  309.                             add eax, ebx
  310.                             mov ebx, edx
  311.                         loop fibonachi
  312.                         mov n_fib, eax
  313.                     }
  314.                     y += 20;
  315.                     _itoa(n_fib, p5, 10);
  316.                     TextOut(hdc, x, y, str5, 10);
  317.                     break;
  318.                 }
  319.                 break;
  320.             }
  321.         }
  322.     case WM_CREATE:
  323.         {
  324.             hdc = GetDC(hWnd);
  325.             GetTextMetrics(hdc, &tm);
  326.             dwCharX = tm.tmAveCharWidth;
  327.             dwCharY = tm.tmHeight;
  328.             break;
  329.         }
  330.     case WM_PAINT:
  331.         {
  332.             hdc = BeginPaint(hWnd, &ps);
  333.             TextOut(hdc, 10, 10, "A = ", 5);
  334.             TextOut(hdc, 10, 35, "B = ", 5);
  335.             TextOut(hdc, 10, 60, "N1 = ", 6);
  336.             TextOut(hdc, 10, 85, "N2 = ", 6);
  337.             TextOut(hdc, 10, 110, "N fibonachi = ", 15);
  338.             EndPaint(hWnd, &ps);
  339.             break;
  340.         }
  341.     case WM_DESTROY:
  342.         {
  343.             PostQuitMessage(0);
  344.             break;
  345.         }
  346.     default:
  347.         return DefWindowProc(hWnd, message, wParam, lParam);
  348.     }
  349.     return 0;
  350. }
  351.  
  352. void RegisterChild(HINSTANCE hInstance)
  353. {
  354.     wcex1.cbSize = sizeof(WNDCLASSEX);
  355.     wcex1.style = CS_HREDRAW | CS_VREDRAW;
  356.     wcex1.lpfnWndProc = (WNDPROC)ChildProc;    
  357.     wcex1.cbClsExtra = 0;
  358.     wcex1.cbWndExtra = 0;
  359.     wcex1.hInstance = hInstance;    
  360.     wcex1.hIcon = LoadIcon(NULL, IDI_HAND);
  361.     wcex1.hCursor = LoadCursor(NULL, IDC_ARROW);
  362.     wcex1.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
  363.     wcex1.lpszMenuName = NULL;     
  364.     wcex1.lpszClassName = szChildClass;        
  365.     wcex1.hIconSm = NULL;
  366.     RegisterClassEx(&wcex1);
  367. }
  368.  
  369. BOOL InitChild(HINSTANCE hInstance)
  370. {
  371.     childWnd = CreateWindow(szChildClass,
  372.         childTitle,            
  373.         WS_OVERLAPPEDWINDOW,   
  374.         200,           
  375.         200,       
  376.         250,       
  377.         250,       
  378.         hWnd,              
  379.         NULL,              
  380.         hInstance,         
  381.         NULL);     
  382.     button2 = CreateWindow("button", "OK", WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 150, 50, 50, childWnd, (HMENU)1000, NULL, NULL);
  383.     if (!childWnd)
  384.     {
  385.         return FALSE;
  386.     }
  387.  
  388.     return TRUE;
  389. }
  390.  
  391. LRESULT CALLBACK ChildProc(HWND childWnd, UINT message, WPARAM wParam, LPARAM lParam)
  392. {
  393.     PAINTSTRUCT ps;
  394.     HDC hdc;
  395.     switch (message)
  396.     {
  397.     case WM_CREATE:
  398.         break;
  399.     case WM_COMMAND:
  400.         {
  401.             switch (LOWORD(wParam))
  402.             {
  403.             case 1000:
  404.                 switch (HIWORD(wParam))
  405.                 {
  406.                 case BN_CLICKED:
  407.                     DestroyWindow(childWnd);
  408.                     break;
  409.                 }
  410.                 break;
  411.             }
  412.         }
  413.     case WM_PAINT:
  414.         {
  415.             hdc = BeginPaint(childWnd, &ps);
  416.             TextOut(hdc, 60, 100, "SYNTAX ERROR", 30);
  417.             EndPaint(childWnd, &ps);
  418.             break;
  419.         }
  420.     default:
  421.         return DefWindowProc(childWnd, message, wParam, lParam);
  422.     }
  423.     return 0;
  424. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement