// 怕一些静态变量可能冲突,由宏改为函数 // 当目录下删除最后一张叶子后, 直接设TVIF_CHILDREN为0, 不能除去前面-符号. 增加TreeView_Expand还是不行 void TreeView_SetChilerenByPath(HWND hctl, HTREEITEM htvi, char *path) { // 这里要求要是path是文件的话(原则上是不应该是出现的,但调用程序可能不小心出现), is_empty_dir需要返回TRUE, // 否则这个文件叶子要被错误的被cChildren置为1. if (is_empty_dir(path)) { TreeView_Expand(hctl, htvi, TVE_COLLAPSE); TreeView_SetItem1(hctl, htvi, TVIF_CHILDREN, 0, 0, 0, 0, NULL); } else { TreeView_SetItem1(hctl, htvi, TVIF_CHILDREN, 0, 0, 0, 1, NULL); } return; }
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; }
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; }
// 更新某一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; }
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); }