Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // WIN_Project_2.cpp : Defines the entry point for the application.
- //
- #include "stdafx.h"
- #include "WIN_Project_2.h"
- #include <stdio.h>
- #include <string>
- #define MAX_LOADSTRING 100
- using namespace std;
- // Global Variables:
- HINSTANCE hInst; // current instance
- WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
- WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
- // Forward declarations of functions included in this code module:
- ATOM MyRegisterClass(HINSTANCE hInstance);
- BOOL InitInstance(HINSTANCE, int);
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
- INT_PTR CALLBACK Swap(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); //Swap Dialog Box
- INT_PTR CALLBACK Calc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); //Calc Dialog Box
- INT_PTR CALLBACK MathTest(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); //Math Test Dialog Box
- int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
- _In_opt_ HINSTANCE hPrevInstance,
- _In_ LPWSTR lpCmdLine,
- _In_ int nCmdShow)
- {
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
- // TODO: Place code here.
- // Initialize global strings
- LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
- LoadStringW(hInstance, IDC_WINPROJECT2, szWindowClass, MAX_LOADSTRING);
- MyRegisterClass(hInstance);
- // Perform application initialization:
- if (!InitInstance (hInstance, nCmdShow))
- {
- return FALSE;
- }
- HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINPROJECT2));
- MSG msg;
- // Main message loop:
- while (GetMessage(&msg, nullptr, 0, 0))
- {
- if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- return (int) msg.wParam;
- }
- //
- // FUNCTION: MyRegisterClass()
- //
- // PURPOSE: Registers the window class.
- //
- ATOM MyRegisterClass(HINSTANCE hInstance)
- {
- WNDCLASSEXW wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINPROJECT2));
- wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_WINPROJECT2);
- wcex.lpszClassName = szWindowClass;
- wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
- return RegisterClassExW(&wcex);
- }
- //
- // FUNCTION: InitInstance(HINSTANCE, int)
- //
- // PURPOSE: Saves instance handle and creates main window
- //
- // COMMENTS:
- //
- // In this function, we save the instance handle in a global variable and
- // create and display the main program window.
- //
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- hInst = hInstance; // Store instance handle in our global variable
- HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
- if (!hWnd)
- {
- return FALSE;
- }
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- return TRUE;
- }
- //
- // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
- //
- // PURPOSE: Processes messages for the main window.
- //
- // WM_COMMAND - process the application menu
- // WM_PAINT - Paint the main window
- // WM_DESTROY - post a quit message and return
- //
- //
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_COMMAND:
- {
- int wmId = LOWORD(wParam);
- // Parse the menu selections:
- switch (wmId)
- {
- case ID_CHECK:
- {
- HMENU hMenu = GetMenu(hWnd);
- UINT res = GetMenuState(hMenu, ID_CHECK, MF_BYCOMMAND);
- if (res & MF_CHECKED)
- CheckMenuItem(hMenu, ID_CHECK, MF_BYCOMMAND | MF_UNCHECKED);
- else
- CheckMenuItem(hMenu, ID_CHECK, MF_BYCOMMAND | MF_CHECKED);
- } break;
- case ID_ENABLE:
- {
- HMENU hMenu = GetMenu(hWnd);
- UINT res = GetMenuState(hMenu, ID_DISABLE, MF_BYCOMMAND);
- if (res & MF_GRAYED)
- EnableMenuItem(hMenu, ID_DISABLE, MF_BYCOMMAND | MF_ENABLED);
- else
- EnableMenuItem(hMenu, ID_DISABLE, MF_BYCOMMAND | MF_GRAYED);
- }
- break;
- case ID_DOSOMETHING:
- {
- MessageBox(NULL, "Something has been done!", "I did it!", MB_OK | MB_ICONASTERISK);
- } break;
- case ID_ADD:
- {
- HMENU hMenu = GetMenu(hWnd);
- if (GetMenuState(hMenu, ID_ADD + 1, MF_BYCOMMAND) == -1) // == -1 – означава, че не // съществува елемент с такова ID - IDM_ADD + 1
- {
- MENUITEMINFO mii; //съдържа информация за елемент на менюто
- ZeroMemory(&mii, sizeof(mii)); //запълва съответния блок от паметта с нули
- mii.cbSize = sizeof(mii); //размер на структурата в байтове
- mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
- mii.wID = ID_ADD + 1; // ID-то на елемента
- mii.fType = MFT_STRING; // типа на елемента - string
- mii.dwTypeData = LPSTR("Delete me, Alice"); //текст на елем. от менюто
- mii.fState = MFS_ENABLED; //да е достъпно
- InsertMenuItem(hMenu, ID_ADD, FALSE, &mii);
- //добавяне на елемента, инициализиран в структурата &mii, пред елемента с посоченото ID, т.е. пред IDM_ADD
- }
- }
- break;
- case ID_ADD + 1: //при избор елемент с това ID от менюто се изтрива
- {
- int x = MessageBox(NULL, "Are you sure?", "Delete?", MB_YESNO | MB_ICONQUESTION);
- if (x==IDYES) {
- HMENU hMenu = GetMenu(hWnd);
- DeleteMenu(hMenu, ID_ADD + 1, MF_BYCOMMAND);
- } //изтрива елемента с това ID
- }
- break;
- case ID_MATH:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hWnd, MathTest);
- break;
- case IDM_CALC:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG2), hWnd, Calc);
- break; // calc dlg box
- case IDM_SWAP:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, Swap);
- break; // swap dlg box
- case IDM_ABOUT:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
- break;
- case IDM_EXIT:
- DestroyWindow(hWnd);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- }
- break;
- case WM_RBUTTONDOWN: //при натиснат десен бутон на мишката
- {
- HMENU hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU2));
- // зарежда темплейта на менюто от ресурсите, съдържащо бързото меню
- HMENU hSubMenu = GetSubMenu(hMenu, 0); //взема първото бързо меню от темплейта
- POINT pt = { LOWORD(lParam), HIWORD(lParam) }; //текущи координати на мишката
- ClientToScreen(hWnd, &pt); //преобразува коорд. на мишката в коорд. на екрана
- TrackPopupMenu(hSubMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWnd, NULL);
- //показва бързо меню и проследява избора на елементи от менюто
- DestroyMenu(hMenu); //разрушава менюто и освобождава ресурсите
- }
- break;
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(hWnd, &ps);
- // TODO: Add any drawing code that uses hdc here...
- EndPaint(hWnd, &ps);
- }
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- // Message handler for about box.
- INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDC_LUIGI)
- {
- MessageBox(NULL,
- _T("It works?"),
- _T("It does!"),
- NULL);
- }
- if (LOWORD(wParam) == ID_ZDR)
- {
- MessageBox(NULL,
- _T("It works?"),
- _T("It does!"),
- NULL);
- }
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hDlg, LOWORD(wParam));
- return (INT_PTR)TRUE;
- }
- break;
- }
- return (INT_PTR)FALSE;
- }
- int cor = 0, wr = 0;
- INT_PTR CALLBACK MathTest(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- //CheckDlgButton(hDlg, IDC_PLUS, BST_CHECKED);
- CheckDlgButton(hDlg, IDC_R1, BST_CHECKED);
- return (INT_PTR)TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDC_CHECK)
- {
- if (IsDlgButtonChecked(hDlg, IDC_PLUS))
- {
- int a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
- int b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- int c = GetDlgItemInt(hDlg, IDC_C, NULL, true);
- int sum = a + b;
- if (sum == c)
- {
- cor++;
- SetDlgItemInt(hDlg, IDC_CORRECT, cor, true);
- }
- else
- {
- SetDlgItemInt(hDlg, IDC_WRONG, wr, true);
- wr++;
- }
- }
- if (IsDlgButtonChecked(hDlg, IDC_MINUS))
- {
- int a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
- int b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- int c = GetDlgItemInt(hDlg, IDC_C, NULL, true);
- int sum = a - b;
- if (sum == c)
- {
- cor++;
- SetDlgItemInt(hDlg, IDC_CORRECT, cor, true);
- }
- else
- {
- SetDlgItemInt(hDlg, IDC_WRONG, wr, true);
- wr++;
- }
- }
- if (IsDlgButtonChecked(hDlg, IDC_MUL))
- {
- int a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
- int b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- int c = GetDlgItemInt(hDlg, IDC_C, NULL, true);
- int sum = a * b;
- if (sum == c)
- {
- cor++;
- SetDlgItemInt(hDlg, IDC_CORRECT, cor, true);
- }
- else
- {
- SetDlgItemInt(hDlg, IDC_WRONG, wr, true);
- wr++;
- }
- }
- if (IsDlgButtonChecked(hDlg, IDC_DIV))
- {
- int a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
- int b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- if (b == 0)
- {
- MessageBox(hDlg,
- _T("No Value to divide by or dividing bt zer0 "),
- _T("Error!"),
- NULL);
- break;
- }
- else
- {
- int c = GetDlgItemInt(hDlg, IDC_C, NULL, true);
- int sum = a / b;
- if (sum == c)
- {
- cor++;
- SetDlgItemInt(hDlg, IDC_CORRECT, cor, true);
- }
- else
- {
- SetDlgItemInt(hDlg, IDC_WRONG, wr, true);
- wr++;
- }
- }
- }
- }
- if (LOWORD(wParam) == IDC_RANDOM)
- {
- if (IsDlgButtonChecked(hDlg, IDC_R1))
- {
- int a = rand() % (21 + 1 -0) + 0;
- int b = rand() % (21 + 1 - 0) + 0;
- SetDlgItemInt(hDlg, IDC_A, a, true);
- SetDlgItemInt(hDlg, IDC_B, b, true);
- }
- if (IsDlgButtonChecked(hDlg, IDC_R2))
- {
- int a = rand() % (50 + 1 - 20) + 20;
- int b = rand() % (50 + 1 - 21) + 21;
- SetDlgItemInt(hDlg, IDC_A, a, true);
- SetDlgItemInt(hDlg, IDC_B, b, true);
- }
- if (IsDlgButtonChecked(hDlg, IDC_R3))
- {
- int a = rand() % (100 + 1 - 51) + 51;
- int b = rand() % (100 + 1 - 51) + 51;
- SetDlgItemInt(hDlg, IDC_A, a, true);
- SetDlgItemInt(hDlg, IDC_B, b, true);
- }
- }
- if (LOWORD(wParam) == IDC_CLEAR)
- {
- SetDlgItemText(hDlg, IDC_A, NULL);
- SetDlgItemText(hDlg, IDC_B, NULL);
- SetDlgItemText(hDlg, IDC_C, NULL);
- }
- if (LOWORD(wParam) == IDC_FINISH)
- {
- // TO DO
- double res;
- if (cor > wr)
- {
- res = wr / cor;
- }
- else
- {
- res = cor / wr;
- }
- res *=100;
- char s1[3];
- // res = atof(s1);
- string s2 = to_string(res);
- // res.c_tring();
- MessageBox(hDlg,
- _T(s2.c_str(),"%"),
- _T(" Not yet Done"),
- NULL);
- break;
- }
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hDlg, LOWORD(wParam));
- return (INT_PTR)TRUE;
- }
- break;
- }
- return (INT_PTR)FALSE;
- }
- INT_PTR CALLBACK Swap(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) //dialog box for SWAPPING "int" and "text"
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == ID_SWAPINT) {
- int a = GetDlgItemInt(hDlg, IDC_EDIT1, NULL, true);
- int b = GetDlgItemInt(hDlg, IDC_EDIT2, NULL, true);
- SetDlgItemInt(hDlg, IDC_EDIT2, a, true);
- SetDlgItemInt(hDlg, IDC_EDIT1, b, true);
- }
- if (LOWORD(wParam) == ID_SWAPTXT) {
- char t1[20],t2[20];
- GetDlgItemText(hDlg, IDC_EDIT3, t1, 20);
- GetDlgItemText(hDlg, IDC_EDIT4, t2, 20);
- SetDlgItemText(hDlg, IDC_EDIT3, t2);
- SetDlgItemText(hDlg, IDC_EDIT4, t1);
- }
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hDlg, LOWORD(wParam));
- return (INT_PTR)TRUE;
- }
- break;
- }
- return (INT_PTR)FALSE;
- }
- /*INT_PTR CALLBACK Calc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == ID_PLUS)
- {
- int a, b, c;
- a= GetDlgItemInt(hDlg, IDC_A, NULL, true);
- b= GetDlgItemInt(hDlg, IDC_B, NULL, true);
- c = a + b;
- SetDlgItemInt(hDlg, IDC_RESULT, c, true);
- }
- if (LOWORD(wParam) == ID_MINUS)
- {
- int a, b, c;
- a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
- b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- c = a - b;
- SetDlgItemInt(hDlg, IDC_RESULT, c, true);
- }
- if (LOWORD(wParam) == ID_MULT)
- {
- int a, b, c;
- a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
- b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- c = a * b;
- SetDlgItemInt(hDlg, IDC_RESULT, c, true);
- }
- if (LOWORD(wParam) == ID_DIVIDE)
- {
- int a, b, c;
- a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
- b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- if (0 == b)
- {
- MessageBox(hDlg,
- _T("No Value to divide by or dividing bt zer0 "),
- _T("Error!"),
- NULL);
- break;
- }
- else
- {
- c = a / b;
- SetDlgItemInt(hDlg, IDC_RESULT, c, true);
- }
- }
- if (LOWORD(wParam) == ID_MULT)
- {
- int a, b, c;
- a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
- b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- c = a * b;
- SetDlgItemInt(hDlg, IDC_RESULT, c, true);
- }
- if (LOWORD(wParam) == IDC_A2)
- {
- int a, c;
- a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
- //b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- c = a * a;
- SetDlgItemInt(hDlg, IDC_RESULT, c, true);
- }
- if (LOWORD(wParam) == IDC_B2)
- {
- int a, c;
- a = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- //b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- c = a * a;
- SetDlgItemInt(hDlg, IDC_RESULT, c, true);
- }
- if (LOWORD(wParam) == IDC_LEFTOVER)
- {
- int a, b, c;
- a = GetDlgItemInt(hDlg, IDC_A, NULL, true);
- b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- if (0 == b)
- {
- MessageBox(hDlg,
- _T("No Value to divide by or dividing bt zer0 "),
- _T("Error!"),
- NULL);
- break;
- }
- else
- {
- c = a % b;
- SetDlgItemInt(hDlg, IDC_RESULT, c, true);
- }
- }
- if (LOWORD(wParam) == IDC_CLEAR)
- {
- SetDlgItemText(hDlg, IDC_A, NULL);
- SetDlgItemText(hDlg, IDC_B, NULL);
- SetDlgItemText(hDlg, IDC_RESULT, NULL);
- }
- if (LOWORD(wParam) == IDC_RAND)
- {
- int a = rand() % 100;
- int b = rand() % 100;
- SetDlgItemInt(hDlg, IDC_A, a,true);
- SetDlgItemInt(hDlg, IDC_B, b, true);
- }
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hDlg, LOWORD(wParam));
- return (INT_PTR)TRUE;
- }
- break;
- }
- return (INT_PTR)FALSE;
- } */
- INT_PTR CALLBACK Calc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == ID_PLUS)
- {
- char s1[20], s2[20];
- GetDlgItemText(hDlg, IDC_A, s1, 20);
- GetDlgItemText(hDlg, IDC_B, s2, 20);
- double a = atof(s1);
- double b = atof(s2);
- double c = a + b;
- string s3 = to_string(c);
- size_t t = s3.find_last_not_of('0');
- int l = s3.length() - t;
- s3.erase(t + 1, l);
- SetDlgItemText(hDlg, IDC_RESULT, s3.c_str());
- }
- if (LOWORD(wParam) == ID_MINUS)
- {
- char s1[20], s2[20];
- GetDlgItemText(hDlg, IDC_A, s1, 20);
- GetDlgItemText(hDlg, IDC_B, s2, 20);
- double a = atof(s1);
- double b = atof(s2);
- double c = a - b;
- string s3 = to_string(c);
- size_t t = s3.find_last_not_of('0');
- int l = s3.length() - t;
- s3.erase(t + 1, l);
- SetDlgItemText(hDlg, IDC_RESULT, s3.c_str());
- }
- if (LOWORD(wParam) == ID_MULT)
- {
- char s1[20], s2[20];
- GetDlgItemText(hDlg, IDC_A, s1, 20);
- GetDlgItemText(hDlg, IDC_B, s2, 20);
- double a = atof(s1);
- double b = atof(s2);
- double c = a * b;
- string s3 = to_string(c);
- size_t t = s3.find_last_not_of('0');
- int l = s3.length() - t;
- s3.erase(t + 1, l);
- SetDlgItemText(hDlg, IDC_RESULT, s3.c_str());
- }
- if (LOWORD(wParam) == ID_DIVIDE)
- {
- char s1[20], s2[20];
- GetDlgItemText(hDlg, IDC_A, s1, 20);
- GetDlgItemText(hDlg, IDC_B, s2, 20);
- double a = atof(s1);
- double b = atof(s2);
- if (0 == b)
- {
- MessageBox(hDlg,
- _T("No Value to divide by or dividing bt zer0 "),
- _T("Error!"),
- NULL);
- break;
- }
- else
- {
- double c = a / b;
- string s3 = to_string(c);
- size_t t = s3.find_last_not_of('0');
- int l = s3.length() - t;
- s3.erase(t + 1, l);
- SetDlgItemText(hDlg, IDC_RESULT, s3.c_str());
- }
- }
- if (LOWORD(wParam) == IDC_A2)
- {
- char s1[20];
- GetDlgItemText(hDlg, IDC_A, s1, 20);
- double a = atof(s1);
- //b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- double c = a * a;
- string s3 = to_string(c);
- size_t t = s3.find_last_not_of('0');
- int l = s3.length() - t;
- s3.erase(t + 1, l);
- SetDlgItemText(hDlg, IDC_RESULT, s3.c_str());
- }
- if (LOWORD(wParam) == IDC_B2)
- {
- char s1[20];
- GetDlgItemText(hDlg, IDC_B, s1, 20);
- double a = atof(s1);
- //b = GetDlgItemInt(hDlg, IDC_B, NULL, true);
- double c = a * a;
- string s3 = to_string(c);
- size_t t = s3.find_last_not_of('0');
- int l = s3.length() - t;
- s3.erase(t + 1, l);
- SetDlgItemText(hDlg, IDC_RESULT, s3.c_str());
- }
- if (LOWORD(wParam) == IDC_LEFTOVER)
- {
- char s1[20], s2[20];
- GetDlgItemText(hDlg, IDC_A, s1, 20);
- GetDlgItemText(hDlg, IDC_B, s2, 20);
- double a = atof(s1);
- double b = atof(s2);
- if (0 == b)
- {
- MessageBox(hDlg,
- _T("No Value to divide by or dividing bt zer0 "),
- _T("Error!"),
- NULL);
- break;
- }
- else
- {
- double c = a / b;
- string s3 = to_string(c);
- size_t t = s3.find_last_not_of('0');
- int l = s3.length() - t;
- s3.erase(t + 1, l);
- SetDlgItemText(hDlg, IDC_RESULT, s3.c_str());
- }
- }
- if (LOWORD(wParam) == IDC_CLEAR)
- {
- SetDlgItemText(hDlg, IDC_A, NULL);
- SetDlgItemText(hDlg, IDC_B, NULL);
- SetDlgItemText(hDlg, IDC_RESULT, NULL);
- }
- if (LOWORD(wParam) == IDC_RAND)
- {
- double a = (double)rand() / 100;
- double b = (double)rand() / 100 ;
- string s1 = to_string(a);
- string s2 = to_string(b);
- SetDlgItemText(hDlg, IDC_A, s1.c_str());
- SetDlgItemText(hDlg, IDC_B, s2.c_str());
- }
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hDlg, LOWORD(wParam));
- return (INT_PTR)TRUE;
- }
- break;
- }
- return (INT_PTR)FALSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement