alexx876

Untitled

Jan 14th, 2019
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. #include <Windows.h>
  2. #include "resource.h"
  3. #include <math.h>
  4. #include <Windowsx.h>
  5. #include <string>
  6. #include <iostream>
  7. #include <fstream>
  8.  
  9. using namespace std;
  10.  
  11. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  12.  
  13. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int
  14. nCmdShow)
  15. {
  16. HWND hMainWnd;
  17. MSG msg;
  18.  
  19. //Создаём основное окно приложения
  20. hMainWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), 0, (DLGPROC)WndProc);
  21.  
  22. if (!hMainWnd) {
  23. MessageBox(NULL, "Cannot create main window", "Error", MB_OK);
  24. return 0;
  25. }
  26.  
  27. //Показываем наше окно
  28. ShowWindow(hMainWnd, nCmdShow);
  29. UpdateWindow(hMainWnd); //См. примечание в разделе "Отображение окна..."
  30.  
  31. //Выполняем цикл обработки сообщений до закрытия приложения
  32. while (GetMessage(&msg, NULL, 0, 0)) {
  33. TranslateMessage(&msg);
  34. DispatchMessage(&msg);
  35. }
  36.  
  37. return msg.wParam;
  38. }
  39.  
  40. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  41. {
  42. HWND ComboBox = GetDlgItem(hWnd, IDC_COMBO1);
  43. switch (uMsg)
  44. {
  45. case WM_INITDIALOG: {
  46. ComboBox_AddString(ComboBox, "Sphere");
  47. ComboBox_AddString(ComboBox, "Cube");
  48. ComboBox_AddString(ComboBox, "Circle");
  49. ComboBox_AddString(ComboBox, "Square");
  50.  
  51. Button_Enable(GetDlgItem(hWnd, ID_SAVE), 0);
  52. break;
  53. }
  54.  
  55. case WM_CLOSE:
  56. DestroyWindow(hWnd);
  57. break;
  58. case WM_COMMAND: {
  59. if (LOWORD(wParam) == ID_SAVE) {
  60. char val[500];
  61. string figure;
  62. Edit_GetText(GetDlgItem(hWnd, IDC_EDIT2), val, sizeof(val));
  63.  
  64. double value = atof(val), calc = 0;
  65.  
  66. int boxValue = ComboBox_GetCurSel(ComboBox);
  67.  
  68. if (boxValue == 0) {
  69. figure = "Sphere: ";
  70. calc = 4 * 3.14*pow(value, 2);
  71. }
  72. else if (boxValue == 1) {
  73. figure = "Cube: ";
  74. calc = pow(value, 3);
  75. }
  76. else if (boxValue == 2) {
  77. figure = "Circle: ";
  78. calc = 3.14 * pow(value, 2);
  79. }
  80. else if (boxValue == 3) {
  81. figure = "Square: ";
  82. calc = pow(value, 2);
  83. }
  84.  
  85. figure = figure + to_string(calc);
  86.  
  87. ofstream file("datalist.txt", ios_base::app);
  88.  
  89. file << figure.c_str() << endl;
  90. file.close();
  91.  
  92. } else {
  93. Button_Enable(GetDlgItem(hWnd, ID_SAVE), 0);
  94. //Check val's
  95. if (ComboBox_GetCurSel(ComboBox) < 0) break;
  96. if (Edit_GetTextLength(GetDlgItem(hWnd, IDC_EDIT2)) < 1) break;
  97.  
  98. Button_Enable(GetDlgItem(hWnd, ID_SAVE), 1);
  99. }
  100. break;
  101. }
  102. case WM_DESTROY:
  103. PostQuitMessage(0);
  104. break;
  105. }
  106.  
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment