Advertisement
alexx876

Untitled

Dec 8th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.67 KB | None | 0 0
  1. #include <tchar.h>
  2. #include <Strsafe.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include<string>
  6. #include<string.h>
  7. #include <windows.h>
  8. #include "resource.h"
  9. #include <fstream>
  10. #include "commctrl.h"
  11. #include <streambuf>
  12. #pragma comment(lib, "comctl32.lib")
  13. #include <commctrl.h>
  14. #include <Shlobj_core.h>
  15.  
  16.  
  17. using namespace std;
  18.  
  19. //Конец объявления функций
  20.  
  21. typedef struct
  22. {
  23.  
  24. int number;
  25. char name[15];
  26. int count;
  27. } train;
  28.  
  29. INT list_count = 0;
  30. train *TRAIN = (train*)malloc(sizeof(train)*list_count);
  31.  
  32. #define ID_LISTBOX 3001
  33. #define ID_BUTTON_ABOUT 3002
  34. #define ID_BUTTON_DEL 3003
  35. #define ID_BUTTON_CREATE 3004
  36. #define ID_OPEN 3005
  37. #define ID_SAVE 3006
  38. #define ID_EXIT 3007
  39. #define ID_NAME_B 3008
  40. #define ID_NAME_Y 3009
  41. #define ID_CAR_B 3010
  42. #define ID_CAR_Y 3011
  43. #define ID_LISTVIEW 3012
  44.  
  45. int RegisterParentWindowClass(void);
  46. void CreateGUIElements(HWND);
  47.  
  48. BOOL CALLBACK helpProc(HWND, UINT, WPARAM, LPARAM);
  49. LRESULT CALLBACK ParentWndProc(HWND, UINT, WPARAM, LPARAM);
  50.  
  51. //Путь
  52. string path = "*";
  53.  
  54.  
  55. char ParentClassName[] = "ParentWindowClass";
  56. HINSTANCE hInstance;
  57. HWND hwnd_main;
  58.  
  59. HMENU hMenu, hFileMenu, hSortMenu;
  60. HWND hButtonAdd, hButtonCreate, hButtonDelete, hListBox, hEditCar, hEditName, hEditNumber, hListView;
  61.  
  62. INT num = -1, N = -1, A = 0;
  63. CHAR buffer[100], buf1[40], buf2[40];
  64. CHAR szSymbol[1];
  65. CHAR nameFile[] = "data.bin";
  66. CHAR add[35] = "";
  67. DWORD amount = 1;
  68.  
  69. void AddColToListView(char *st, int sub, int size)
  70. {
  71. LVCOLUMN lvc;
  72. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  73. lvc.iSubItem = sub;
  74. lvc.pszText = st;
  75. lvc.cx = size;
  76. lvc.fmt = LVCFMT_LEFT;
  77.  
  78. ListView_InsertColumn(hListView, sub, &lvc);
  79.  
  80. }
  81.  
  82. int i;
  83.  
  84. BOOL InitListViewImageLists(HWND hWndListView, int size)
  85. {
  86.  
  87. HIMAGELIST hSmall;
  88. SHFILEINFO lp;
  89. hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_MASK | ILC_COLOR32, size, 1);
  90.  
  91. WIN32_FIND_DATA FindFileData;
  92. HANDLE hFind;
  93.  
  94. hFind = FindFirstFile(path.c_str(), &FindFileData);
  95. if (hFind == INVALID_HANDLE_VALUE) {
  96. MessageBox(0, "Ошибка", "Не найден", MB_OK | MB_ICONWARNING);
  97. }
  98. else
  99. {
  100. do {//присваеваем атрибуты
  101. if (FindFileData.cFileName == ".") {//если диск
  102. char buf1[MAX_PATH] = "C:\\*";
  103. strcat(buf1, (char*)FindFileData.cFileName);
  104.  
  105.  
  106. }
  107. if (FindFileData.cFileName == "..") {//если фаилы,папки
  108. char buf1[MAX_PATH] = "C:\\*";
  109. strcat(buf1, (char*)FindFileData.cFileName);
  110.  
  111. }
  112.  
  113. } while (FindNextFile(hFind, &FindFileData) != 0);
  114.  
  115. FindClose(hFind);
  116. }
  117.  
  118. ListView_SetImageList(hWndListView, hSmall, LVSIL_SMALL);
  119.  
  120. return TRUE;
  121. }
  122.  
  123. void Viev_List(char *buf, HWND hList, int i) {
  124. LVITEM lvItem;
  125. lvItem.mask = LVIF_IMAGE | LVIF_TEXT;
  126. lvItem.state = 0;
  127. lvItem.stateMask = 0;
  128. lvItem.iItem = i;
  129. lvItem.iImage = i;
  130. lvItem.iSubItem = 0;
  131. lvItem.pszText = buf;
  132. lvItem.cchTextMax = sizeof(buf);
  133. ListView_InsertItem(hList, &lvItem);
  134. }
  135.  
  136. void FindFile(HWND hList)
  137. {
  138. //Очистка ListView
  139. ListView_DeleteAllItems(hList);
  140.  
  141. SendMessage(hList, LVM_DELETEALLITEMS, (WPARAM)0, (LPARAM)0);
  142. i = 0;
  143.  
  144. WIN32_FIND_DATA FindFileData;
  145. HANDLE hFind;
  146.  
  147. hFind = FindFirstFile(path.c_str(), &FindFileData);
  148. if (hFind == INVALID_HANDLE_VALUE) {
  149. MessageBox(0, "Ошибка", "Не найден", MB_OK | MB_ICONWARNING);
  150. }
  151. else
  152. {
  153. do {
  154. Viev_List((char*)FindFileData.cFileName, hList, i);//выз. ф-ция Viev_List передаем туда наиденый фаил ,и HWND ListBox и итератор i++,
  155. ++i;
  156.  
  157. } while (FindNextFile(hFind, &FindFileData) != 0);
  158.  
  159. FindClose(hFind); //закрываем работу поиска фаилов
  160. InitListViewImageLists(hList, i);//тут уже передаем HWND ListBox, и кол-во фаилов
  161.  
  162.  
  163. }
  164. }
  165.  
  166. int RegisterParentWindowClass(void)
  167. {
  168. WNDCLASS wc;
  169. memset(&wc, 0, sizeof(WNDCLASS));
  170. wc.style = CS_VREDRAW | CS_HREDRAW;
  171. wc.lpfnWndProc = ParentWndProc;
  172. wc.hInstance = hInstance;
  173. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  174. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  175. wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
  176. wc.lpszMenuName = NULL;
  177. wc.lpszClassName = ParentClassName;
  178.  
  179. return RegisterClass(&wc);
  180. }
  181.  
  182. int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  183. {
  184. hInstance = hIns;
  185. if (!RegisterParentWindowClass()) return -1;
  186.  
  187. hwnd_main = CreateWindow(ParentClassName, "14 Вариант",
  188. WS_SYSMENU | WS_OVERLAPPED | WS_BORDER | DS_CENTER,
  189. 500, 300, 500, 300, NULL, NULL, hInstance, 0);
  190.  
  191. if (!hwnd_main) return 0;
  192. ShowWindow(hwnd_main, SW_SHOW);
  193. UpdateWindow(hwnd_main);
  194.  
  195. MSG msg;
  196. while (GetMessage(&msg, 0, 0, 0)) {
  197. TranslateMessage(&msg);
  198. DispatchMessage(&msg);
  199. }
  200.  
  201. return 0;
  202. }
  203.  
  204. LRESULT CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  205. {
  206. HMENU ContextMenu;
  207. switch (message) {
  208. case WM_CREATE:
  209. {
  210. RECT rect;
  211. GetWindowRect(hwnd, &rect);
  212. LONG width = rect.right - rect.left;
  213. LONG height = rect.bottom - rect.top;
  214.  
  215. hButtonAdd = CreateWindow(TEXT("button"), "?", WS_CHILD | WS_VISIBLE,
  216. 450, 10, 20, 20, hwnd, (HMENU)ID_BUTTON_ABOUT, hInstance, 0);
  217. hButtonCreate = CreateWindow(TEXT("button"), "Архивировать", WS_CHILD | WS_VISIBLE,
  218. width / 2 - 70, height - 110, 130, 30, hwnd, (HMENU)ID_BUTTON_CREATE, hInstance, 0);
  219. hButtonDelete = CreateWindow(TEXT("button"), "Разархивировать", WS_CHILD | WS_VISIBLE,
  220. width - 165, height - 110, 130, 30, hwnd, (HMENU)ID_BUTTON_DEL, hInstance, 0);
  221. InitCommonControls();
  222. hListView = CreateWindowEx(WS_EX_CLIENTEDGE | LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT, WC_LISTVIEW, (LPCTSTR)NULL,
  223. WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SINGLESEL, 20, 35, width - 55, height - 150, hwnd, (HMENU)NULL,
  224. hInstance, (LPVOID)NULL);
  225. SendMessage(hListBox, WM_SETFONT, (LPARAM)GetStockObject(DEFAULT_GUI_FONT), true);
  226. ListView_SetExtendedListViewStyleEx(hListBox, 0, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
  227.  
  228. AddColToListView("Имя", 1, 100);
  229. AddColToListView("Тип", 2, 50);
  230. AddColToListView("Размер", 3, 50);
  231. AddColToListView("Дата", 4, 70);
  232. AddColToListView("Атрибуты", 5, 50);
  233. FindFile(hListView);
  234.  
  235. //SHOW LISTBOX
  236. /*ShowWindow(hListBox, SW_SHOWDEFAULT);*/
  237.  
  238. hMenu = CreateMenu();
  239. hFileMenu = CreatePopupMenu();
  240. hSortMenu = CreatePopupMenu();
  241. AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hFileMenu, "Файл");
  242. {
  243. AppendMenu(hFileMenu, MF_STRING, ID_OPEN, "Открыть");
  244. AppendMenu(hFileMenu, MF_STRING, ID_SAVE, "Сохранить");
  245. AppendMenu(hFileMenu, MF_SEPARATOR, NULL, "");
  246. AppendMenu(hFileMenu, MF_STRING, ID_EXIT, "Выход");
  247. }
  248. SetMenu(hwnd, hMenu);
  249. break;
  250. }
  251. case WM_CONTEXTMENU: {
  252. ContextMenu = CreatePopupMenu();
  253.  
  254. POINT cp;
  255. GetCursorPos(&cp);
  256.  
  257. AppendMenu(ContextMenu, MF_STRING | MF_POPUP, 3008, TEXT("Добавить"));
  258. AppendMenu(ContextMenu, MF_STRING | MF_POPUP, 3009, TEXT("Изменить"));
  259. AppendMenu(ContextMenu, MF_STRING | MF_POPUP, 3010, TEXT("Удалить"));
  260.  
  261. TrackPopupMenu(ContextMenu, TPM_RIGHTBUTTON, cp.x, cp.y, 1, hwnd, 0);
  262. break;
  263. }
  264. case WM_COMMAND: {
  265. switch (LOWORD(wParam)) {
  266. case ID_BUTTON_ABOUT:
  267. {
  268. MessageBox(hwnd, "Hi!", "About Us", MB_OK | MB_ICONEXCLAMATION);
  269. break;
  270. }
  271. case ID_EXIT:
  272. {
  273. PostQuitMessage(0);
  274. free(TRAIN);
  275. break;
  276. }
  277. case ID_OPEN: {
  278. break;
  279. }
  280. }
  281. break;
  282. }
  283. case WM_DESTROY:
  284. PostQuitMessage(0);
  285. free(TRAIN);
  286. break;
  287. default: return DefWindowProc(hwnd, message, wParam, lParam);
  288. }
  289. return 0;
  290. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement