0% found this document useful (0 votes)
49 views2 pages

Todo List - CPP

The document contains a C++ program that implements a simple To-Do List application using the Windows API. It allows users to input a date and displays tasks associated with that date in a list box. The program includes functions for loading tasks from a database, handling user input, and managing the window's lifecycle.

Uploaded by

sabashafqat771
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views2 pages

Todo List - CPP

The document contains a C++ program that implements a simple To-Do List application using the Windows API. It allows users to input a date and displays tasks associated with that date in a list box. The program includes functions for loading tasks from a database, handling user input, and managing the window's lifecycle.

Uploaded by

sabashafqat771
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#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 = {};
[Link] = TodoListProc;
[Link] = hInstance;
[Link] = 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);
}

You might also like