我想了解更多关于 C++ 编码的知识,尤其是设计和创建桌面应用程序。
首先,我想创建一个通知应用程序,在其中我可以通过为任务指定名称和内容来完成任务。为此,我使用 2 个向量 (name
和content
)。
我像这样初始化向量:
std::vector <LPWSTR> NameTask;
std::vector <LPWSTR> ContentTask;
之后,我只需创建一个按钮来将name
和添加content
到向量中:
if (wmId == ID_BUTTON) {
//local variables (only for the Button event)
int len_name = GetWindowTextLength(TextBox_Name) + 1; //give the lenght value of the text in the textbox
int len_content = GetWindowTextLength(TextBox_content) + 1; //give the lenght value of the text in the textbox
wchar_t Text_name[100] = L""; //Wchar is compatible with LPWSTR
wchar_t Text_content[100] = L""; //Wchar is compatible with LPWSTR
// get the text of the Text edit and put it in local variable name and content
GetWindowText(TextBox_Name, Text_name, len_name);
GetWindowText(TextBox_content, Text_content, len_content);
//verify if the texts are empty
if (wcslen(Text_name) == 0 || wcslen(Text_content) == 0) {
MessageBox(hWnd, L"name and content can't be empty", L"MessageBox", MB_OK);
}
else {
NameTask.push_back(Text_name); // set name of task in vector of NameTask
ContentTask.push_back (Text_name); // set content of task in vector of ContentTask
//ComboBox_AddString(Combobox, Text_name); // add the title of the task in the combotext
//SetWindowText(TextBox_Name, L""); //empty the textbox
SetWindowText(TextBox_content, NameTask.at(0)); // visualize first element of vector name
}
}
我遇到的问题是,当我向向量添加一个新元素,然后我去可视化它时,它总是向我显示添加的最后一个元素。即使我使用SetWindowText(TextBox_content, NameTask.at(0));
当我使用另一个按钮来可视化name
andcontent
时,它会给出一个奇怪的输出: