📄 createbookdlg.cpp
字号:
//PK 2007/03/05 - 10
//PK Recite
#include "stdafx.h"
#include "CreateBookDlg.h"
#include "Book.h"
#include "wtl_tools.h"
LRESULT CAddBookDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{ //PK 2007/03/06 - 10
CenterWindow(GetParent());
HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
SetIcon(hIconSmall, FALSE);
_edt_name = GetDlgItem(IDC_EDT_DLGADD_BOOK);
_edt_dir = GetDlgItem(IDC_EDT_DLGADD_DIR);
_edt_contributor = GetDlgItem(IDC_EDT_DLGADD_CONTRIBUTOR);
if (ADD == _status) SetWindowText("Add a book");
if (MODIFY == _status) {
SetWindowText("Modify book");
_edt_name.SetWindowText(_name.c_str());
_edt_dir.SetWindowText(_path.c_str());
_edt_dir.EnableWindow(false);
_edt_contributor.SetWindowText(_contributor.c_str());
}
return 0;
}
LRESULT CAddBookDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{ //PK 2007/03/05 - 10
string name, contributor;
get_window_text(_edt_name, name);
get_window_text(_edt_dir, _path);
get_window_text(_edt_contributor, contributor);
trim(name);
trim(_path);
trim(contributor);
if (_path.empty()) _path = name;
//PK if no modification
if (MODIFY == _status && _name == name && _contributor == contributor) {
EndDialog(IDCANCEL);
return 0;
}
_name = name;
_contributor = contributor;
bool is_valid = true;
stringstream prompt;
fs::path book_dir;
if (_name.empty()) {
prompt << "Please enter a book name!" << std::endl;
is_valid = false;
} else {
if (_name.size() > BOOK_NAME_MAX_LEN) {
prompt << "The length of book name must be less than " << BOOK_NAME_MAX_LEN << "." << std::endl;
is_valid = false;
}
if (_contributor.empty()) _contributor = "Noname";
else if (_contributor.size() > CONTRIBUTOR_NAME_MAX_LEN) {
prompt << "The length of contributor name must be less than " << CONTRIBUTOR_NAME_MAX_LEN << "." << std::endl;
is_valid = false;
}
try {
book_dir = fs::path(_path, fs::native);
} catch (...) {
is_valid = false;
prompt << "Book directory name is not a valid path name!" << std::endl;
}
}
if (!is_valid) {
MessageBox(prompt.str().c_str(), "Add Book error!", MB_OK | MB_ICONWARNING);
return 0;
}
EndDialog(wID);
return 0;
}
LRESULT CAddBookDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{ //PK 2007/03/05
EndDialog(wID);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -