Advertisement
alien_fx_fiend

Dictionary-win32 GUI-Based F2Key= EditsWord + Icon In Titlebar !!

Apr 1st, 2025 (edited)
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 50.88 KB | Source Code | 0 0
  1. ==++ Here's the full source code for (file 1/4) "realtime-search.cpp"::: ++==
  2. ```realtime-search.cpp
  3. #include <Windows.h>
  4. #include <CommCtrl.h>
  5. #include <fstream>
  6. #include <sstream>
  7. #include <string>
  8. #include <algorithm>
  9. #include <vector>
  10. #include "resource2.h"
  11. #include "resource.h"
  12.  
  13. #pragma comment(lib, "comctl32.lib")
  14.  
  15. using namespace std;
  16.  
  17. // Structure to represent a dictionary entry
  18. struct DictionaryEntry {
  19.    wstring word;
  20.    wstring definition;
  21. };
  22.  
  23. // Structure to represent a node in the linked list
  24. struct Node {
  25.    DictionaryEntry data;
  26.    Node* next;
  27. };
  28.  
  29. Node* dictionary = nullptr;
  30. vector<wstring> words;
  31. WNDPROC oldWordEditProc;
  32. WNDPROC oldDefinitionEditProc;
  33. HHOOK g_hHook = NULL;
  34. HWND g_hDlg = NULL;
  35. HWND g_hDefinitionDlg = NULL; // Add this near where you declare g_hDlg
  36.  
  37. // Function prototypes
  38. //LRESULT CALLBACK EditSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  39. LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
  40. INT_PTR CALLBACK ViewDefinitionDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  41. void AddWordToList(HWND hwnd);
  42. void insertNode(Node*& head, const DictionaryEntry& entry);
  43. //void addWord(Node*& head, const wstring& word, const wstring& definition);
  44. bool addWord(Node*& head, const wstring& word, const wstring& definition);
  45. void deleteWord(Node*& head, const wstring& keyword);
  46. wstring InputBox(HWND hwnd, const wstring& prompt, const wstring& title);
  47. void DisplayDefinition(HWND hwnd, const wstring& word, const wstring& definition);
  48. void editWord(Node* head, const wstring& oldWord, const wstring& newWord, const wstring& newDefinition);
  49. void listWords(const Node* head, vector<wstring>& words);
  50. void serializeDictionary(const Node* head, const wstring& filename);
  51. void deserializeDictionary(Node*& head, const wstring& filename);
  52. void searchWordRealtime(const Node* head, const wstring& keyword, vector<wstring>& suggestions);
  53. int pruneDictionary(Node*& head);
  54. void updateDictionaryAfterPrune(Node*& head, vector<wstring>& words, HWND hwnd);
  55. void updateListBox(HWND hwnd, const vector<wstring>& words);
  56.  
  57. LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
  58.    if (nCode == HC_ACTION) {
  59.        KBDLLHOOKSTRUCT* pKbdStruct = (KBDLLHOOKSTRUCT*)lParam;
  60.        if (wParam == WM_KEYDOWN) {
  61.            switch (pKbdStruct->vkCode) {
  62.            case VK_RETURN:
  63.                if (GetFocus() == GetDlgItem(g_hDlg, IDC_WORD_INPUT) ||
  64.                    GetFocus() == GetDlgItem(g_hDlg, IDC_DEFINITION_INPUT)) {
  65.                    AddWordToList(g_hDlg);
  66.                    return 1;
  67.                }
  68.                break;
  69.            case VK_ESCAPE:
  70.                if (GetDlgItem(g_hDlg, IDCANCEL)) {
  71.                    SendMessage(g_hDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0);
  72.                    return TRUE;
  73.                }
  74.                else if (GetDlgItem(g_hDlg, IDNO)) {
  75.                    SendMessage(g_hDlg, WM_COMMAND, MAKEWPARAM(IDNO, 0), 0);
  76.                    return TRUE;
  77.                }
  78.                else {
  79.                    SendMessage(g_hDlg, WM_CLOSE, 0, 0);
  80.                    return TRUE;
  81.                }
  82.                break;
  83.            case VK_F1:
  84.            {
  85.                if (g_hDefinitionDlg && IsWindowVisible(g_hDefinitionDlg)) {
  86.                    // If the definition window is visible, hide it
  87.                    ShowWindow(g_hDefinitionDlg, SW_HIDE);
  88.                }
  89.                else {
  90.                    // If the definition window is not visible or doesn't exist, show/create it
  91.                     HWND hListBox = GetDlgItem(g_hDlg, IDC_LISTBOX);
  92.                     int selectedIndex = SendMessage(hListBox, LB_GETCURSEL, 0, 0);
  93.                     if (selectedIndex != LB_ERR) {
  94.                         wchar_t selectedWord[256];
  95.                         SendMessage(hListBox, LB_GETTEXT, selectedIndex, (LPARAM)selectedWord);
  96.                         Node* current = dictionary;
  97.                         while (current) {
  98.                             if (current->data.word == selectedWord) {
  99.                                 wstring message = L"Definition of '" + current->data.word + L"': \n\n" + current->data.definition;
  100.                                 if (g_hDefinitionDlg) {
  101.                                     // Update existing dialog
  102.                                     SetDlgItemText(g_hDefinitionDlg, IDC_DEFINITION_EDIT, message.c_str());
  103.                                     ShowWindow(g_hDefinitionDlg, SW_SHOW);
  104.                                 }
  105.                                 else {
  106.                                     // Create new dialog
  107.                                     g_hDefinitionDlg = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DEFINITION), g_hDlg, ViewDefinitionDlgProc, (LPARAM)new wstring(message));
  108.                                     ShowWindow(g_hDefinitionDlg, SW_SHOW);
  109.                                 }
  110.                                 break;
  111.                             }
  112.                             current = current->next;
  113.                         }
  114.                     }
  115.                 }
  116.                 return 1;
  117.             }
  118.             /* {
  119.                 if (g_hDefinitionDlg) {
  120.                     if (IsWindowVisible(g_hDefinitionDlg)) {
  121.                         ShowWindow(g_hDefinitionDlg, SW_HIDE);
  122.                     }
  123.                     else {
  124.                         ShowWindow(g_hDefinitionDlg, SW_SHOW);
  125.                     }
  126.                 }
  127.                 else {
  128.                     HWND hListBox = GetDlgItem(g_hDlg, IDC_LISTBOX);
  129.                     int selectedIndex = SendMessage(hListBox, LB_GETCURSEL, 0, 0);
  130.                     if (selectedIndex != LB_ERR) {
  131.                         wchar_t selectedWord[256];
  132.                         SendMessage(hListBox, LB_GETTEXT, selectedIndex, (LPARAM)selectedWord);
  133.                         Node* current = dictionary;
  134.                         while (current) {
  135.                             if (current->data.word == selectedWord) {
  136.                                 g_hDefinitionDlg = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DEFINITION), g_hDlg, ViewDefinitionDlgProc, (LPARAM)new wstring(current->data.definition));
  137.                                 ShowWindow(g_hDefinitionDlg, SW_SHOW);
  138.                                 break;
  139.                             }
  140.                             current = current->next;
  141.                         }
  142.                     }
  143.                 }
  144.                 return 1;
  145.             }*/
  146.             case VK_F2:
  147.             {
  148.                 // F2: Simulate the "Edit Word" command for the currently selected item.
  149.                 HWND hListBox = GetDlgItem(g_hDlg, IDC_LISTBOX);
  150.                 int selectedIndex = SendMessage(hListBox, LB_GETCURSEL, 0, 0);
  151.                 if (selectedIndex != LB_ERR) {
  152.                     // Send WM_COMMAND message to simulate clicking the "Edit Word" button.
  153.                     SendMessage(g_hDlg, WM_COMMAND, MAKEWPARAM(IDC_EDIT_WORD, BN_CLICKED), 0);
  154.                 }
  155.                 return 1;
  156.             }
  157.             case VK_F9:
  158.             {
  159.                 MessageBox(g_hDlg, L"Advanced LinkedList Dictionary using SubClassing & LowLevelHookFunction. Made in C++ GUI-based Win32 1148+ Lines of code! Copyright (c) 2025 Evans Thorpemorton", L"About Info", MB_OK | MB_ICONINFORMATION);
  160.                 return 1;
  161.             }
  162.             }
  163.         }
  164.     }
  165.     return CallNextHookEx(NULL, nCode, wParam, lParam);
  166. }
  167.  
  168. /*INT_PTR CALLBACK ViewDefinitionDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
  169.     switch (message) {
  170.     case WM_INITDIALOG:
  171.     {
  172.         wstring* definition = (wstring*)lParam;
  173.         SetDlgItemText(hDlg, IDC_DEFINITION_EDIT, definition->c_str());
  174.         delete definition;
  175.         return (INT_PTR)TRUE;
  176.     }
  177.     case WM_COMMAND:
  178.         if (LOWORD(wParam) == IDCANCEL) {
  179.             EndDialog(hDlg, LOWORD(wParam));
  180.             return (INT_PTR)TRUE;
  181.         }
  182.         break;
  183.     case WM_CLOSE:
  184.         EndDialog(hDlg, 0);
  185.         return (INT_PTR)TRUE;
  186.     }
  187.     return (INT_PTR)FALSE;
  188. }*/
  189. INT_PTR CALLBACK ViewDefinitionDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
  190.     switch (message) {
  191.     case WM_INITDIALOG:
  192.     {
  193.         wstring* fullMessage = (wstring*)lParam;
  194.         SetDlgItemText(hDlg, IDC_DEFINITION_EDIT, fullMessage->c_str());
  195.         delete fullMessage;
  196.         return (INT_PTR)TRUE;
  197.     }
  198.     case WM_COMMAND:
  199.         if (LOWORD(wParam) == IDCANCEL) {
  200.             ShowWindow(hDlg, SW_HIDE);
  201.             return (INT_PTR)TRUE;
  202.         }
  203.         break;
  204.     case WM_CLOSE:
  205.         ShowWindow(hDlg, SW_HIDE);
  206.         return (INT_PTR)TRUE;
  207.     }
  208.     return (INT_PTR)FALSE;
  209. }
  210.  
  211. // Function implementations
  212. void insertNode(Node*& head, const DictionaryEntry& entry) {
  213.     Node* newNode = new Node{ entry, nullptr };
  214.     if (!head) {
  215.         head = newNode;
  216.     }
  217.     else {
  218.         Node* current = head;
  219.         while (current->next) {
  220.             current = current->next;
  221.         }
  222.         current->next = newNode;
  223.     }
  224. }
  225.  
  226. bool addWord(Node*& head, const wstring& word, const wstring& definition) {
  227.     // Check if the word already exists
  228.     Node* current = head;
  229.     while (current) {
  230.         if (current->data.word == word) {
  231.             return false; // Word already exists, don't add
  232.         }
  233.         current = current->next;
  234.     }
  235.  
  236.     // Word doesn't exist, add it
  237.     insertNode(head, { word, definition });
  238.     return true;
  239. }
  240. // w/o duplicates
  241. /* // Modify the addWord function to check for duplicates
  242. bool addWord(Node*& head, const wstring& word, const wstring& definition) {
  243.     // Check if the word already exists
  244.     Node* current = head;
  245.     while (current) {
  246.         if (current->data.word == word) {
  247.             return false; // Word already exists, don't add
  248.         }
  249.         current = current->next;
  250.     }
  251.  
  252.     // Word doesn't exist, add it
  253.     insertNode(head, { word, definition });
  254.     return true;
  255. }*/
  256. // /w duplicates
  257. /*void addWord(Node*& head, const wstring& word, const wstring& definition) {
  258.     insertNode(head, { word, definition });
  259. }*/
  260.  
  261. void deleteWord(Node*& head, const wstring& keyword) {
  262.     if (!head) return;
  263.  
  264.     if (head->data.word == keyword) {
  265.         Node* temp = head;
  266.         head = head->next;
  267.         delete temp;
  268.         return;
  269.     }
  270.  
  271.     Node* current = head;
  272.     while (current->next && current->next->data.word != keyword) {
  273.         current = current->next;
  274.     }
  275.  
  276.     if (current->next) {
  277.         Node* temp = current->next;
  278.         current->next = current->next->next;
  279.         delete temp;
  280.     }
  281. }
  282.  
  283. // Modify the InputBox function to pre-populate the input
  284. wstring InputBox(HWND hwnd, const wstring& prompt, const wstring& title, const wstring& defaultValue = L"") {
  285.     wstring input = defaultValue;
  286.     DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_INPUT), hwnd,
  287.         [](HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -> INT_PTR {
  288.             static wstring* pInput;
  289.             switch (message) {
  290.             case WM_INITDIALOG:
  291.                 pInput = (wstring*)lParam;
  292.                 SetDlgItemText(hDlg, IDC_INPUT, pInput->c_str());
  293.                 SendDlgItemMessage(hDlg, IDC_INPUT, EM_SETSEL, 0, -1);  // Select all text
  294.                 return (INT_PTR)TRUE;
  295.             case WM_COMMAND:
  296.                 if (LOWORD(wParam) == IDOK) {
  297.                     HWND hEdit = GetDlgItem(hDlg, IDC_INPUT);
  298.                     int len = GetWindowTextLength(hEdit) + 1;
  299.                     wchar_t* buffer = new wchar_t[len];
  300.                     GetWindowText(hEdit, buffer, len);
  301.                     *pInput = buffer;
  302.                     delete[] buffer;
  303.                     EndDialog(hDlg, IDOK);
  304.                     return (INT_PTR)TRUE;
  305.                 }
  306.                 else if (LOWORD(wParam) == IDCANCEL) {
  307.                     EndDialog(hDlg, IDCANCEL);
  308.                     return (INT_PTR)TRUE;
  309.                 }
  310.                 break;
  311.             }
  312.             return (INT_PTR)FALSE;
  313.         }, (LPARAM)&input);
  314.     return input;
  315. }
  316. /*wstring InputBox(HWND hwnd, const wstring& prompt, const wstring& title) {
  317.     wchar_t input[156] = L"";
  318.     if (DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_INPUT), hwnd,
  319.         [](HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -> INT_PTR {
  320.             static wchar_t input[156];
  321.             switch (message) {
  322.             case WM_INITDIALOG: {
  323.                 HWND hEdit = GetDlgItem(hDlg, IDC_INPUT);
  324.                 SetWindowText(hEdit, (LPCWSTR)lParam);
  325.                 SendMessage(hEdit, EM_SETSEL, 0, -1); // Select all text
  326.                 break;
  327.             }
  328.             case WM_COMMAND:
  329.                 if (LOWORD(wParam) == IDOK) {
  330.                     GetDlgItemText(hDlg, IDC_INPUT, input, 156);
  331.                     EndDialog(hDlg, IDOK);
  332.                     return (INT_PTR)TRUE;
  333.                 }
  334.                 else if (LOWORD(wParam) == IDCANCEL) {
  335.                     EndDialog(hDlg, IDCANCEL);
  336.                     return (INT_PTR)TRUE;
  337.                 }
  338.                 break;
  339.             }
  340.             return (INT_PTR)FALSE;
  341.         }, (LPARAM)prompt.c_str()) == IDOK) {
  342.         return (wstring)input;
  343.     }
  344.     return L"";
  345. }*/
  346.  
  347. void DisplayDefinition(HWND hwnd, const wstring& word, const wstring& definition) {
  348.     wstring message = L"Definition of '" + word + L"': \n\n" + definition;
  349.     HWND hDlg = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DEFINITION), hwnd, [](HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -> INT_PTR {
  350.         switch (message) {
  351.         case WM_INITDIALOG:
  352.         {
  353.             wstring* definition = (wstring*)lParam;
  354.             SetDlgItemText(hDlg, IDC_DEFINITION_EDIT, definition->c_str());
  355.             delete definition;
  356.         }
  357.         return (INT_PTR)TRUE;
  358.         case WM_COMMAND:
  359.             if (LOWORD(wParam) == IDCANCEL) {
  360.                 EndDialog(hDlg, LOWORD(wParam));
  361.                 return (INT_PTR)TRUE;
  362.             }
  363.             break;
  364.         case WM_CLOSE:
  365.             EndDialog(hDlg, 0);
  366.             return (INT_PTR)TRUE;
  367.         }
  368.         return (INT_PTR)FALSE;
  369.         }, (LPARAM)new wstring(message));
  370.     ShowWindow(hDlg, SW_SHOW);
  371. }
  372. /*void DisplayDefinition(HWND hwnd, const wstring& word, const wstring& definition) {
  373.     wstring message = L"Definition of '" + word + L"':\n\n" + definition;
  374.     MessageBox(hwnd, message.c_str(), L"Word Definition", MB_OK | MB_ICONINFORMATION);
  375. }*/
  376.  
  377. void editWord(Node* head, const wstring& oldWord, const wstring& newWord, const wstring& newDefinition) {
  378.     Node* current = head;
  379.     while (current) {
  380.         if (current->data.word == oldWord) {
  381.             current->data.word = newWord;
  382.             current->data.definition = newDefinition;
  383.             return;
  384.         }
  385.         current = current->next;
  386.     }
  387. }
  388.  
  389. void listWords(const Node* head, vector<wstring>& words) {
  390.     words.clear();
  391.     const Node* current = head;
  392.     while (current) {
  393.         words.push_back(current->data.word);
  394.         current = current->next;
  395.     }
  396. }
  397.  
  398. // Delimiter Old Semicolon
  399. void serializeDictionary(const Node* head, const wstring& filename) {
  400.     wofstream file(filename, ios::out | ios::trunc);
  401.     if (!file.is_open()) {
  402.         MessageBox(NULL, L"Failed to open file for writing", L"Error", MB_OK | MB_ICONERROR);
  403.         return;
  404.     }
  405.     const Node* current = head;
  406.     while (current) {
  407.         file << current->data.word << L";" << current->data.definition << endl;
  408.         current = current->next;
  409.     }
  410.     file.close();
  411. }
  412.  
  413. // Delimiter Old Semicolon
  414. void deserializeDictionary(Node*& head, const wstring& filename) {
  415.     wifstream file(filename);
  416.     if (!file.is_open()) {
  417.         MessageBox(NULL, L"Failed to open dictionary file", L"Error", MB_OK | MB_ICONERROR);
  418.         return;
  419.     }
  420.     wstring line;
  421.     while (getline(file, line)) {
  422.         size_t pos = line.find(L';');
  423.         if (pos != wstring::npos) {
  424.             wstring word = line.substr(0, pos);
  425.             wstring definition = line.substr(pos + 1);
  426.             addWord(head, word, definition);
  427.         }
  428.     }
  429.     file.close();
  430. }
  431.  
  432. // Add this function to convert a string to lowercase
  433. wstring toLower(const wstring& str) {
  434.     wstring lower = str;
  435.     transform(lower.begin(), lower.end(), lower.begin(), ::towlower);
  436.     return lower;
  437. }
  438.  
  439. // Modify the searchWordRealtime function to be case-insensitive
  440. void searchWordRealtime(const Node* head, const wstring& keyword, vector<wstring>& suggestions) {
  441.     suggestions.clear();
  442.     const Node* current = head;
  443.     wstring lowercaseKeyword = toLower(keyword);
  444.     while (current) {
  445.         wstring lowercaseWord = toLower(current->data.word);
  446.         if (lowercaseWord.find(lowercaseKeyword) != wstring::npos) {
  447.             suggestions.push_back(current->data.word);
  448.         }
  449.         current = current->next;
  450.     }
  451. }
  452.  
  453. // Prune Functions
  454. int pruneDictionary(Node*& head) {
  455.     if (!head) return 0;
  456.  
  457.     int duplicatesRemoved = 0;
  458.     Node* current = head;
  459.  
  460.     while (current && current->next) {
  461.         Node* runner = current;
  462.         while (runner->next) {
  463.             if (current->data.word == runner->next->data.word) {
  464.                 Node* duplicate = runner->next;
  465.                 runner->next = runner->next->next;
  466.                 delete duplicate;
  467.                 duplicatesRemoved++;
  468.             }
  469.             else {
  470.                 runner = runner->next;
  471.             }
  472.         }
  473.         current = current->next;
  474.     }
  475.  
  476.     return duplicatesRemoved;
  477. }
  478.  
  479. // Prune Functions
  480. void updateDictionaryAfterPrune(Node*& head, vector<wstring>& words, HWND hwnd) {
  481.     listWords(head, words);
  482.     updateListBox(hwnd, words);
  483.     serializeDictionary(head, L"myDictionary99x.txt");
  484. }
  485.  
  486. void updateListBox(HWND hwnd, const vector<wstring>& words) {
  487.     HWND hListBox = GetDlgItem(hwnd, IDC_LISTBOX);
  488.     SendMessage(hListBox, LB_RESETCONTENT, 0, 0);
  489.     for (const auto& word : words) {
  490.         SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)word.c_str());
  491.     }
  492. }
  493.  
  494. void AddWordToList(HWND hwnd) {
  495.     wchar_t word[256], definition[1024];
  496.     GetDlgItemText(hwnd, IDC_WORD_INPUT, word, 256);
  497.     GetDlgItemText(hwnd, IDC_DEFINITION_INPUT, definition, 1024);
  498.     if (wcslen(word) > 0) {
  499.         if (!addWord(dictionary, word, definition)) {
  500.             wstring message = L"An entry with the name '";
  501.             message += word;
  502.             message += L"' already exists. Do you want to add a duplicate entry?";
  503.             int result = MessageBox(hwnd, message.c_str(), L"Confirm Duplicate Entry", MB_YESNO | MB_ICONQUESTION);
  504.  
  505.             if (result == IDYES) {
  506.                 insertNode(dictionary, { word, definition });
  507.             }
  508.         }
  509.         listWords(dictionary, words);
  510.         updateListBox(hwnd, words);
  511.         serializeDictionary(dictionary, L"myDictionary99x.txt");
  512.         SetDlgItemText(hwnd, IDC_WORD_INPUT, L"");
  513.         SetDlgItemText(hwnd, IDC_DEFINITION_INPUT, L"");
  514.     }
  515. }
  516.  
  517. /*LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
  518.     if (nCode == HC_ACTION) {
  519.         KBDLLHOOKSTRUCT* pKbdStruct = (KBDLLHOOKSTRUCT*)lParam;
  520.         if (wParam == WM_KEYDOWN && pKbdStruct->vkCode == VK_RETURN) {
  521.             HWND hFocus = GetFocus();
  522.             if (hFocus == GetDlgItem(g_hDlg, IDC_WORD_INPUT) ||
  523.                 hFocus == GetDlgItem(g_hDlg, IDC_DEFINITION_INPUT)) {
  524.                 AddWordToList(g_hDlg);
  525.                 return 1;  // Prevent further processing of this key
  526.             }
  527.         }
  528.     }
  529.     return CallNextHookEx(g_hHook, nCode, wParam, lParam);
  530. }*/
  531.  
  532.  
  533. //Return this function
  534. /*LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
  535.     if (nCode == HC_ACTION) {
  536.         KBDLLHOOKSTRUCT* pKbdStruct = (KBDLLHOOKSTRUCT*)lParam;
  537.         if (wParam == WM_KEYDOWN) {
  538.             switch (pKbdStruct->vkCode) {
  539.             case VK_RETURN:
  540.                 if (GetFocus() == GetDlgItem(g_hDlg, IDC_WORD_INPUT) ||
  541.                     GetFocus() == GetDlgItem(g_hDlg, IDC_DEFINITION_INPUT)) {
  542.                     AddWordToList(g_hDlg);
  543.                     return 1;
  544.                 }
  545.                 break;
  546.             case VK_ESCAPE:
  547.                 /*if (IsWindowVisible(g_hDlg)) { // Assuming g_hDlg is your dialog handle
  548.                     PostMessage(g_hDlg, WM_COMMAND, IDCANCEL, 0);
  549.                     return 1; // Signal that we've handled this key
  550.                 }
  551.                 // Check for Cancel button                
  552.                 if (GetDlgItem(g_hDlg, IDCANCEL)) {
  553.                     SendMessage(g_hDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0);
  554.                     return TRUE;
  555.                 }
  556.                 // Check for No button
  557.                 else if (GetDlgItem(g_hDlg, IDNO)) {
  558.                     SendMessage(g_hDlg, WM_COMMAND, MAKEWPARAM(IDNO, 0), 0);
  559.                     return TRUE;
  560.                 }
  561.                 // For dialogs with only a close button (like View Definition)
  562.                 else {
  563.                     SendMessage(g_hDlg, WM_CLOSE, 0, 0);
  564.                     return TRUE;
  565.                 }
  566.                 break;
  567.             case VK_F1:
  568.             {
  569.     if (g_hDefinitionDlg && IsWindowVisible(g_hDefinitionDlg)) {
  570.         // If the dialog is visible, hide it
  571.         ShowWindow(g_hDefinitionDlg, SW_HIDE);
  572.         g_hDefinitionDlg = NULL; // Reset since we're hiding it
  573.     } else {
  574.         // If not visible or doesn't exist, show it or create it
  575.         HWND hListBox = GetDlgItem(g_hDlg, IDC_LISTBOX);
  576.         int selectedIndex = SendMessage(hListBox, LB_GETCURSEL, 0, 0);
  577.         if (selectedIndex != LB_ERR) {
  578.             wchar_t selectedWord[256];
  579.             SendMessage(hListBox, LB_GETTEXT, selectedIndex, (LPARAM)selectedWord);
  580.             Node* current = dictionary;
  581.             while (current) {
  582.                 if (current->data.word == selectedWord) {
  583.                     // Here, instead of calling DisplayDefinition directly, we'll manage the dialog
  584.                     if (!g_hDefinitionDlg) {
  585.                         g_hDefinitionDlg = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DEFINITION), g_hDlg, ViewDefinitionDlgProc, (LPARAM)new wstring(current->data.definition));
  586.                         ShowWindow(g_hDefinitionDlg, SW_SHOW);
  587.                     }
  588.                     break;
  589.                 }
  590.                 current = current->next;
  591.             }
  592.         }
  593.     }
  594.     return 1;
  595. }*/
  596.  
  597. /*LRESULT CALLBACK EditSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  598. {
  599.     if (uMsg == WM_KEYDOWN && wParam == VK_RETURN)
  600.     {
  601.         HWND hwndParent = (HWND)GetWindowLongPtr(hWnd, GWLP_USERDATA);
  602.         if (hwndParent)
  603.         {
  604.             HWND hwndAddButton = GetDlgItem(hwndParent, IDC_ADD_WORD);
  605.             if (hwndAddButton)
  606.             {
  607.                 SendMessage(hwndParent, WM_COMMAND, MAKEWPARAM(IDC_ADD_WORD, BN_CLICKED), (LPARAM)hwndAddButton);
  608.                 return 0;
  609.             }
  610.         }
  611.     }
  612.  
  613.     return CallWindowProc((WNDPROC)GetWindowLongPtr(hWnd, GWLP_USERDATA), hWnd, uMsg, wParam, lParam);
  614. }*/
  615.  
  616. /*LRESULT CALLBACK EditSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam,
  617.     LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
  618. {
  619.     if (uMsg == WM_KEYDOWN && wParam == VK_RETURN) {
  620.         HWND hwndParent = (HWND)dwRefData;
  621.         SendMessage(hwndParent, WM_COMMAND, MAKEWPARAM(IDC_ADD_WORD, BN_CLICKED),
  622.             (LPARAM)GetDlgItem(hwndParent, IDC_ADD_WORD));
  623.         return 0;
  624.     }
  625.     return DefSubclassProc(hWnd, uMsg, wParam, lParam);
  626. }*/
  627. /*LRESULT CALLBACK WordEditSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  628.     if (uMsg == WM_KEYDOWN && wParam == VK_RETURN) {
  629.         SendMessage(GetParent(hWnd), WM_COMMAND, MAKEWPARAM(IDC_ADD_WORD, BN_CLICKED), (LPARAM)GetDlgItem(GetParent(hWnd), IDC_ADD_WORD));
  630.         return 0;
  631.     }
  632.     return CallWindowProc(oldWordEditProc, hWnd, uMsg, wParam, lParam);
  633. }
  634.  
  635. LRESULT CALLBACK DefinitionEditSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  636.     if (uMsg == WM_KEYDOWN && wParam == VK_RETURN) {
  637.         SendMessage(GetParent(hWnd), WM_COMMAND, MAKEWPARAM(IDC_ADD_WORD, BN_CLICKED), (LPARAM)GetDlgItem(GetParent(hWnd), IDC_ADD_WORD));
  638.         return 0;
  639.     }
  640.     return CallWindowProc(oldDefinitionEditProc, hWnd, uMsg, wParam, lParam);
  641. }*/            
  642.  
  643. // Dialog procedure
  644. // Modify the DialogProc function
  645. INT_PTR CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  646.     static HWND hFocusedEdit = nullptr; // Define hFocusedEdit here
  647.     static HWND hWordEdit = nullptr;
  648.     static HWND hDefinitionEdit = nullptr;
  649.     switch (uMsg) {
  650.     case WM_INITDIALOG:
  651.     {
  652.         // Load dictionary
  653.         /*wchar_t path[MAX_PATH];
  654.         GetModuleFileName(NULL, path, MAX_PATH);
  655.         wstring exePath(path);
  656.         wstring dirPath = exePath.substr(0, exePath.find_last_of(L"\\/"));
  657.         wstring filePath = dirPath + L"\\myDictionary99x.txt";*/
  658.         // Set both large and small icons
  659.         HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
  660.  
  661.         deserializeDictionary(dictionary, L"myDictionary99x.txt");
  662.         listWords(dictionary, words);
  663.         updateListBox(hwnd, words);
  664.         g_hDlg = hwnd;  // Store the dialog handle globally
  665.         g_hHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), 0);
  666.         //hWordEdit = GetDlgItem(hwnd, IDC_WORD_INPUT);
  667.         //hDefinitionEdit = GetDlgItem(hwnd, IDC_DEFINITION_INPUT);
  668.  
  669.         // Set up subclassing
  670.         /*SetWindowLongPtr(hWordEdit, GWLP_USERDATA, (LONG_PTR)hwnd);
  671.         SetWindowLongPtr(hDefinitionEdit, GWLP_USERDATA, (LONG_PTR)hwnd);
  672.         SetWindowLongPtr(hWordEdit, GWLP_WNDPROC, (LONG_PTR)EditSubclassProc);
  673.         SetWindowLongPtr(hDefinitionEdit, GWLP_WNDPROC, (LONG_PTR)EditSubclassProc);*/
  674.         SetFocus(GetDlgItem(hwnd, IDC_SEARCH_INPUT));  // Set focus to search field
  675.         SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)));
  676.         return TRUE;
  677.     }
  678.  
  679.     case WM_COMMAND:
  680.         // Start Double-Click View ListBox Definitions function block
  681.         switch (HIWORD(wParam)) {
  682.         case LBN_DBLCLK:
  683.             if (LOWORD(wParam) == IDC_LISTBOX) {
  684.                 int index = SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETCURSEL, 0, 0);
  685.                 if (index != LB_ERR) {
  686.                     wchar_t word[256];
  687.                     SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETTEXT, index, (LPARAM)word);
  688.  
  689.                     // Find the definition for the selected word
  690.                     Node* current = dictionary;
  691.                     while (current) {
  692.                         if (current->data.word == word) {
  693.                             DisplayDefinition(hwnd, word, current->data.definition);
  694.                             break;
  695.                         }
  696.                         current = current->next;
  697.                     }
  698.                 }
  699.                 return TRUE;
  700.             }
  701.             //break;
  702.         //}
  703.  
  704.         case EN_SETFOCUS:
  705.             if (LOWORD(wParam) == IDC_WORD_INPUT || LOWORD(wParam) == IDC_DEFINITION_INPUT) {
  706.                 hFocusedEdit = (HWND)lParam;
  707.             }
  708.             break;
  709.         }
  710.  
  711.         // End Double-Click View ListBox Definitions function block
  712.         // Handle other controls
  713.         switch (LOWORD(wParam)) {
  714.         case IDC_ADD_WORD: {
  715.             if (LOWORD(wParam) == IDC_ADD_WORD) {
  716.                 AddWordToList(hwnd);
  717.                 return TRUE;
  718.             }
  719.             else if ((LOWORD(wParam) == IDC_WORD_INPUT || LOWORD(wParam) == IDC_DEFINITION_INPUT) &&
  720.                 HIWORD(wParam) == EN_SETFOCUS) {
  721.                 SetTimer(hwnd, 1, 10, NULL);
  722.                 return TRUE;
  723.             }
  724.             else if ((LOWORD(wParam) == IDC_WORD_INPUT || LOWORD(wParam) == IDC_DEFINITION_INPUT) &&
  725.                 HIWORD(wParam) == EN_KILLFOCUS) {
  726.                 KillTimer(hwnd, 1);
  727.                 return TRUE;
  728.             }
  729.             break;
  730.         }
  731.                          /*wchar_t word[256], definition[1024];
  732.                          GetDlgItemText(hwnd, IDC_WORD_INPUT, word, 256);
  733.                          GetDlgItemText(hwnd, IDC_DEFINITION_INPUT, definition, 1024);
  734.                          if (wcslen(word) > 0) {
  735.                              if (!addWord(dictionary, word, definition)) {
  736.                                  // Word already exists, show confirmation box
  737.                                  wstring message = L"An entry with the name '";
  738.                                  message += word;
  739.                                  message += L"' already exists. Do you want to add a duplicate entry?";
  740.                                  int result = MessageBox(hwnd, message.c_str(), L"Confirm Duplicate Entry", MB_YESNO | MB_ICONQUESTION);
  741.  
  742.                                  if (result == IDYES) {
  743.                                      // User confirmed, add the duplicate entry
  744.                                      insertNode(dictionary, { word, definition });
  745.                                      listWords(dictionary, words);
  746.                                      updateListBox(hwnd, words);
  747.                                      serializeDictionary(dictionary, L"myDictionary99x.txt");
  748.                                      SetDlgItemText(hwnd, IDC_WORD_INPUT, L"");
  749.                                      SetDlgItemText(hwnd, IDC_DEFINITION_INPUT, L"");
  750.                                  }
  751.                                  // If result is IDNO, do nothing (silently ignore)
  752.                              }
  753.                              else {
  754.                                  // Word added successfully
  755.                                  listWords(dictionary, words);
  756.                                  updateListBox(hwnd, words);
  757.                                  serializeDictionary(dictionary, L"myDictionary99x.txt");
  758.                                  SetDlgItemText(hwnd, IDC_WORD_INPUT, L"");
  759.                                  SetDlgItemText(hwnd, IDC_DEFINITION_INPUT, L"");
  760.                              }
  761.                          }
  762.                          return TRUE;
  763.                      }
  764.                  }*/
  765.                  // w/o duplicates
  766.                  /*case IDC_ADD_WORD: {
  767.                      wchar_t word[256], definition[1024];
  768.                      GetDlgItemText(hwnd, IDC_WORD_INPUT, word, 256);
  769.                      GetDlgItemText(hwnd, IDC_DEFINITION_INPUT, definition, 1024);
  770.                      if (wcslen(word) > 0) {
  771.                          if (addWord(dictionary, word, definition)) {
  772.                              listWords(dictionary, words);
  773.                              updateListBox(hwnd, words);
  774.                              serializeDictionary(dictionary, L"myDictionary99x.txt");
  775.                              SetDlgItemText(hwnd, IDC_WORD_INPUT, L"");
  776.                              SetDlgItemText(hwnd, IDC_DEFINITION_INPUT, L"");
  777.                          }
  778.                          // If addWord returns false, it means the word already exists.
  779.                          // We silently ignore it as per the requirement.
  780.                      }
  781.                      return TRUE;
  782.                  }*/
  783.                  // /w duplicates        
  784.                  /*case IDC_ADD_WORD: {
  785.                      wchar_t word[256], definition[1024];
  786.                      GetDlgItemText(hwnd, IDC_WORD_INPUT, word, 256);
  787.                      GetDlgItemText(hwnd, IDC_DEFINITION_INPUT, definition, 1024);
  788.                      if (wcslen(word) > 0) {  // Only check if word is not empty
  789.                          addWord(dictionary, word, definition);
  790.                          listWords(dictionary, words);
  791.                          updateListBox(hwnd, words);
  792.                          serializeDictionary(dictionary, L"myDictionary99x.txt");
  793.                          SetDlgItemText(hwnd, IDC_WORD_INPUT, L"");
  794.                          SetDlgItemText(hwnd, IDC_DEFINITION_INPUT, L"");
  795.                      }
  796.                      return TRUE;
  797.                  }*/
  798.  
  799.         case IDC_DELETE_WORD: {
  800.             int index = SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETCURSEL, 0, 0);
  801.             if (index != LB_ERR) {
  802.                 wchar_t word[256];
  803.                 SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETTEXT, index, (LPARAM)word);
  804.  
  805.                 // Create the confirmation message
  806.                 wstring message = L"Are you sure you want to delete the word '";
  807.                 message += word;
  808.                 message += L"'?";
  809.  
  810.                 // Show the confirmation box
  811.                 int result = MessageBox(hwnd, message.c_str(), L"Confirm Deletion", MB_YESNO | MB_ICONQUESTION);
  812.  
  813.                 // If the user clicks "Yes", proceed with deletion
  814.                 if (result == IDYES) {
  815.                     deleteWord(dictionary, word);
  816.                     listWords(dictionary, words);
  817.                     updateListBox(hwnd, words);
  818.                     serializeDictionary(dictionary, L"myDictionary99x.txt");
  819.                 }
  820.             }
  821.             return TRUE;
  822.         }
  823.  
  824.         case IDC_EDIT_WORD: {
  825.             int index = SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETCURSEL, 0, 0);
  826.             if (index != LB_ERR) {
  827.                 wchar_t wordToEdit[256];
  828.                 SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETTEXT, index, (LPARAM)wordToEdit);
  829.                 Node* current = dictionary;
  830.                 while (current) {
  831.                     if (current->data.word == wordToEdit) {
  832.                         wstring newWord = InputBox(hwnd, L"Edit Word", L"Edit Word", current->data.word);
  833.                         if (!newWord.empty()) {
  834.                             wstring newDefinition = InputBox(hwnd, L"Edit Definition", L"Edit Definition", current->data.definition);
  835.                             // newDefinition can be empty now
  836.                             SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_DELETESTRING, index, 0); // Delete the old word
  837.                             editWord(dictionary, wordToEdit, newWord, newDefinition);
  838.                             listWords(dictionary, words);
  839.                             updateListBox(hwnd, words);
  840.                             // fix for C++ best practices "<" Signed/ Unsigned Mismatch
  841.                             for (size_t i = 0; i < words.size(); i++) {
  842.                                 //for (int i = 0; i < words.size(); i++) {
  843.                                 if (words[i] == newWord) {
  844.                                     SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_SETCURSEL, static_cast<WPARAM>(i), 0); // Select the edited word
  845.                                     // fix for C++ best practices "<" Signed Unsigned Mismatch
  846.                                     //SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_SETCURSEL, i, 0); // Select the edited word
  847.                                     break;
  848.                                 }
  849.                             }
  850.                             serializeDictionary(dictionary, L"myDictionary99x.txt");
  851.                         }
  852.                         break;
  853.                     }
  854.                     current = current->next;
  855.                 }
  856.                 if (!current) {
  857.                     MessageBox(hwnd, L"Word not found in the dictionary.", L"Error", MB_OK | MB_ICONERROR);
  858.                 }
  859.             }
  860.             return TRUE;
  861.         }
  862.                           // /w duplicates (does not affect duplicates tho only no check for blank definitions
  863.                           /*case IDC_EDIT_WORD: {
  864.                               int index = SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETCURSEL, 0, 0);
  865.                               if (index != LB_ERR) {
  866.                                   wchar_t wordToEdit[256];
  867.                                   SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETTEXT, index, (LPARAM)wordToEdit);
  868.                                   Node* current = dictionary;
  869.                                   while (current) {
  870.                                       if (current->data.word == wordToEdit) {
  871.                                           wstring newWord = InputBox(hwnd, L"Edit Word", L"Edit Word", current->data.word);
  872.                                           if (!newWord.empty()) {
  873.                                               wstring newDefinition = InputBox(hwnd, L"Edit Definition", L"Edit Definition", current->data.definition);
  874.                                               SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_DELETESTRING, index, 0); // Delete the old word
  875.                                               editWord(dictionary, wordToEdit, newWord, newDefinition);
  876.                                               listWords(dictionary, words);
  877.                                               updateListBox(hwnd, words);
  878.                                               for (int i = 0; i < words.size(); i++) {
  879.                                                   if (words[i] == newWord) {
  880.                                                       SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_SETCURSEL, i, 0); // Select the edited word
  881.                                                       break;
  882.                                                   }
  883.                                               }
  884.                                               serializeDictionary(dictionary, L"myDictionary99x.txt");
  885.                                           }
  886.                                           break;
  887.                                       }
  888.                                       current = current->next;
  889.                                   }
  890.                                   if (!current) {
  891.                                       MessageBox(hwnd, L"Word not found in the dictionary.", L"Error", MB_OK | MB_ICONERROR);
  892.                                   }
  893.                               }
  894.                               return TRUE;
  895.                           }*/
  896.  
  897.         case IDC_VIEW_DEFINITION: {
  898.             int index = SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETCURSEL, 0, 0);
  899.             if (index != LB_ERR) {
  900.                 wchar_t word[256];
  901.                 SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETTEXT, index, (LPARAM)word);
  902.                 Node* current = dictionary;
  903.                 while (current) {
  904.                     if (current->data.word == word) {
  905.                         DisplayDefinition(hwnd, current->data.word, current->data.definition);
  906.                         break;
  907.                     }
  908.                     current = current->next;
  909.                 }
  910.             }
  911.             return TRUE;
  912.         }
  913.  
  914.         case IDC_SEARCH_INPUT: {
  915.             if (HIWORD(wParam) == EN_CHANGE) {
  916.                 wchar_t query[256];
  917.                 GetDlgItemText(hwnd, IDC_SEARCH_INPUT, query, 256);
  918.                 if (wcslen(query) == 0) {
  919.                     updateListBox(hwnd, words);
  920.                 }
  921.                 else {
  922.                     vector<wstring> suggestions;
  923.                     searchWordRealtime(dictionary, query, suggestions);
  924.                     updateListBox(hwnd, suggestions);
  925.                 }
  926.             }
  927.             return TRUE;
  928.         }
  929.  
  930.         case IDC_CLEAR_SEARCH: {
  931.             SetDlgItemText(hwnd, IDC_SEARCH_INPUT, L"");
  932.             updateListBox(hwnd, words);
  933.             return TRUE;
  934.         }
  935.  
  936.                              //Prune Functions
  937.         case IDC_PRUNE: {
  938.             int result = MessageBox(hwnd, L"Are you sure you want to prune the list and remove duplicates?", L"Confirm Prune", MB_YESNO | MB_ICONQUESTION);
  939.             if (result == IDYES) {
  940.                 int duplicatesRemoved = pruneDictionary(dictionary);
  941.                 updateDictionaryAfterPrune(dictionary, words, hwnd);
  942.  
  943.                 wstring message = L"Pruning complete. ";
  944.                 message += to_wstring(duplicatesRemoved);
  945.                 message += L" duplicate entries were removed.";
  946.                 MessageBox(hwnd, message.c_str(), L"Prune Results", MB_OK | MB_ICONINFORMATION);
  947.             }
  948.             return TRUE;
  949.         }
  950.  
  951.         case WM_TIMER:
  952.             if (wParam == 1) {
  953.                 if (GetAsyncKeyState(VK_RETURN) & 0x8000) {
  954.                     AddWordToList(hwnd);
  955.                     KillTimer(hwnd, 1);
  956.                     SetTimer(hwnd, 1, 10, NULL);  // Restart the timer
  957.                 }
  958.             }
  959.             break;
  960.             /*case IDC_WORD_INPUT:
  961.             case IDC_DEFINITION_INPUT:
  962.                 if (HIWORD(wParam) == EN_SETFOCUS) {
  963.                     hFocusedEdit = (HWND)lParam;
  964.                 }
  965.                 break;
  966.                 //}
  967.                 //break;
  968.  
  969.                     case WM_KEYDOWN:
  970.                 if (wParam == VK_RETURN) {
  971.                     HWND focusedControl = GetFocus();
  972.                     if (focusedControl == hWordEdit || focusedControl == hDefinitionEdit) {
  973.                         SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDC_ADD_WORD, BN_CLICKED), 0);
  974.                         return TRUE;
  975.                     }
  976.                 }
  977.                 break;*/
  978.  
  979.         case IDCANCEL:
  980.             DestroyWindow(hwnd);
  981.             PostQuitMessage(0);
  982.             return TRUE;
  983.         }
  984.         break;
  985.  
  986.     /*case WM_KEYDOWN:
  987.         if (wParam == VK_ESCAPE) {
  988.             // Check for Cancel button
  989.             if (GetDlgItem(hwnd, IDCANCEL)) {
  990.                 SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0);
  991.                 return TRUE;
  992.             }
  993.             // Check for No button
  994.             else if (GetDlgItem(hwnd, IDNO)) {
  995.                 SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDNO, 0), 0);
  996.                 return TRUE;
  997.             }
  998.             // For dialogs with only a close button (like View Definition)
  999.             else {
  1000.                 SendMessage(hwnd, WM_CLOSE, 0, 0);
  1001.                 return TRUE;
  1002.             }
  1003.         } */
  1004.         //break; //this block was already commentedout break+if->break
  1005.         /*if (wParam == VK_ESCAPE) {
  1006.             if (GetDlgItem(hwnd, IDCANCEL)) {
  1007.             SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0);
  1008.             return TRUE;
  1009.         }
  1010.     }
  1011.         break;*/
  1012.         /*if (wParam == VK_F1) {
  1013.             HWND hListBox = GetDlgItem(hwnd, IDC_LISTBOX);
  1014.             int selectedIndex = SendMessage(hListBox, LB_GETCURSEL, 0, 0);
  1015.             if (selectedIndex != LB_ERR) {
  1016.                 wchar_t selectedWord[256];
  1017.                 SendMessage(hListBox, LB_GETTEXT, selectedIndex, (LPARAM)selectedWord);
  1018.                 Node* current = dictionary;
  1019.                 while (current) {
  1020.                     if (current->data.word == selectedWord) {
  1021.                         DisplayDefinition(hwnd, current->data.word, current->data.definition);
  1022.                         break;
  1023.                     }
  1024.                     current = current->next;
  1025.                 }
  1026.             }
  1027.             return TRUE;
  1028.         }
  1029.         break; */
  1030.     case WM_KEYDOWN:
  1031.         if (wParam == VK_ESCAPE) {
  1032.             // Check for Cancel button
  1033.             if (GetDlgItem(hwnd, IDCANCEL)) {
  1034.                 SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0);
  1035.                 return TRUE;
  1036.             }
  1037.             // Check for No button
  1038.             else if (GetDlgItem(hwnd, IDNO)) {
  1039.                 SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDNO, 0), 0);
  1040.                 return TRUE;
  1041.             }
  1042.             // For dialogs with only a close button (like View Definition)
  1043.             else {
  1044.                 SendMessage(hwnd, WM_CLOSE, 0, 0);
  1045.                 return TRUE;
  1046.             }
  1047.         }
  1048.         if (wParam == VK_F1) {
  1049.             HWND hListBox = GetDlgItem(hwnd, IDC_LISTBOX);
  1050.             int selectedIndex = SendMessage(hListBox, LB_GETCURSEL, 0, 0);
  1051.             if (selectedIndex != LB_ERR) {
  1052.                 wchar_t selectedWord[256];
  1053.                 SendMessage(hListBox, LB_GETTEXT, selectedIndex, (LPARAM)selectedWord);
  1054.                 Node* current = dictionary;
  1055.                 while (current) {
  1056.                     if (current->data.word == selectedWord) {
  1057.                         DisplayDefinition(hwnd, current->data.word, current->data.definition);
  1058.                         break;
  1059.                     }
  1060.                     current = current->next;
  1061.                 }
  1062.             }
  1063.             return TRUE;
  1064.         }
  1065.         if (wParam == VK_F2) {
  1066.             HWND hListBox = GetDlgItem(hwnd, IDC_LISTBOX);
  1067.             int selectedIndex = SendMessage(hListBox, LB_GETCURSEL, 0, 0);
  1068.             if (selectedIndex != LB_ERR) {
  1069.                 // Simulate clicking the "Edit Word" button
  1070.                 SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDC_EDIT_WORD, BN_CLICKED), 0);
  1071.             }
  1072.             return TRUE;
  1073.         }
  1074.         break;
  1075.  
  1076.     case WM_GETDLGCODE:
  1077.         if (wParam == VK_ESCAPE) {
  1078.             return DLGC_WANTALLKEYS;
  1079.         }
  1080.         if (wParam == VK_F1) {
  1081.             return DLGC_WANTALLKEYS | DLGC_WANTCHARS;
  1082.         }
  1083.         break;
  1084.  
  1085.     case WM_SHOWWINDOW:
  1086.         if (wParam == TRUE) {  // Only set focus when the window is shown
  1087.             SetFocus(GetDlgItem(hwnd, IDC_SEARCH_INPUT));
  1088.         }
  1089.         return 0;
  1090.  
  1091.     /*case WM_DESTROY:
  1092.         // In your cleanup or WM_DESTROY handling
  1093.         UnhookWindowsHookEx(g_hHook);
  1094.         DestroyWindow(hwnd);
  1095.         PostQuitMessage(0);*/
  1096.  
  1097.     case WM_CLOSE:
  1098.         if (g_hHook) {
  1099.             UnhookWindowsHookEx(g_hHook);
  1100.         }
  1101.         DestroyWindow(hwnd);
  1102.         PostQuitMessage(0);
  1103.         return TRUE;
  1104.     }
  1105.    
  1106.     return FALSE;
  1107. }
  1108.  
  1109. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
  1110.     HWND hDlg = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_MAINDIALOG), 0, DialogProc, 0);
  1111.     if (!hDlg) {
  1112.         MessageBox(NULL, L"Failed to create dialog", L"Error", MB_ICONERROR | MB_OK);
  1113.         return 1;
  1114.     }
  1115.  
  1116.     // Retrieve screen dimensions
  1117.     RECT desktop;
  1118.     const HWND hDesktop = GetDesktopWindow();
  1119.     GetWindowRect(hDesktop, &desktop);
  1120.  
  1121.     // Retrieve window dimensions
  1122.     RECT windowRect;
  1123.     GetWindowRect(hDlg, &windowRect);
  1124.     int windowWidth = windowRect.right - windowRect.left;
  1125.     int windowHeight = windowRect.bottom - windowRect.top;
  1126.  
  1127.     // Calculate position to center the window
  1128.     int posX = (desktop.right / 2) - (windowWidth / 2);
  1129.     int posY = (desktop.bottom / 2) - (windowHeight / 2);
  1130.  
  1131.     // Set window position
  1132.     SetWindowPos(hDlg, NULL, posX, posY, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  1133.  
  1134.     ShowWindow(hDlg, nCmdShow);
  1135.  
  1136.     MSG msg;
  1137.     BOOL bRet;
  1138.     while ((bRet = GetMessage(&msg, nullptr, 0, 0)) != 0) {
  1139.         if (bRet == -1) {
  1140.             // Handle the error and possibly exit
  1141.             break;
  1142.         }
  1143.         else if (!IsWindow(hDlg) || !IsDialogMessage(hDlg, &msg)) {
  1144.             TranslateMessage(&msg);
  1145.             DispatchMessage(&msg);
  1146.         }
  1147.     }
  1148.  
  1149.     return (int)msg.wParam;
  1150. }
  1151. ```
  1152.  
  1153. ==++ Here's the full source code for (file 2/4) "Resource2.rc"::: ++==
  1154. ```Resource2.rc
  1155. #include <windows.h>
  1156. #include "resource2.h"
  1157.  
  1158. IDD_MAINDIALOG DIALOGEX 0, 0, 320, 240
  1159. STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
  1160. CAPTION "Dictionary Application (F1=QuickViewToggle F2=EditWord F9About)"
  1161. FONT 8, "MS Shell Dlg", 400, 0, 0x1
  1162. BEGIN
  1163. LTEXT           "Word:", -1, 10, 10, 30, 8
  1164. EDITTEXT        IDC_WORD_INPUT, 50, 8, 100, 14, ES_AUTOHSCROLL | WS_TABSTOP
  1165. LTEXT           "Definition:", -1, 10, 30, 40, 8
  1166. EDITTEXT        IDC_DEFINITION_INPUT, 50, 28, 200, 14, ES_AUTOHSCROLL | WS_TABSTOP
  1167. PUSHBUTTON      "Add Word", IDC_ADD_WORD, 260, 8, 50, 14
  1168. PUSHBUTTON      "Delete Word", IDC_DELETE_WORD, 260, 28, 50, 14
  1169. PUSHBUTTON      "Edit Word", IDC_EDIT_WORD, 260, 48, 50, 14
  1170. PUSHBUTTON      "View Definition", IDC_VIEW_DEFINITION, 205, 8, 55, 14
  1171. PUSHBUTTON      "Prune", IDC_PRUNE, 160, 8, 25, 14
  1172. PUSHBUTTON      "Clear", IDC_CLEAR_SEARCH, 185, 8, 20, 14
  1173. LTEXT           "Search:", -1, 10, 50, 30, 8
  1174. EDITTEXT        IDC_SEARCH_INPUT, 50, 48, 200, 14, ES_AUTOHSCROLL
  1175. LISTBOX         IDC_LISTBOX, 10, 70, 300, 160, LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL
  1176. END
  1177.  
  1178. IDD_INPUT DIALOGEX 0, 0, 250, 120
  1179. STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
  1180. CAPTION "Input"
  1181. FONT 8, "MS Shell Dlg", 400, 0, 0x1
  1182. BEGIN
  1183. LTEXT           "Input:", -1, 7, 14, 50, 8
  1184. EDITTEXT        IDC_INPUT, 7, 30, 230, 65, ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL
  1185. DEFPUSHBUTTON   "OK", IDOK, 70, 100, 50, 14
  1186. PUSHBUTTON      "Cancel", IDCANCEL, 130, 100, 50, 14
  1187. END
  1188. //20->65 (EditText last value), 60->100 (DefPushButton second value), 60->100 (PushButton second value) Only ES_AUTOHSCROLL (in EditText)
  1189.  
  1190. IDD_DEFINITION DIALOGEX 0, 0, 300, 200
  1191. STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
  1192. CAPTION "Definition"
  1193. FONT 8, "MS Shell Dlg"
  1194. BEGIN
  1195. EDITTEXT        IDC_DEFINITION_EDIT, 7, 7, 286, 186, ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | WS_VSCROLL
  1196. END
  1197.  
  1198. /*IDD_INPUT DIALOGEX 0, 0, 200, 100
  1199. STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
  1200. CAPTION "Input"
  1201. FONT 8, "MS Shell Dlg"
  1202. BEGIN
  1203. LTEXT           "Input:", -1, 7, 14, 50, 8
  1204. EDITTEXT        IDC_INPUT, 7, 24, 186, 12, ES_AUTOHSCROLL
  1205. DEFPUSHBUTTON   "OK", IDOK, 139, 7, 50, 14
  1206. PUSHBUTTON      "Cancel", IDCANCEL, 139, 24, 50, 14
  1207. END*/
  1208.  
  1209. //EDITTEXT        IDC_WORD_INPUT, 50, 8, 100, 14, ES_AUTOHSCROLL
  1210. //PUSHBUTTON      "Add Word", IDC_ADD_WORD, 260, 8, 50, 14
  1211. //PUSHBUTTON      "View Definition", IDC_VIEW_DEFINITION, 260, 68, 50, 14
  1212. ```
  1213.  
  1214. ==++ Here's the full source code for (file 3/4) "resource2.h"::: ++==
  1215. ```resource2.h
  1216. #ifndef RESOURCE2_H
  1217. #define RESOURCE2_H
  1218.  
  1219. #define IDD_MAINDIALOG                  101
  1220. #define IDC_WORD_INPUT                  1001
  1221. #define IDC_DEFINITION_INPUT            1002
  1222. #define IDC_ADD_WORD                    1003
  1223. #define IDC_DELETE_WORD                 1004
  1224. #define IDC_SEARCH_INPUT                1005
  1225. #define IDC_LISTBOX                     1006
  1226. #define IDC_INPUT                       1007  // Add this line if you're using IDC_INPUT
  1227. #define IDC_EDIT_WORD                   1008
  1228. #define IDC_VIEW_DEFINITION             1009
  1229. #define IDD_INPUT                       1010
  1230. #define IDD_DEFINITION                  1011
  1231. #define IDC_DEFINITION_EDIT             1012
  1232. #define IDC_CLEAR_SEARCH                1013
  1233. #define IDC_PRUNE                       1014
  1234.  
  1235. #endif // RESOURCE2_H
  1236.  
  1237. ```
  1238.  
  1239. ==++ Here's the full source code for (file 4/4) "resource.h"::: ++==
  1240. ```resource.h
  1241. //{{NO_DEPENDENCIES}}
  1242. // Microsoft Visual C++ generated include file.
  1243. // Used by Dictionary-win32.rc
  1244. //
  1245. #define IDI_ICON1                       101
  1246.  
  1247. // Next default values for new objects
  1248. //
  1249. #ifdef APSTUDIO_INVOKED
  1250. #ifndef APSTUDIO_READONLY_SYMBOLS
  1251. #define _APS_NEXT_RESOURCE_VALUE        102
  1252. #define _APS_NEXT_COMMAND_VALUE         40001
  1253. #define _APS_NEXT_CONTROL_VALUE         1001
  1254. #define _APS_NEXT_SYMED_VALUE           101
  1255. #endif
  1256. #endif
  1257.  
  1258. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement