Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <cstring>
  6. using namespace std;
  7.  
  8. //#define ID_TextArea 3002
  9.  
  10. HINSTANCE hInst;
  11.  
  12. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  13. LRESULT CALLBACK Wndchild(HWND, UINT, WPARAM, LPARAM);
  14. int RegClass();
  15. HWND hwndR;
  16. HWND hwndL;
  17.  
  18. HWND savebutton; //дескриптор кнопки Сохранить
  19. HWND Cancelbuttom; //дескриптор кнопки Отмена
  20. HWND TextName; // дестриптор "edit" де будет именя файла
  21. HWND TextArea; // дестриптор "edit"где впишется текст
  22. char chText[70]; //имя файла
  23. char Text[100]; // текст файла
  24. int N=0;
  25.  
  26. int Regchil()
  27. {
  28. WNDCLASS wc;
  29. memset(&wc, 0, sizeof(WNDCLASS));
  30. wc.lpfnWndProc = Wndchild;
  31. wc.hInstance = hInst;
  32. wc.hIcon = LoadIcon(NULL, IDC_ARROW);
  33. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  34. wc.hbrBackground = GetStockBrush(COLOR_WINDOW);
  35. wc.lpszClassName = L"child";
  36. return RegisterClass(&wc);
  37. }
  38.  
  39. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCndShow)
  40. {
  41. MSG Msg;
  42. RegClass();
  43. int x = GetSystemMetrics(SM_CXSCREEN);
  44. int y = GetSystemMetrics(SM_CYSCREEN);
  45. HWND hwnd = CreateWindow(L"MainWindow", L"программа(вариант 16)", WS_OVERLAPPEDWINDOW | WS_SIZEBOX, x / 3, y / 3, x / 2 - 350, y / 2 - 40, NULL, NULL, hInst, NULL);
  46. ShowWindow(hwnd, nCndShow);
  47.  
  48. TextName = CreateWindow(L"edit", L"text.txt", WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 300, 20, hwnd, (HMENU)3001 , hInstance, NULL);
  49. ShowWindow(TextName, nCndShow);
  50. TextArea = CreateWindow(L"edit", L"", WS_CHILD | WS_BORDER| ES_MULTILINE, 50, 80, 300, 200, hwnd, (HMENU)3002, hInst, NULL);
  51. ShowWindow(TextArea, nCndShow);
  52. savebutton = CreateWindow(L"button", L"Сохранить", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE | WS_BORDER, 50, 290, 85, 50, hwnd, (HMENU)3003, hInst, NULL);
  53. ShowWindow(savebutton, nCndShow);
  54. Cancelbuttom = CreateWindow(L"button", L"отменить", WS_CHILD | WS_VISIBLE | WS_BORDER, 265, 290, 85, 50, hwnd, (HMENU)3004, hInst, NULL);
  55. ShowWindow(Cancelbuttom, true);
  56.  
  57. //SendMessage(TextArea, EM_SETREADONLY, false, 0);
  58. while (GetMessage(&Msg, NULL, 0, 0)) DispatchMessage(&Msg);
  59. return 0;
  60. }
  61.  
  62. int RegClass()
  63. {
  64. WNDCLASS wc;
  65. memset(&wc, 0, sizeof(WNDCLASS));
  66. wc.lpfnWndProc = WndProc;
  67. wc.hInstance = hInst;
  68. wc.hIcon = LoadIcon(NULL, IDC_ARROW);
  69. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  70. wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
  71. //wc.hbrBackground = GetStockBrush(COLOR_WINDOW);
  72. wc.lpszClassName = L"MainWindow";
  73. return RegisterClass(&wc);
  74. }
  75.  
  76. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lparam)
  77. {
  78. ofstream Write;
  79. wfstream read;
  80.  
  81. switch (msg) {
  82.  
  83. case WM_COMMAND:
  84. {
  85.  
  86. switch (LOWORD(wParam)) {
  87.  
  88. case 3003:
  89. wchar_t name[100];
  90. memset(&name, 100, sizeof(name));
  91. GetWindowText(TextName, (LPWSTR)name, 15);
  92.  
  93. Write.open(name);
  94. wchar_t Area[100];
  95. memset(&Area, 100, sizeof(Area));
  96.  
  97. N = GetWindowText(TextArea, Area, 100);
  98. MessageBox(TextArea, Area, L"Текст файла ", MB_OK);
  99.  
  100. for (int i = 0;i < N;i++) {
  101. Write << (char)Area[i];
  102. }
  103. Write.close();
  104. break;
  105.  
  106. case 3004:
  107. read.open(name);
  108.  
  109. wchar_t str[100];
  110. memset(&str, 100, sizeof(str));
  111. //read >> Area;
  112.  
  113. GetDlgItemText(hwnd, 1, str, 20);
  114. SetWindowText(TextArea, (LPWSTR)str);
  115.  
  116. read.close();
  117.  
  118. break;
  119. return DefWindowProc(hwnd, msg, wParam, lparam);
  120.  
  121.  
  122. }
  123. break;
  124. }
  125. case WM_DESTROY: {
  126. PostQuitMessage(0);
  127. return 0;
  128. }
  129. default:
  130. return(DefWindowProc(hwnd, msg, wParam, lparam));
  131. }
  132. }
  133.  
  134.  
  135. LRESULT CALLBACK Wndchild(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  136. {
  137. return DefWindowProc(hwnd, msg, wParam, lParam);
  138. }
  139.  
  140. /*file.open("text.txt");
  141. if (!file) {
  142. //file.close();
  143. MessageBox(hwnd, L"Не найдет файл text.txt", L"Ошибка!", 0);
  144. return 0;
  145. }
  146. SetWindowText(TextArea, L"Поц...");
  147. file.close();*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement