Advertisement
Old_But_Gold

Untitled

Sep 3rd, 2024 (edited)
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. #ifndef UNICODE
  2. #define UNICODE
  3. #endif
  4.  
  5. #include <Windows.h>
  6. #include <CommCtrl.h>
  7.  
  8. #define LoadFilesButtonClicked 1
  9. #define SortFilesButtonClicked 2
  10.  
  11. struct FileData {
  12. const wchar_t* fileName;
  13. const FILETIME* fileTime;
  14. };
  15.  
  16. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  17.  
  18. HWND hEdit, hListViewLeft, hListViewRight, hLoadButton, hSortButton;
  19.  
  20. void AddColumns(HWND hListView)
  21. {
  22. LVCOLUMN lvCol = { };
  23. lvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
  24.  
  25. lvCol.cx = 100;
  26. lvCol.pszText = (LPWSTR)L"Index";
  27. ListView_InsertColumn(hListView, 0, &lvCol);
  28.  
  29. lvCol.cx = 100;
  30. lvCol.pszText = (LPWSTR)L"File Name";
  31. ListView_InsertColumn(hListView, 1, &lvCol);
  32.  
  33. lvCol.cx = 300;
  34. lvCol.pszText = (LPWSTR)L"Last Access Time";
  35. ListView_InsertColumn(hListView, 2, &lvCol);
  36. }
  37.  
  38. void AddItemToListView(HWND hListView, int index, FileData* fileData)
  39. {
  40. LVITEM lvItem;
  41. lvItem.mask = LVIF_TEXT;
  42. lvItem.iItem = index;
  43. lvItem.iSubItem = 0; //Позицию для вставки в колонку
  44.  
  45. }
  46.  
  47. void LoadFiles(HWND hListView, const wchar_t* directoryPath)
  48. {
  49.  
  50. }
  51.  
  52. void SortListView(HWND hListView) {
  53.  
  54. }
  55.  
  56.  
  57. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
  58. {
  59. const wchar_t CLASS_NAME[] = L"WINAPI_LAB1";
  60.  
  61. WNDCLASS wc = { };
  62. wc.lpfnWndProc = WindowProc;
  63. wc.hInstance = hInstance;
  64. wc.lpszClassName = CLASS_NAME;
  65.  
  66. RegisterClass(&wc);
  67.  
  68. HWND hwnd = CreateWindowEx(0, CLASS_NAME, L"WINAPI_LAB1", WS_OVERLAPPEDWINDOW,
  69. CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
  70. NULL, NULL, hInstance, NULL
  71. );
  72.  
  73. if (hwnd == NULL)
  74. {
  75. return 0;
  76. }
  77.  
  78. ShowWindow(hwnd, nCmdShow);
  79.  
  80. hEdit = CreateWindowEx(0, WC_EDIT, L"",
  81. WS_CHILD | WS_VISIBLE | WS_BORDER,
  82. 10, 10, 500, 20,
  83. hwnd, NULL, NULL, NULL);
  84. ShowWindow(hEdit, TRUE);
  85.  
  86. hListViewLeft = CreateWindowEx(0, WC_LISTVIEW, L"",
  87. WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_REPORT,
  88. 10, 40, 370, 500,
  89. hwnd, NULL, NULL, NULL);
  90. ShowWindow(hListViewLeft, TRUE);
  91.  
  92. hListViewRight = CreateWindowEx(0, WC_LISTVIEW, L"",
  93. WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_REPORT,
  94. 390, 40, 370, 500,
  95. hwnd, NULL, NULL, NULL);
  96. ShowWindow(hListViewRight, TRUE);
  97.  
  98. AddColumns(hListViewLeft);
  99. AddColumns(hListViewRight);
  100.  
  101. hLoadButton = CreateWindowEx(0, WC_BUTTON, L"Load Files",
  102. WS_CHILD | WS_VISIBLE,
  103. 530, 10, 80, 25,
  104. hwnd, (HMENU)LoadFilesButtonClicked, NULL, NULL);
  105.  
  106. ShowWindow(hLoadButton, TRUE);
  107.  
  108. hSortButton = CreateWindowEx(0, L"BUTTON", L"Sort Files",
  109. WS_CHILD | WS_VISIBLE,
  110. 680, 10, 80, 25,
  111. hwnd, (HMENU)SortFilesButtonClicked, NULL, NULL);
  112.  
  113. ShowWindow(hLoadButton, TRUE);
  114.  
  115. MSG msg;
  116. while (GetMessage(&msg, NULL, 0, 0) > 0)
  117. {
  118. TranslateMessage(&msg);
  119. DispatchMessage(&msg);
  120. }
  121.  
  122. return 0;
  123. }
  124.  
  125. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  126. {
  127. switch (uMsg)
  128. {
  129. case WM_CREATE:
  130. {
  131.  
  132. }
  133. break;
  134.  
  135. case WM_COMMAND:
  136. switch (LOWORD(wParam))
  137. {
  138. case LoadFilesButtonClicked:
  139. {
  140. wchar_t directoryPath[MAX_PATH];
  141. GetWindowText(hEdit, directoryPath, MAX_PATH);
  142. LoadFiles(hListViewLeft, directoryPath);
  143. }
  144. break;
  145.  
  146. case SortFilesButtonClicked:
  147. SortListView(hListViewRight);
  148. break;
  149. }
  150. break;
  151.  
  152. case WM_CLOSE:
  153. PostQuitMessage(0);
  154. break;
  155.  
  156. case WM_DESTROY:
  157. return 0;
  158.  
  159. default:
  160. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  161. }
  162. return 0;
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement