⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 booksdlg.cpp

📁 一个帮助你学习英语的软件~~很不错的咯~~ 对功能又做了改进~大家支持下哈~
💻 CPP
字号:
//PK 2007/03/05 - 10
//PK Recite

#include "stdafx.h"
#include "BooksDlg.h"
#include "Repository.h"
#include "Book.h"
#include "CreateBookDlg.h"
#include "MainDlg.h"

LRESULT CBooksDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{	//PK 2007/03/05 - 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);

	_list = GetDlgItem(IDC_LIST1);
	_list.SetExtendedListViewStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	_list.InsertColumn(0, "Book name", LVCFMT_LEFT, 260);
	_list.InsertColumn(1, "Contributor", LVCFMT_LEFT, 100);
	_list.InsertColumn(2, "Item count", LVCFMT_RIGHT, 70);
	_list.InsertColumn(3, "Dir name", LVCFMT_LEFT, 100);

	int amount = _repository.size();
	for (int i = 0; i < amount; ++i) {
		CBook * book = _repository.get_book(i);
		int index = _list.GetItemCount();
		_list.AddItem(index, 0, "");
		_update_book_to_list(book, index);
		if (book->is_active()) _list.SetCheckState(index, TRUE);
	}
	return 0;
}
LRESULT CBooksDlg::OnAdd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{	//PK 2007/03/05 - 07
	CAddBookDlg dlg;
	dlg.status(CAddBookDlg::ADD);
	if (IDOK == dlg.DoModal()) {
		CBook * book = _repository.add_book(dlg._name, fs::path(dlg._path, fs::native));
		int index = _list.GetItemCount();
		_list.AddItem(index, 0, "");
		_update_book_to_list(book, index);
	}

	return 0;
}
LRESULT CBooksDlg::OnModify(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{	//PK 2007/03/06 - 10
	int index = _list.GetSelectedIndex();
	if (-1 == index) {
		MessageBox("Please select the BOOK you want to modify!", "No selected book!", MB_OK | MB_ICONWARNING);
		return 0;
	}
	CBook * book = (CBook *)_list.GetItemData(index);
	assert(book != NULL);
	CAddBookDlg dlg;
	dlg.status(CAddBookDlg::MODIFY);
	dlg._name = book->book_name();
	dlg._path = book->dir().string();
	dlg._contributor = book->contributor();
	if (IDOK == dlg.DoModal()) {
		book->book_info_changed(dlg._name, dlg._contributor);
		_update_book_to_list(book, index);
		::PostMessage(GetParent(), WM_BOOKNAME_MODIFIED, (WPARAM)book, 0);
	}
	return 0;
}
LRESULT CBooksDlg::OnDelete(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{	//PK 2007/03/06 - 07
	int index = _list.GetSelectedIndex();
	if (-1 == index) {
		MessageBox("Please select the BOOK you want to delete!", "No selected book!", MB_OK | MB_ICONWARNING);
		return 0;
	}
	
	if (IDNO ==  MessageBox("Do you really want to delete this book?\nThis action cannot UNDO!", "Confirm delete!", MB_YESNO | MB_ICONWARNING)) return 0;
	
	CBook * book = (CBook *)_list.GetItemData(index);
	assert(book != NULL);
	::SendMessage(GetParent(), WM_BOOK_DELETE, (WPARAM)book, 0);
	bool res = _repository.delete_book(book);
	if (!res) {
		MessageBox("Deleting book error!", "Error", MB_OK | MB_ICONERROR);
		return 0;
	}
	_list.DeleteItem(index);

	return 0;
}
LRESULT CBooksDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{	//PK 2007/03/05 - 07
	int amount = _list.GetItemCount();
	for (int i = 0; i < amount; ++i) {
		CBook * book = (CBook *)_list.GetItemData(i);
		if (_list.GetCheckState(i)) {
			book->set_active(true);
			g_config.set_active_book(book->get_book_id());
			::PostMessage(GetParent(), WM_BOOK_ADD, (WPARAM)book, 0);
		} else {
			book->set_active(false);
			g_config.move_active_book(book->get_book_id());
			::PostMessage(GetParent(), WM_BOOK_DELETE, (WPARAM)book, 0);
		}
	}
	
	EndDialog(wID);
	return 0;
}
void CBooksDlg::_update_book_to_list(CBook * book, const int index)
{	//PK 2007/03/06 - 10
	assert(book != NULL);
	assert(index >= 0 && index < _list.GetItemCount());
	_list.SetItemText(index, 0, book->book_name().c_str());
	_list.SetItemText(index, 1, book->contributor().c_str());
	stringstream size;
	size << book->size();
	_list.SetItemText(index, 2, size.str().c_str());
	_list.SetItemText(index, 3, book->dir().leaf().c_str());
	_list.SetItemData(index, (DWORD_PTR)book);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -