
之前也尝试过多种版本,比如微软自己常用的tab标签型,KMPlayer的tree型.最终选择了这种样式.
我个人认为是在美观和简易上做的折衷.类似的样式在原版emule上也可以看到,不过那些有某些缺陷,样子是一样的.
左边的东西实质上是一个treeview,不过拥有样式TVS_SHOWSELALWAYS | TVS_FULLROWSELECT 这个TreeView只有根节点,没有子节点.
另外使用了TreeView_SetItemHeight来设置行的高度.一个Imagelist来设置图标.
做好之后要做的就是捕捉几个消息处理就是了.我在这里只对TVN_BEGINDRAG, TVN_BEGINRDRAG, TVN_SELCHANGED三个消息做了处理.同时还避免了emule上出现的一些小瑕疵.
右边被切换的对话框我使用CreateDialogIndirect来加速切换速度.
时间很晚了,毕竟开学了,要早睡早起~.下面给出部分关键代码,有空再把本文补充地完善些:
// self defined struct : for save infomation of items
struct ConfigerItemsInfo {
//dialog call back function
INT_PTR (CALLBACK * CallBackProc)(HWND, UINT, WPARAM, LPARAM);
//icon and string id in resources file
UINT iconID;
UINT StringID;
//dialog hwnd
HWND hwnd;
//dialog Template
DLGTEMPLATE * dlgTemplate;
};
//function to initial Dialog
//get TreeView Cotrol
HWND hwndTemp = GetDlgItem(hwndDlg,IDC_TREE_CONFIG);
//set new height
TreeView_SetItemHeight(hwndTemp, 22);
// get Configer class
if (NULL == BP_Configer) BP_Configer = new module_configurer();
// BP_Configer->getImageList() return the imagelist initied
TreeView_SetImageList(hwndTemp, BP_Configer->getImageList(), TVSIL_NORMAL);
// number of Items
int Temp = BP_Configer->getItemsCount();
TCHAR TempString[MAX_PATH];
for (int i=0; i
ConfigerItemsInfo * cfgitem;
// Get Item config info
cfgitem = BP_Configer->getItemByID(i);
// load string from resources
loadStringByID(cfgitem->StringID, TempString, MAX_PATH);
AddItemToTreeView(hwndTemp, TempString, cfgitem->iconID, (LPARAM)cfgitem);
}
//Add Item To TreeView
bool AddItemToTreeView (HWND hwndTV, LPWSTR lpszItem, int ImageId, LPARAM lparam) {
TVITEM tvi;
TVINSERTSTRUCT tvins;
HTREEITEM hti;
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_PARAM | TVIF_SELECTEDIMAGE;
// Set the text of the item.
tvi.pszText = lpszItem;
tvi.cchTextMax = sizeof(tvi.pszText)/sizeof(tvi.pszText[0]);
// Assume the item is not a parent item, so give it a
// document image.
tvi.iImage = ImageId;
tvi.iSelectedImage = ImageId;
// Save the heading level in the item's application-defined
// data area.
tvi.lParam = lparam;
tvins.item = tvi;
tvins.hInsertAfter = TVI_LAST;
tvins.hParent = TVI_ROOT;
// Add the item to the tree-view control.
if (NULL == TreeView_InsertItem(hwndTV,&tvins)) return false;
else return true;
}
No comments:
Post a Comment