Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- HINSTANCE hInst;
- LPCTSTR szWindowClass = "QWERTY";
- LPCTSTR szChildClass = "QWERTY2";
- LPCTSTR szTitle = "ЛАБА8", childTitle = "ОШИБКА";
- WNDCLASSEX wcex, wcex1;
- ATOM MyRegisterClass(HINSTANCE hInstance);
- BOOL InitInstance(HINSTANCE, int);
- void RegisterChild(HINSTANCE hInstance);
- BOOL InitChild(HINSTANCE hInstance);
- LRESULT CALLBACK ChildProc(HWND childWnd, UINT message, WPARAM wParam, LPARAM lParam);
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- char var_dbl[8][32];
- int var[8];
- HWND childWnd, hWnd, button1, button2, text1, text2, text3, text4, text5;
- char str1[100], str2[100], str3[100], str4[100], str5[100];
- char *p1 = str1, *p2 = str2, *p3 = str3, *p4 = str4, *p5 = str5;
- bool check1 = true, check2 = true, check3 = true, check4 = true, check5 = true;
- int a, b, n1, n2, fib;
- int sum = 0, fact = 1, n_fib = 0;
- void IsDigit(char *p, char str[100], bool check)
- {
- while (*p)
- {
- if (!isdigit(*p++))
- {
- check = false;
- break;
- }
- }
- p = str;
- }
- void bin_to_char(int x, char *str)
- {
- int sq[32];
- _asm
- {
- mov eax, x
- mov ebx, 2
- mov ecx, 32
- mov edx, 0
- mov esi, 124
- cycle:
- div ebx
- mov sq[esi], edx
- mov edx, 0
- cmp eax, 0
- jz zero
- sub esi, 4
- loop cycle
- zero :
- sub ecx, 1
- cycle1 :
- sub esi, 4
- mov sq[esi], 0
- loop cycle1
- }
- for (int i = 0; i < 32; i++)
- {
- _itoa(sq[i], (str + i)/*&var_dbl[j][i]*/, 10);
- }
- }
- void ConvertAllReg()
- {
- for (int i = 0; i < 8; i++)
- {
- bin_to_char(var[i], &var_dbl[i][0]);
- }
- }
- void OutPutReg(HDC hdc, int x, int &y)
- {
- ConvertAllReg();
- int yy = y;
- TextOut(hdc, x, y, "eax = ", 7); y += 20;
- TextOut(hdc, x, y, "edx = ", 7); y += 20;
- TextOut(hdc, x, y, "ecx = ", 7); y += 20;
- TextOut(hdc, x, y, "ebx = ", 7); y += 20;
- TextOut(hdc, x, y, "ebp = ", 7); y += 20;
- TextOut(hdc, x, y, "esi = ", 7); y += 20;
- TextOut(hdc, x, y, "edi = ", 7); y += 20;
- TextOut(hdc, x, y, "esp = ", 7);
- x += 40;
- y = yy;
- for (int i = 0; i < 8; i++)
- {
- TextOut(hdc, x, y, var_dbl[i], 32);
- y += 20;
- }
- }
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- MSG msg;
- MyRegisterClass(hInstance);
- if (!InitInstance(hInstance, nCmdShow))
- {
- return FALSE;
- }
- RegisterChild(hInstance);
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- ATOM MyRegisterClass(HINSTANCE hInstance)
- {
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = (WNDPROC)WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(NULL, IDI_INFORMATION);
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
- wcex.lpszMenuName = NULL;
- wcex.lpszClassName = szWindowClass;
- wcex.hIconSm = NULL;
- return RegisterClassEx(&wcex);
- }
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- hInst = hInstance;
- hWnd = CreateWindow(szWindowClass,
- szTitle,
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 1300,
- 600,
- NULL,
- NULL,
- hInstance,
- NULL);
- button1 = CreateWindow("button", "Execute", WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 10, 170, 100, 50, hWnd, (HMENU)0001, NULL, NULL);
- text1 = CreateWindow("edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 45, 10, 100, 20, hWnd, (HMENU)0010, NULL, NULL);
- text2 = CreateWindow("edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 45, 35, 100, 20, hWnd, (HMENU)0100, NULL, NULL);
- text3 = CreateWindow("edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 45, 60, 100, 20, hWnd, (HMENU)0011, NULL, NULL);
- text4 = CreateWindow("edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 45, 85, 100, 20, hWnd, (HMENU)0111, NULL, NULL);
- text5 = CreateWindow("edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 10, 130, 100, 20, hWnd, (HMENU)1111, NULL, NULL);
- if (!hWnd)
- {
- return FALSE;
- }
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- return TRUE;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- PAINTSTRUCT ps;
- static DWORD dwCharX;
- static DWORD dwCharY;
- TEXTMETRIC tm;
- HDC hdc = GetDC(hWnd);
- switch (message)
- {
- case WM_COMMAND:
- {
- switch (LOWORD(wParam))
- {
- case 0001:
- switch (HIWORD(wParam))
- {
- case BN_CLICKED:
- int stat1 = GetWindowText(text1, str1, 100); IsDigit(p1, str1, check1);
- int stat2 = GetWindowText(text2, str2, 100); IsDigit(p2, str2, check2);
- int stat3 = GetWindowText(text3, str3, 100); IsDigit(p3, str3, check3);
- int stat4 = GetWindowText(text4, str4, 100); IsDigit(p4, str4, check4);
- int stat5 = GetWindowText(text5, str5, 100); IsDigit(p5, str5, check5);
- if (check1 && check2 && check3 && check4 && check5)
- {
- a = atoi(str1); b = atoi(str2);
- n1 = atoi(str3); n2 = atoi(str4); fib = atoi(str5);
- }
- else
- {
- if (!InitChild(hInst))
- {
- return FALSE;
- }
- ShowWindow(childWnd, SW_SHOW);
- }
- check1 = true;
- check2 = true;
- check3 = true;
- check4 = true;
- check5 = true;
- __asm
- {
- mov var[0], eax
- mov var[4], edx
- mov var[8], ecx
- mov var[12], ebx
- mov var[16], ebp
- mov var[20], esi
- mov var[24], edi
- mov var[28], esp
- }
- InvalidateRect(hWnd, NULL, NULL);
- int x = 155, y = 10;
- TextOut(hdc, x, y, "До операций : ", 15); y = 35;
- OutPutReg(hdc, x, y);
- y += 15;
- __asm
- {
- mov eax, a
- mov edx, b
- and eax, edx
- mov var[0], eax
- mov var[4], edx
- mov var[8], ecx
- mov var[12], ebx
- mov var[16], ebp
- mov var[20], esi
- mov var[24], edi
- mov var[28], esp
- }
- TextOut(hdc, x, y, "После коньюнкции : ", 20); y += 20;
- OutPutReg(hdc, x, y);
- __asm
- {
- mov eax, a
- mov edx, b
- or eax, edx
- mov var[0], eax
- mov var[4], edx
- mov var[8], ecx
- mov var[12], ebx
- mov var[16], ebp
- mov var[20], esi
- mov var[24], edi
- mov var[28], esp
- }
- x = 500; y = 10;
- TextOut(hdc, x, y, "После дизьюнкции : ", 20); y = 35;
- OutPutReg(hdc, x, y);
- y += 15;
- __asm
- {
- mov eax, a
- mov edx, b
- xor eax, edx
- mov var[0], eax
- mov var[4], edx
- mov var[8], ecx
- mov var[12], ebx
- mov var[16], ebp
- mov var[20], esi
- mov var[24], edi
- mov var[28], esp
- }
- TextOut(hdc, x, y, "После сложения по модулю 2 : ", 30); y += 20;
- OutPutReg(hdc, x, y);
- x = 820; y = 10;
- TextOut(hdc, x, y, "Сумма от 1 до N1 : ", 20); y += 20;
- _asm
- {
- mov ebx, 0
- mov ecx, n1
- summa :
- add ebx, ecx
- loop summa
- mov sum, ebx
- }
- _itoa(sum, p3, 10);
- TextOut(hdc, x, y, str3, 10);
- y += 30;
- TextOut(hdc, x, y, "Факториал числа N2 : ", 22);
- _asm
- {
- mov ecx, n2
- mov eax, fact
- factorial :
- mul ecx
- loop factorial
- mov fact, eax
- }
- y += 20;
- _itoa(fact, p4, 10);
- TextOut(hdc, x, y, str4, 10);
- y += 30;
- TextOut(hdc, x, y, "N-ое число Фибоначчи : ", 24);
- _asm
- {
- mov eax, 1
- mov ebx, 0
- mov ecx, fib
- sub ecx, 2
- fibonachi :
- mov edx, eax
- add eax, ebx
- mov ebx, edx
- loop fibonachi
- mov n_fib, eax
- }
- y += 20;
- _itoa(n_fib, p5, 10);
- TextOut(hdc, x, y, str5, 10);
- break;
- }
- break;
- }
- }
- case WM_CREATE:
- {
- hdc = GetDC(hWnd);
- GetTextMetrics(hdc, &tm);
- dwCharX = tm.tmAveCharWidth;
- dwCharY = tm.tmHeight;
- break;
- }
- case WM_PAINT:
- {
- hdc = BeginPaint(hWnd, &ps);
- TextOut(hdc, 10, 10, "A = ", 5);
- TextOut(hdc, 10, 35, "B = ", 5);
- TextOut(hdc, 10, 60, "N1 = ", 6);
- TextOut(hdc, 10, 85, "N2 = ", 6);
- TextOut(hdc, 10, 110, "N fibonachi = ", 15);
- EndPaint(hWnd, &ps);
- break;
- }
- case WM_DESTROY:
- {
- PostQuitMessage(0);
- break;
- }
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- void RegisterChild(HINSTANCE hInstance)
- {
- wcex1.cbSize = sizeof(WNDCLASSEX);
- wcex1.style = CS_HREDRAW | CS_VREDRAW;
- wcex1.lpfnWndProc = (WNDPROC)ChildProc;
- wcex1.cbClsExtra = 0;
- wcex1.cbWndExtra = 0;
- wcex1.hInstance = hInstance;
- wcex1.hIcon = LoadIcon(NULL, IDI_HAND);
- wcex1.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex1.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
- wcex1.lpszMenuName = NULL;
- wcex1.lpszClassName = szChildClass;
- wcex1.hIconSm = NULL;
- RegisterClassEx(&wcex1);
- }
- BOOL InitChild(HINSTANCE hInstance)
- {
- childWnd = CreateWindow(szChildClass,
- childTitle,
- WS_OVERLAPPEDWINDOW,
- 200,
- 200,
- 250,
- 250,
- hWnd,
- NULL,
- hInstance,
- NULL);
- button2 = CreateWindow("button", "OK", WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 150, 50, 50, childWnd, (HMENU)1000, NULL, NULL);
- if (!childWnd)
- {
- return FALSE;
- }
- return TRUE;
- }
- LRESULT CALLBACK ChildProc(HWND childWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- PAINTSTRUCT ps;
- HDC hdc;
- switch (message)
- {
- case WM_CREATE:
- break;
- case WM_COMMAND:
- {
- switch (LOWORD(wParam))
- {
- case 1000:
- switch (HIWORD(wParam))
- {
- case BN_CLICKED:
- DestroyWindow(childWnd);
- break;
- }
- break;
- }
- }
- case WM_PAINT:
- {
- hdc = BeginPaint(childWnd, &ps);
- TextOut(hdc, 60, 100, "SYNTAX ERROR", 30);
- EndPaint(childWnd, &ps);
- break;
- }
- default:
- return DefWindowProc(childWnd, message, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement