Advertisement
alien_fx_fiend

Dictionary GUI-Based Win32 (Now /w Prune!!!) (*THE END*) FIXED

Jul 30th, 2024 (edited)
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 25.17 KB | None | 0 0
  1. realtime-search.cpp file::
  2. #include <Windows.h>
  3. #include <fstream>
  4. #include <sstream>
  5. #include <string>
  6. #include <algorithm>
  7. #include <vector>
  8. #include "resource2.h"
  9.  
  10. using namespace std;
  11.  
  12. // Structure to represent a dictionary entry
  13. struct DictionaryEntry {
  14.     wstring word;
  15.     wstring definition;
  16. };
  17.  
  18. // Structure to represent a node in the linked list
  19. struct Node {
  20.     DictionaryEntry data;
  21.     Node* next;
  22. };
  23.  
  24. Node* dictionary = nullptr;
  25. vector<wstring> words;
  26.  
  27. // Function prototypes
  28. void insertNode(Node*& head, const DictionaryEntry& entry);
  29. //void addWord(Node*& head, const wstring& word, const wstring& definition);
  30. bool addWord(Node*& head, const wstring& word, const wstring& definition);
  31. void deleteWord(Node*& head, const wstring& keyword);
  32. wstring InputBox(HWND hwnd, const wstring& prompt, const wstring& title);
  33. void DisplayDefinition(HWND hwnd, const wstring& word, const wstring& definition);
  34. void editWord(Node* head, const wstring& oldWord, const wstring& newWord, const wstring& newDefinition);
  35. void listWords(const Node* head, vector<wstring>& words);
  36. void serializeDictionary(const Node* head, const wstring& filename);
  37. void deserializeDictionary(Node*& head, const wstring& filename);
  38. void searchWordRealtime(const Node* head, const wstring& keyword, vector<wstring>& suggestions);
  39. int pruneDictionary(Node*& head);
  40. void updateDictionaryAfterPrune(Node*& head, vector<wstring>& words, HWND hwnd);
  41. void updateListBox(HWND hwnd, const vector<wstring>& words);
  42.  
  43. // Function implementations
  44. void insertNode(Node*& head, const DictionaryEntry& entry) {
  45.     Node* newNode = new Node{ entry, nullptr };
  46.     if (!head) {
  47.         head = newNode;
  48.     }
  49.     else {
  50.         Node* current = head;
  51.         while (current->next) {
  52.             current = current->next;
  53.         }
  54.         current->next = newNode;
  55.     }
  56. }
  57.  
  58. bool addWord(Node*& head, const wstring& word, const wstring& definition) {
  59.     // Check if the word already exists
  60.     Node* current = head;
  61.     while (current) {
  62.         if (current->data.word == word) {
  63.             return false; // Word already exists, don't add
  64.         }
  65.         current = current->next;
  66.     }
  67.  
  68.     // Word doesn't exist, add it
  69.     insertNode(head, { word, definition });
  70.     return true;
  71. }
  72. // w/o duplicates
  73. /* // Modify the addWord function to check for duplicates
  74. bool addWord(Node*& head, const wstring& word, const wstring& definition) {
  75.     // Check if the word already exists
  76.     Node* current = head;
  77.     while (current) {
  78.         if (current->data.word == word) {
  79.             return false; // Word already exists, don't add
  80.         }
  81.         current = current->next;
  82.     }
  83.  
  84.     // Word doesn't exist, add it
  85.     insertNode(head, { word, definition });
  86.     return true;
  87. }*/
  88. // /w duplicates
  89. /*void addWord(Node*& head, const wstring& word, const wstring& definition) {
  90.     insertNode(head, { word, definition });
  91. }*/
  92.  
  93. void deleteWord(Node*& head, const wstring& keyword) {
  94.     if (!head) return;
  95.  
  96.     if (head->data.word == keyword) {
  97.         Node* temp = head;
  98.         head = head->next;
  99.         delete temp;
  100.         return;
  101.     }
  102.  
  103.     Node* current = head;
  104.     while (current->next && current->next->data.word != keyword) {
  105.         current = current->next;
  106.     }
  107.  
  108.     if (current->next) {
  109.         Node* temp = current->next;
  110.         current->next = current->next->next;
  111.         delete temp;
  112.     }
  113. }
  114.  
  115. // Modify the InputBox function to pre-populate the input
  116. wstring InputBox(HWND hwnd, const wstring& prompt, const wstring& title, const wstring& defaultValue = L"") {
  117.     wstring input = defaultValue;
  118.     DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_INPUT), hwnd,
  119.         [](HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -> INT_PTR {
  120.             static wstring* pInput;
  121.             switch (message) {
  122.             case WM_INITDIALOG:
  123.                 pInput = (wstring*)lParam;
  124.                 SetDlgItemText(hDlg, IDC_INPUT, pInput->c_str());
  125.                 SendDlgItemMessage(hDlg, IDC_INPUT, EM_SETSEL, 0, -1);  // Select all text
  126.                 return (INT_PTR)TRUE;
  127.             case WM_COMMAND:
  128.                 if (LOWORD(wParam) == IDOK) {
  129.                     HWND hEdit = GetDlgItem(hDlg, IDC_INPUT);
  130.                     int len = GetWindowTextLength(hEdit) + 1;
  131.                     wchar_t* buffer = new wchar_t[len];
  132.                     GetWindowText(hEdit, buffer, len);
  133.                     *pInput = buffer;
  134.                     delete[] buffer;
  135.                     EndDialog(hDlg, IDOK);
  136.                     return (INT_PTR)TRUE;
  137.                 }
  138.                 else if (LOWORD(wParam) == IDCANCEL) {
  139.                     EndDialog(hDlg, IDCANCEL);
  140.                     return (INT_PTR)TRUE;
  141.                 }
  142.                 break;
  143.             }
  144.             return (INT_PTR)FALSE;
  145.         }, (LPARAM)&input);
  146.     return input;
  147. }
  148. /*wstring InputBox(HWND hwnd, const wstring& prompt, const wstring& title) {
  149.     wchar_t input[156] = L"";
  150.     if (DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_INPUT), hwnd,
  151.         [](HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -> INT_PTR {
  152.             static wchar_t input[156];
  153.             switch (message) {
  154.             case WM_INITDIALOG: {
  155.                 HWND hEdit = GetDlgItem(hDlg, IDC_INPUT);
  156.                 SetWindowText(hEdit, (LPCWSTR)lParam);
  157.                 SendMessage(hEdit, EM_SETSEL, 0, -1); // Select all text
  158.                 break;
  159.             }
  160.             case WM_COMMAND:
  161.                 if (LOWORD(wParam) == IDOK) {
  162.                     GetDlgItemText(hDlg, IDC_INPUT, input, 156);
  163.                     EndDialog(hDlg, IDOK);
  164.                     return (INT_PTR)TRUE;
  165.                 }
  166.                 else if (LOWORD(wParam) == IDCANCEL) {
  167.                     EndDialog(hDlg, IDCANCEL);
  168.                     return (INT_PTR)TRUE;
  169.                 }
  170.                 break;
  171.             }
  172.             return (INT_PTR)FALSE;
  173.         }, (LPARAM)prompt.c_str()) == IDOK) {
  174.         return (wstring)input;
  175.     }
  176.     return L"";
  177. }*/
  178.  
  179. void DisplayDefinition(HWND hwnd, const wstring& word, const wstring& definition) {
  180.     wstring message = L"Definition of '" + word + L"':\n\n" + definition;
  181.     HWND hDlg = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DEFINITION), hwnd, [](HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -> INT_PTR {
  182.         switch (message) {
  183.         case WM_INITDIALOG:
  184.         {
  185.             wstring* definition = (wstring*)lParam;
  186.             SetDlgItemText(hDlg, IDC_DEFINITION_EDIT, definition->c_str());
  187.             delete definition;
  188.         }
  189.         return (INT_PTR)TRUE;
  190.         case WM_COMMAND:
  191.             if (LOWORD(wParam) == IDCANCEL) {
  192.                 EndDialog(hDlg, LOWORD(wParam));
  193.                 return (INT_PTR)TRUE;
  194.             }
  195.             break;
  196.         case WM_CLOSE:
  197.             EndDialog(hDlg, 0);
  198.             return (INT_PTR)TRUE;
  199.         }
  200.         return (INT_PTR)FALSE;
  201.         }, (LPARAM)new wstring(message));
  202.     ShowWindow(hDlg, SW_SHOW);
  203. }
  204. /*void DisplayDefinition(HWND hwnd, const wstring& word, const wstring& definition) {
  205.     wstring message = L"Definition of '" + word + L"':\n\n" + definition;
  206.     MessageBox(hwnd, message.c_str(), L"Word Definition", MB_OK | MB_ICONINFORMATION);
  207. }*/
  208.  
  209. void editWord(Node* head, const wstring& oldWord, const wstring& newWord, const wstring& newDefinition) {
  210.     Node* current = head;
  211.     while (current) {
  212.         if (current->data.word == oldWord) {
  213.             current->data.word = newWord;
  214.             current->data.definition = newDefinition;
  215.             return;
  216.         }
  217.         current = current->next;
  218.     }
  219. }
  220.  
  221. void listWords(const Node* head, vector<wstring>& words) {
  222.     words.clear();
  223.     const Node* current = head;
  224.     while (current) {
  225.         words.push_back(current->data.word);
  226.         current = current->next;
  227.     }
  228. }
  229.  
  230. void serializeDictionary(const Node* head, const wstring& filename) {
  231.     wofstream file(filename);
  232.     const Node* current = head;
  233.     while (current) {
  234.         file << current->data.word << L";" << current->data.definition << endl;
  235.         current = current->next;
  236.     }
  237.     file.close();
  238. }
  239.  
  240. void deserializeDictionary(Node*& head, const wstring& filename) {
  241.     wifstream file(filename);
  242.     wstring line;
  243.     while (getline(file, line)) {
  244.         size_t pos = line.find(L';');
  245.         if (pos != wstring::npos) {
  246.             wstring word = line.substr(0, pos);
  247.             wstring definition = line.substr(pos + 1);
  248.             addWord(head, word, definition);
  249.         }
  250.     }
  251.     file.close();
  252. }
  253.  
  254. // Add this function to convert a string to lowercase
  255. wstring toLower(const wstring& str) {
  256.     wstring lower = str;
  257.     transform(lower.begin(), lower.end(), lower.begin(), ::towlower);
  258.     return lower;
  259. }
  260.  
  261. // Modify the searchWordRealtime function to be case-insensitive
  262. void searchWordRealtime(const Node* head, const wstring& keyword, vector<wstring>& suggestions) {
  263.     suggestions.clear();
  264.     const Node* current = head;
  265.     wstring lowercaseKeyword = toLower(keyword);
  266.     while (current) {
  267.         wstring lowercaseWord = toLower(current->data.word);
  268.         if (lowercaseWord.find(lowercaseKeyword) != wstring::npos) {
  269.             suggestions.push_back(current->data.word);
  270.         }
  271.         current = current->next;
  272.     }
  273. }
  274.  
  275. // Prune Functions
  276. int pruneDictionary(Node*& head) {
  277.     if (!head) return 0;
  278.  
  279.     int duplicatesRemoved = 0;
  280.     Node* current = head;
  281.  
  282.     while (current && current->next) {
  283.         Node* runner = current;
  284.         while (runner->next) {
  285.             if (current->data.word == runner->next->data.word) {
  286.                 Node* duplicate = runner->next;
  287.                 runner->next = runner->next->next;
  288.                 delete duplicate;
  289.                 duplicatesRemoved++;
  290.             }
  291.             else {
  292.                 runner = runner->next;
  293.             }
  294.         }
  295.         current = current->next;
  296.     }
  297.  
  298.     return duplicatesRemoved;
  299. }
  300.  
  301. // Prune Functions
  302. void updateDictionaryAfterPrune(Node*& head, vector<wstring>& words, HWND hwnd) {
  303.     listWords(head, words);
  304.     updateListBox(hwnd, words);
  305.     serializeDictionary(head, L"dictionary.txt");
  306. }
  307.  
  308. void updateListBox(HWND hwnd, const vector<wstring>& words) {
  309.     HWND hListBox = GetDlgItem(hwnd, IDC_LISTBOX);
  310.     SendMessage(hListBox, LB_RESETCONTENT, 0, 0);
  311.     for (const auto& word : words) {
  312.         SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)word.c_str());
  313.     }
  314. }
  315.  
  316. // Dialog procedure
  317. // Modify the DialogProc function
  318. INT_PTR CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  319.     switch (uMsg) {
  320.     case WM_INITDIALOG:
  321.         deserializeDictionary(dictionary, L"dictionary.txt");
  322.         listWords(dictionary, words);
  323.         updateListBox(hwnd, words);
  324.         return TRUE;
  325.  
  326.     case WM_COMMAND:
  327.         switch (LOWORD(wParam)) {
  328.         case IDC_ADD_WORD: {
  329.             wchar_t word[256], definition[1024];
  330.             GetDlgItemText(hwnd, IDC_WORD_INPUT, word, 256);
  331.             GetDlgItemText(hwnd, IDC_DEFINITION_INPUT, definition, 1024);
  332.             if (wcslen(word) > 0) {
  333.                 if (!addWord(dictionary, word, definition)) {
  334.                     // Word already exists, show confirmation box
  335.                     wstring message = L"An entry with the name '";
  336.                     message += word;
  337.                     message += L"' already exists. Do you want to add a duplicate entry?";
  338.                     int result = MessageBox(hwnd, message.c_str(), L"Confirm Duplicate Entry", MB_YESNO | MB_ICONQUESTION);
  339.  
  340.                     if (result == IDYES) {
  341.                         // User confirmed, add the duplicate entry
  342.                         insertNode(dictionary, { word, definition });
  343.                         listWords(dictionary, words);
  344.                         updateListBox(hwnd, words);
  345.                         serializeDictionary(dictionary, L"dictionary.txt");
  346.                         SetDlgItemText(hwnd, IDC_WORD_INPUT, L"");
  347.                         SetDlgItemText(hwnd, IDC_DEFINITION_INPUT, L"");
  348.                     }
  349.                     // If result is IDNO, do nothing (silently ignore)
  350.                 }
  351.                 else {
  352.                     // Word added successfully
  353.                     listWords(dictionary, words);
  354.                     updateListBox(hwnd, words);
  355.                     serializeDictionary(dictionary, L"dictionary.txt");
  356.                     SetDlgItemText(hwnd, IDC_WORD_INPUT, L"");
  357.                     SetDlgItemText(hwnd, IDC_DEFINITION_INPUT, L"");
  358.                 }
  359.             }
  360.             return TRUE;
  361.         }
  362.         // w/o duplicates
  363.         /*case IDC_ADD_WORD: {
  364.             wchar_t word[256], definition[1024];
  365.             GetDlgItemText(hwnd, IDC_WORD_INPUT, word, 256);
  366.             GetDlgItemText(hwnd, IDC_DEFINITION_INPUT, definition, 1024);
  367.             if (wcslen(word) > 0) {
  368.                 if (addWord(dictionary, word, definition)) {
  369.                     listWords(dictionary, words);
  370.                     updateListBox(hwnd, words);
  371.                     serializeDictionary(dictionary, L"dictionary.txt");
  372.                     SetDlgItemText(hwnd, IDC_WORD_INPUT, L"");
  373.                     SetDlgItemText(hwnd, IDC_DEFINITION_INPUT, L"");
  374.                 }
  375.                 // If addWord returns false, it means the word already exists.
  376.                 // We silently ignore it as per the requirement.
  377.             }
  378.             return TRUE;
  379.         }*/
  380.         // /w duplicates        
  381.         /*case IDC_ADD_WORD: {
  382.             wchar_t word[256], definition[1024];
  383.             GetDlgItemText(hwnd, IDC_WORD_INPUT, word, 256);
  384.             GetDlgItemText(hwnd, IDC_DEFINITION_INPUT, definition, 1024);
  385.             if (wcslen(word) > 0) {  // Only check if word is not empty
  386.                 addWord(dictionary, word, definition);
  387.                 listWords(dictionary, words);
  388.                 updateListBox(hwnd, words);
  389.                 serializeDictionary(dictionary, L"dictionary.txt");
  390.                 SetDlgItemText(hwnd, IDC_WORD_INPUT, L"");
  391.                 SetDlgItemText(hwnd, IDC_DEFINITION_INPUT, L"");
  392.             }
  393.             return TRUE;
  394.         }*/
  395.  
  396.         case IDC_DELETE_WORD: {
  397.             int index = SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETCURSEL, 0, 0);
  398.             if (index != LB_ERR) {
  399.                 wchar_t word[256];
  400.                 SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETTEXT, index, (LPARAM)word);
  401.  
  402.                 // Create the confirmation message
  403.                 wstring message = L"Are you sure you want to delete the word '";
  404.                 message += word;
  405.                 message += L"'?";
  406.  
  407.                 // Show the confirmation box
  408.                 int result = MessageBox(hwnd, message.c_str(), L"Confirm Deletion", MB_YESNO | MB_ICONQUESTION);
  409.  
  410.                 // If the user clicks "Yes", proceed with deletion
  411.                 if (result == IDYES) {
  412.                     deleteWord(dictionary, word);
  413.                     listWords(dictionary, words);
  414.                     updateListBox(hwnd, words);
  415.                     serializeDictionary(dictionary, L"dictionary.txt");
  416.                 }
  417.             }
  418.             return TRUE;
  419.         }
  420.  
  421.         case IDC_EDIT_WORD: {
  422.             int index = SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETCURSEL, 0, 0);
  423.             if (index != LB_ERR) {
  424.                 wchar_t wordToEdit[256];
  425.                 SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETTEXT, index, (LPARAM)wordToEdit);
  426.                 Node* current = dictionary;
  427.                 while (current) {
  428.                     if (current->data.word == wordToEdit) {
  429.                         wstring newWord = InputBox(hwnd, L"Edit Word", L"Edit Word", current->data.word);
  430.                         if (!newWord.empty()) {
  431.                             wstring newDefinition = InputBox(hwnd, L"Edit Definition", L"Edit Definition", current->data.definition);
  432.                             // newDefinition can be empty now
  433.                             SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_DELETESTRING, index, 0); // Delete the old word
  434.                             editWord(dictionary, wordToEdit, newWord, newDefinition);
  435.                             listWords(dictionary, words);
  436.                             updateListBox(hwnd, words);
  437.                             for (int i = 0; i < words.size(); i++) {
  438.                                 if (words[i] == newWord) {
  439.                                     SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_SETCURSEL, i, 0); // Select the edited word
  440.                                     break;
  441.                                 }
  442.                             }
  443.                             serializeDictionary(dictionary, L"dictionary.txt");
  444.                         }
  445.                         break;
  446.                     }
  447.                     current = current->next;
  448.                 }
  449.                 if (!current) {
  450.                     MessageBox(hwnd, L"Word not found in the dictionary.", L"Error", MB_OK | MB_ICONERROR);
  451.                 }
  452.             }
  453.             return TRUE;
  454.         }
  455.         // /w duplicates (does not affect duplicates tho only no check for blank definitions
  456.         /*case IDC_EDIT_WORD: {
  457.             int index = SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETCURSEL, 0, 0);
  458.             if (index != LB_ERR) {
  459.                 wchar_t wordToEdit[256];
  460.                 SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETTEXT, index, (LPARAM)wordToEdit);
  461.                 Node* current = dictionary;
  462.                 while (current) {
  463.                     if (current->data.word == wordToEdit) {
  464.                         wstring newWord = InputBox(hwnd, L"Edit Word", L"Edit Word", current->data.word);
  465.                         if (!newWord.empty()) {
  466.                             wstring newDefinition = InputBox(hwnd, L"Edit Definition", L"Edit Definition", current->data.definition);
  467.                             SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_DELETESTRING, index, 0); // Delete the old word
  468.                             editWord(dictionary, wordToEdit, newWord, newDefinition);
  469.                             listWords(dictionary, words);
  470.                             updateListBox(hwnd, words);
  471.                             for (int i = 0; i < words.size(); i++) {
  472.                                 if (words[i] == newWord) {
  473.                                     SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_SETCURSEL, i, 0); // Select the edited word
  474.                                     break;
  475.                                 }
  476.                             }
  477.                             serializeDictionary(dictionary, L"dictionary.txt");
  478.                         }
  479.                         break;
  480.                     }
  481.                     current = current->next;
  482.                 }
  483.                 if (!current) {
  484.                     MessageBox(hwnd, L"Word not found in the dictionary.", L"Error", MB_OK | MB_ICONERROR);
  485.                 }
  486.             }
  487.             return TRUE;
  488.         }*/
  489.  
  490.         case IDC_VIEW_DEFINITION: {
  491.             int index = SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETCURSEL, 0, 0);
  492.             if (index != LB_ERR) {
  493.                 wchar_t word[256];
  494.                 SendDlgItemMessage(hwnd, IDC_LISTBOX, LB_GETTEXT, index, (LPARAM)word);
  495.                 Node* current = dictionary;
  496.                 while (current) {
  497.                     if (current->data.word == word) {
  498.                         DisplayDefinition(hwnd, current->data.word, current->data.definition);
  499.                         break;
  500.                     }
  501.                     current = current->next;
  502.                 }
  503.             }
  504.             return TRUE;
  505.         }
  506.  
  507.         case IDC_SEARCH_INPUT: {
  508.             if (HIWORD(wParam) == EN_CHANGE) {
  509.                 wchar_t query[256];
  510.                 GetDlgItemText(hwnd, IDC_SEARCH_INPUT, query, 256);
  511.                 if (wcslen(query) == 0) {
  512.                     updateListBox(hwnd, words);
  513.                 }
  514.                 else {
  515.                     vector<wstring> suggestions;
  516.                     searchWordRealtime(dictionary, query, suggestions);
  517.                     updateListBox(hwnd, suggestions);
  518.                 }
  519.             }
  520.             return TRUE;
  521.         }
  522.  
  523.         case IDC_CLEAR_SEARCH: {
  524.             SetDlgItemText(hwnd, IDC_SEARCH_INPUT, L"");
  525.             updateListBox(hwnd, words);
  526.             return TRUE;
  527.         }
  528.  
  529.         //Prune Functions
  530.         case IDC_PRUNE: {
  531.             int result = MessageBox(hwnd, L"Are you sure you want to prune the list and remove duplicates?", L"Confirm Prune", MB_YESNO | MB_ICONQUESTION);
  532.             if (result == IDYES) {
  533.                 int duplicatesRemoved = pruneDictionary(dictionary);
  534.                 updateDictionaryAfterPrune(dictionary, words, hwnd);
  535.  
  536.                 wstring message = L"Pruning complete. ";
  537.                 message += to_wstring(duplicatesRemoved);
  538.                 message += L" duplicate entries were removed.";
  539.                 MessageBox(hwnd, message.c_str(), L"Prune Results", MB_OK | MB_ICONINFORMATION);
  540.             }
  541.             return TRUE;
  542.         }
  543.  
  544.         case IDCANCEL:
  545.             DestroyWindow(hwnd);
  546.             PostQuitMessage(0);
  547.             return TRUE;
  548.         }      
  549.         break;
  550.  
  551.     case WM_CLOSE:
  552.         DestroyWindow(hwnd);
  553.         PostQuitMessage(0);
  554.         return TRUE;
  555.     }
  556.     return FALSE;
  557. }
  558.  
  559. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
  560.     HWND hDlg = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_MAINDIALOG), 0, DialogProc, 0);
  561.     if (!hDlg) {
  562.         MessageBox(NULL, L"Failed to create dialog", L"Error", MB_ICONERROR | MB_OK);
  563.         return 1;
  564.     }
  565.  
  566.     ShowWindow(hDlg, nCmdShow);
  567.  
  568.     MSG msg;
  569.     BOOL bRet;
  570.     while ((bRet = GetMessage(&msg, nullptr, 0, 0)) != 0) {
  571.         if (bRet == -1) {
  572.             // Handle the error and possibly exit
  573.             break;
  574.         }
  575.         else if (!IsWindow(hDlg) || !IsDialogMessage(hDlg, &msg)) {
  576.             TranslateMessage(&msg);
  577.             DispatchMessage(&msg);
  578.         }
  579.     }
  580.  
  581.     return (int)msg.wParam;
  582. }
  583.  
  584. Resource2.rc file::
  585. #include <windows.h>
  586. #include "resource2.h"
  587.  
  588. IDD_MAINDIALOG DIALOGEX 0, 0, 320, 240
  589. STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
  590. CAPTION "Dictionary Application"
  591. FONT 8, "MS Shell Dlg", 400, 0, 0x1
  592. BEGIN
  593. LTEXT           "Word:", -1, 10, 10, 30, 8
  594. EDITTEXT        IDC_WORD_INPUT, 50, 8, 100, 14, ES_AUTOHSCROLL
  595. LTEXT           "Definition:", -1, 10, 30, 40, 8
  596. EDITTEXT        IDC_DEFINITION_INPUT, 50, 28, 200, 14, ES_AUTOHSCROLL
  597. PUSHBUTTON      "Add Word", IDC_ADD_WORD, 260, 8, 50, 14
  598. PUSHBUTTON      "Delete Word", IDC_DELETE_WORD, 260, 28, 50, 14
  599. PUSHBUTTON      "Edit Word", IDC_EDIT_WORD, 260, 48, 50, 14
  600. PUSHBUTTON      "View Definition", IDC_VIEW_DEFINITION, 205, 8, 55, 14
  601. PUSHBUTTON      "Prune", IDC_PRUNE, 160, 8, 25, 14
  602. PUSHBUTTON      "Clear", IDC_CLEAR_SEARCH, 185, 8, 20, 14
  603. LTEXT           "Search:", -1, 10, 50, 30, 8
  604. EDITTEXT        IDC_SEARCH_INPUT, 50, 48, 200, 14, ES_AUTOHSCROLL
  605. LISTBOX         IDC_LISTBOX, 10, 70, 300, 160, LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
  606. END
  607.  
  608. IDD_INPUT DIALOGEX 0, 0, 250, 120
  609. STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
  610. CAPTION "Input"
  611. FONT 8, "MS Shell Dlg", 400, 0, 0x1
  612. BEGIN
  613. LTEXT           "Input:", -1, 7, 14, 50, 8
  614. EDITTEXT        IDC_INPUT, 7, 30, 230, 20, ES_AUTOHSCROLL
  615. DEFPUSHBUTTON   "OK", IDOK, 70, 60, 50, 14
  616. PUSHBUTTON      "Cancel", IDCANCEL, 130, 60, 50, 14
  617. END
  618.  
  619. IDD_DEFINITION DIALOGEX 0, 0, 300, 200
  620. STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
  621. CAPTION "Definition"
  622. FONT 8, "MS Shell Dlg"
  623. BEGIN
  624. EDITTEXT        IDC_DEFINITION_EDIT, 7, 7, 286, 186, ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | WS_VSCROLL
  625. END
  626.  
  627. /*IDD_INPUT DIALOGEX 0, 0, 200, 100
  628. STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
  629. CAPTION "Input"
  630. FONT 8, "MS Shell Dlg"
  631. BEGIN
  632. LTEXT           "Input:", -1, 7, 14, 50, 8
  633. EDITTEXT        IDC_INPUT, 7, 24, 186, 12, ES_AUTOHSCROLL
  634. DEFPUSHBUTTON   "OK", IDOK, 139, 7, 50, 14
  635. PUSHBUTTON      "Cancel", IDCANCEL, 139, 24, 50, 14
  636. END*/
  637.  
  638. //EDITTEXT        IDC_WORD_INPUT, 50, 8, 100, 14, ES_AUTOHSCROLL
  639. //PUSHBUTTON      "Add Word", IDC_ADD_WORD, 260, 8, 50, 14
  640. //PUSHBUTTON      "View Definition", IDC_VIEW_DEFINITION, 260, 68, 50, 14
  641.  
  642. resource2.h file::
  643. #ifndef RESOURCE2_H
  644. #define RESOURCE2_H
  645.  
  646. #define IDD_MAINDIALOG                  101
  647. #define IDC_WORD_INPUT                  1001
  648. #define IDC_DEFINITION_INPUT            1002
  649. #define IDC_ADD_WORD                    1003
  650. #define IDC_DELETE_WORD                 1004
  651. #define IDC_SEARCH_INPUT                1005
  652. #define IDC_LISTBOX                     1006
  653. #define IDC_INPUT                       1007  // Add this line if you're using IDC_INPUT
  654. #define IDC_EDIT_WORD                   1008
  655. #define IDC_VIEW_DEFINITION             1009
  656. #define IDD_INPUT                       1010
  657. #define IDD_DEFINITION                  1011
  658. #define IDC_DEFINITION_EDIT             1012
  659. #define IDC_CLEAR_SEARCH                1013
  660. #define IDC_PRUNE                       1014
  661.  
  662. #endif // RESOURCE2_H
  663.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement