#include <windows.
h>
#include <string>
#include <vector>
#include <tuple>
#include "database.h"
HWND hTodoListBox, hDateInput, hDateLabel, hShowBtn;
// Function to load tasks for a given date
void LoadTasksForDate(HWND hwnd, const std::string& date) {
std::vector<std::tuple<int, std::string, std::string, std::string >> tasks =
db_LoadTasksForDate(date);
SendMessage(hTodoListBox, LB_RESETCONTENT, 0, 0);
for (const auto& task : tasks) {
int id;
std::string name, deadline, timeRequired;
std::tie(id, name, deadline, timeRequired) = task;
std::string display = "Task: " + name + " | Deadline: " + deadline +
" | Time: " + timeRequired;
SendMessageA(hTodoListBox, LB_ADDSTRING, 0, (LPARAM)display.c_str());
}
}
// Get string from Edit control
std::string GetTextFromHWND(HWND hwnd) {
int length = GetWindowTextLength(hwnd);
char* buffer = new char[length + 1];
GetWindowTextA(hwnd, buffer, length + 1);
std::string text(buffer);
delete[] buffer;
return text;
}
// Window procedure
LRESULT CALLBACK TodoListProc(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam) {
switch (msg) {
case WM_CREATE:
CreateWindowW(L"STATIC", L"To-Do List", WS_CHILD | WS_VISIBLE,
20, 10, 200, 20, hwnd, nullptr, nullptr, nullptr);
// Label and date input
CreateWindowW(L"STATIC", L"Enter Date (dd/mm/yyyy):", WS_CHILD |
WS_VISIBLE,
20, 40, 180, 20, hwnd, nullptr, nullptr, nullptr);
hDateInput = CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER,
200, 40, 150, 20, hwnd, (HMENU)1000, nullptr, nullptr);
hShowBtn = CreateWindowW(L"BUTTON", L"Show Tasks", WS_CHILD | WS_VISIBLE |
BS_PUSHBUTTON,
370, 40, 100, 25, hwnd, (HMENU)1002, nullptr, nullptr);
// ListBox for tasks
hTodoListBox = CreateWindowW(L"LISTBOX", nullptr, WS_CHILD | WS_VISIBLE |
WS_VSCROLL | LBS_NOTIFY,
20, 80, 540, 200, hwnd, (HMENU)1001, nullptr, nullptr);
break;
case WM_COMMAND:
if (LOWORD(wParam) == 1002) { // Show Tasks button
std::string date = GetTextFromHWND(hDateInput);
LoadTasksForDate(hwnd, date);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
return 0;
}
// Entry point to open To-Do List window
void ShowTodoListWindow(HINSTANCE hInstance) {
const wchar_t CLASS_NAME[] = L"TodoListWindowClass";
WNDCLASSW wc = {};
wc.lpfnWndProc = TodoListProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClassW(&wc);
HWND hwnd = CreateWindowW(CLASS_NAME, L"Task Scheduler - To-Do List",
WS_OVERLAPPEDWINDOW, 100, 100, 600, 350,
nullptr, nullptr, hInstance, nullptr);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
}