Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include "resource.h"
- #include <math.h>
- #include <Windowsx.h>
- #include <string>
- #include <iostream>
- #include <fstream>
- using namespace std;
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int
- nCmdShow)
- {
- HWND hMainWnd;
- MSG msg;
- //Создаём основное окно приложения
- hMainWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), 0, (DLGPROC)WndProc);
- if (!hMainWnd) {
- MessageBox(NULL, "Cannot create main window", "Error", MB_OK);
- return 0;
- }
- //Показываем наше окно
- ShowWindow(hMainWnd, nCmdShow);
- UpdateWindow(hMainWnd); //См. примечание в разделе "Отображение окна..."
- //Выполняем цикл обработки сообщений до закрытия приложения
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- HWND ComboBox = GetDlgItem(hWnd, IDC_COMBO1);
- switch (uMsg)
- {
- case WM_INITDIALOG: {
- ComboBox_AddString(ComboBox, "Sphere");
- ComboBox_AddString(ComboBox, "Cube");
- ComboBox_AddString(ComboBox, "Circle");
- ComboBox_AddString(ComboBox, "Square");
- Button_Enable(GetDlgItem(hWnd, ID_SAVE), 0);
- break;
- }
- case WM_CLOSE:
- DestroyWindow(hWnd);
- break;
- case WM_COMMAND: {
- if (LOWORD(wParam) == ID_SAVE) {
- char val[500];
- string figure;
- Edit_GetText(GetDlgItem(hWnd, IDC_EDIT2), val, sizeof(val));
- double value = atof(val), calc = 0;
- int boxValue = ComboBox_GetCurSel(ComboBox);
- if (boxValue == 0) {
- figure = "Sphere: ";
- calc = 4 * 3.14*pow(value, 2);
- }
- else if (boxValue == 1) {
- figure = "Cube: ";
- calc = pow(value, 3);
- }
- else if (boxValue == 2) {
- figure = "Circle: ";
- calc = 3.14 * pow(value, 2);
- }
- else if (boxValue == 3) {
- figure = "Square: ";
- calc = pow(value, 2);
- }
- figure = figure + to_string(calc);
- ofstream file("datalist.txt", ios_base::app);
- file << figure.c_str() << endl;
- file.close();
- } else {
- Button_Enable(GetDlgItem(hWnd, ID_SAVE), 0);
- //Check val's
- if (ComboBox_GetCurSel(ComboBox) < 0) break;
- if (Edit_GetTextLength(GetDlgItem(hWnd, IDC_EDIT2)) < 1) break;
- Button_Enable(GetDlgItem(hWnd, ID_SAVE), 1);
- }
- break;
- }
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment