void OnLSBt(BOOL checkrunning) { ULARGE_INTEGER ullFreeBytesAvailable, ullTotalNumberOfBytes; char text[_MAX_PATH]; HRESULT hr = S_OK; HWND hctl = GetDlgItem(gdmgr._hdlg_ddesc, IDC_TV_DDESC_EXPLORER); // 1. 删除Treeview中所有项 TreeView_DeleteAllItems(hctl); // 2. 地址栏编辑框 Edit_SetText(GetDlgItem(gdmgr._hdlg_ddesc, IDC_ET_DDESC_WWWROOT), appendbackslash(game_config::path.c_str())); // 3. 向TreeView添加一级内容 gdmgr._htvroot = TreeView_AddLeaf(hctl, TVI_ROOT); strcpy(text, basename(game_config::path.c_str())); // 这里一定要设TVIF_CHILDREN, 否则接下折叠后将判断出其cChildren为0, 再不能展开 TreeView_SetItem1(hctl, gdmgr._htvroot, TVIF_TEXT | TVIF_PARAM | TVIF_CHILDREN, (LPARAM)gdmgr._htvroot, 0, 0, is_empty_dir(game_config::path.c_str())? 0: 1, text); dir_2_tv(hctl, gdmgr._htvroot, game_config::path.c_str(), 0); // 4. 底下状态 strncpy(text, game_config::path.c_str(), 2); text[2] = '\\'; text[3] = 0; GetDiskFreeSpaceEx(text, &ullFreeBytesAvailable, &ullTotalNumberOfBytes, NULL); strcpy(text, format_space_u64n(ullTotalNumberOfBytes.QuadPart)); Edit_SetText(GetDlgItem(gdmgr._hdlg_ddesc, IDC_ET_DDESC_SUBAREA), formatstr("%s (Avail Space %s)", text, format_space_u64n(ullFreeBytesAvailable.QuadPart))); return; }
// void advancement_tree_internal(const unit_type& current, void tcore::tree_2_tv(HWND hctl, HTREEITEM htvroot) { char text[_MAX_PATH]; HTREEITEM htvi; std::stringstream strstr; std::vector<std::string> advances_from; size_t index = 0; for (std::vector<node*>::const_iterator it = utype_tree_.begin(); it != utype_tree_.end(); ++ it, index ++) { const node* n = *it; const unit_type* current = n->current; htvi = TreeView_AddLeaf(hctl, htvroot); strstr.str(""); strstr << std::setw(2) << std::setfill('0') << index << ": " << utf8_2_ansi(current->type_name().c_str()) << "(" << current->id() << ")"; if (!current->packer()) { strstr << "[" << current->level() << "级]"; } else { strstr << "[打包]"; } strcpy(text, strstr.str().c_str()); // 枚举到此为止,此个config一定有孩子,强制让出来前面+符号 LPARAM lParam = tv_tree_.size(); advances_from.clear(); tv_tree_.push_back(std::make_pair<std::string, std::vector<std::string> >(current->id(), advances_from)); if (n->advances_to.empty()) { TreeView_SetItem2(hctl, htvi, TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM, lParam, gdmgr._iico_dir, gdmgr._iico_dir, 1, text); } else { TreeView_SetItem2(hctl, htvi, TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_CHILDREN, lParam, gdmgr._iico_dir, gdmgr._iico_dir, 1, text); advances_from.push_back(current->id()); tree_2_tv_internal(hctl, htvi, n->advances_to, advances_from); TreeView_Expand(hctl, htvi, TVE_EXPAND); } } }
// 更新某一ITEM的TV_ITEM结构信息 // @mask: 更改掩码。 // @lParam:mask有TVIF_PARAM标志时有效。 // @lImage:mask有TVIF_IMAGE标志时有效。 // @lSelectedImage:mask有TVIF_SELECTEDIMAGE标志时有效。 // @lpszText:mask有TVIF_TEXT标志时有效。 HTREEITEM TreeView_AddLeaf1(HWND hwndTV, HTREEITEM hTreeParent, UINT mask, LPARAM lParam, int iImage, int iSelectedImage, int cChildren, LPSTR lpszText, ...) { HTREEITEM hti; TCHAR szBuffer[1024]; va_list list; if (lpszText) { // 要求lpszText不能为NULL va_start(list, lpszText); vsprintf(szBuffer, lpszText, list); va_end(list); } else { szBuffer[0] = 0; } hti = TreeView_AddLeaf(hwndTV, hTreeParent); TreeView_SetItem1(hwndTV, hti, mask, lParam, iImage, iSelectedImage, cChildren, szBuffer); return hti; }
BOOL cb_walk_dir_explorer(char *name, uint32_t flags, uint64_t len, int64_t lastWriteTime, uint32_t* ctx) { int iimg = select_iimage_according_fname(name, flags); HTREEITEM htvi; TVSORTCB tvscb; tv_walk_dir_param_t* wdp = (tv_walk_dir_param_t*)ctx; htvi = TreeView_AddLeaf(wdp->hctl, wdp->htvi); TreeView_SetItem1(wdp->hctl, htvi, TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_CHILDREN, (LPARAM)htvi, iimg, iimg, 0, name); tvscb.hParent = wdp->htvi; tvscb.lpfnCompare = fn_tvi_compare_sort; tvscb.lParam = (LPARAM)wdp->hctl; TreeView_SortChildrenCB(wdp->hctl, &tvscb, 0); if (flags & FILE_ATTRIBUTE_DIRECTORY ) { tv_walk_dir_param_t wdp2; sprintf(wdp2.curdir, "%s\\%s", wdp->curdir, name); if (wdp->maxdeep > wdp->deep) { tv_walk_dir_param_t wdp2; wdp2.hctl = wdp->hctl; wdp2.htvi = htvi; wdp2.maxdeep = wdp->maxdeep; wdp2.deep = wdp->deep + 1; walk_dir_win32_deepen(wdp2.curdir, 0, cb_walk_dir_explorer, (uint32_t *)&wdp2); } else if (!is_empty_dir(wdp2.curdir)) { // 枚举到此为止,但因为是目录,强制让出来前面+符号 TreeView_SetItem1(wdp->hctl, htvi, TVIF_CHILDREN, 0, 0, 0, 1, NULL); } } return TRUE; }
void tcore::update_to_ui_formation(HWND hdlgP) { char text[_MAX_PATH]; std::stringstream strstr; HWND hctl = GetDlgItem(hdlgP, IDC_TV_FORMATION_EXPLORER); // 1. clear treeview TreeView_DeleteAllItems(hctl); // 2. fill content htvroot_formation_ = TreeView_AddLeaf(hctl, TVI_ROOT); strstr.str(""); strstr << dgettext_2_ansi("kingdom-lib", "tactical^Formation"); strcpy(text, strstr.str().c_str()); // must set TVIF_CHILDREN TreeView_SetItem1(hctl, htvroot_formation_, TVIF_TEXT | TVIF_PARAM | TVIF_CHILDREN, 0, 0, 0, 1, text); HTREEITEM htvi_formation, htvi_branch, htvi; utils::string_map symbols; const std::map<int, tformation_profile>& formations = unit_types.formations(); for (std::map<int, tformation_profile>::const_iterator it = formations.begin(); it != formations.end(); ++ it) { const tformation_profile& f = it->second; htvi_formation = TreeView_AddLeaf(hctl, htvroot_formation_); LPARAM lParam = f.index(); strstr.str(""); strstr << std::setw(2) << std::setfill('0') << f.index() << ": " << utf8_2_ansi(f.name().c_str()) << "(" << f.id() << ")"; strstr << utf8_2_ansi(_("Description")) << ": "; strstr << utf8_2_ansi(f.description().c_str()); strcpy(text, strstr.str().c_str()); TreeView_SetItem2(hctl, htvi_formation, TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_CHILDREN, lParam, gdmgr._iico_dir, gdmgr._iico_dir, 1, text); // arms requrie htvi = TreeView_AddLeaf(hctl, htvi_formation); strstr.str(""); strstr << _("Arms require"); strcpy(text, utf8_2_ansi(strstr.str().c_str())); TreeView_SetItem2(hctl, htvi, TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN, 0, gdmgr._iico_txt, gdmgr._iico_txt, 1, text); htvi_branch = htvi; htvi = TreeView_AddLeaf(hctl, htvi_branch); strstr.str(""); strstr << _("Type") << ": "; for (std::set<std::string>::const_iterator it2 = f.arms_type_.begin(); it2 != f.arms_type_.end(); ++ it2) { if (it2 != f.arms_type_.begin()) { strstr << ", "; } strstr << dsgettext("kingdom-lib", it2->c_str()); } strstr << " "; strstr << _("attack^Range") << ": " << dsgettext("kingdom-lib", unit_types.range_ids()[f.arms_range_].c_str()); strstr << "(" << f.arms_range_id_ << ")"; strstr << " "; strstr << _("Quantity") << ": " << f.arms_count_; strcpy(text, utf8_2_ansi(strstr.str().c_str())); TreeView_SetItem2(hctl, htvi, TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN, 0, gdmgr._iico_txt, gdmgr._iico_txt, 0, text); TreeView_Expand(hctl, htvi_branch, TVE_EXPAND); if (f.attack_flag_) { bool first = true; htvi = TreeView_AddLeaf(hctl, htvi_formation); strstr.str(""); strstr << _("Attack") << ": "; if (f.attack_flag_ & tformation_profile::SLOW) { if (!first) { strstr << ", "; } else { first = false; } strstr << dsgettext("kingdom-lib", "slowed"); } if (f.attack_flag_ & tformation_profile::BREAK) { if (!first) { strstr << ", "; } else { first = false; } strstr << dsgettext("kingdom-lib", "broken"); } if (f.attack_flag_ & tformation_profile::POISON) { if (!first) { strstr << ", "; } else { first = false; } strstr << dsgettext("kingdom-lib", "poisoned"); } strcpy(text, utf8_2_ansi(strstr.str().c_str())); TreeView_SetItem2(hctl, htvi, TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN, 0, gdmgr._iico_txt, gdmgr._iico_txt, 0, text); } htvi = TreeView_AddLeaf(hctl, htvi_formation); strstr.str(""); strstr << _("Icon") << "/" << _("Image") << ": "; strstr << f.icon() << " " << f.bg_image(); strcpy(text, utf8_2_ansi(strstr.str().c_str())); TreeView_SetItem2(hctl, htvi, TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN, 0, gdmgr._iico_txt, gdmgr._iico_txt, 0, text); TreeView_Expand(hctl, htvi_formation, TVE_EXPAND); } TreeView_Expand(hctl, htvroot_formation_, TVE_EXPAND); }