读程序的高手请进

jw_nj 2002-03-14 04:47:38
以下的程序想在CTreeView视图中显示树,结果树是显示出来了,却没有结点的图标,请高人指点!我想问题可能在CTreeCtrl的风格设置.
void CMainFrame::OnShowtextSentence()
{
// TODO: Add your command handler code here

//Read GB2312 code from the text file
//

m_codeList.RemoveAll();
CSuperCHWApp *pApp = (CSuperCHWApp*)AfxGetApp();
CFile SenTextFile(pApp->m_csTextFilePath, CFile::modeRead);
unsigned short hz;
while(SenTextFile.Read(&hz,2)==2)
{
//if(hz == 0x0a0d) continue;
CCode* pCode=(CCode*)malloc(sizeof(CCode));
pCode->m_textCode=hz;
m_codeList.Add(pCode);
m_nAllLetter++;
}

//Create the imageList
CImageList imageList;
CBitmap bitmap;
int bmpID[] = {IDB_BMP_ROOT1, IDB_BMP_ROOT2, IDB_BMP_C11, IDB_BMP_C12,
IDB_BMP_C21, IDB_BMP_C22, IDB_BMP_C31, IDB_BMP_C32, IDB_BMP_REGION1, IDB_BMP_REGION2,
IDB_BMP_WORD1, IDB_BMP_WORD2};
int bmpNum = sizeof(bmpID) / sizeof(int);
imageList.Create(32, 32, ILC_MASK, 6, 4);
for(int i=0; i < bmpNum; i++)
{
bitmap.LoadBitmap(bmpID[i]);
imageList.Add(&bitmap, (COLORREF)0xFFFFFF);
bitmap.DeleteObject();
}

//Display the sentence tree in the left view
//

CLeftView *pView = (CLeftView*)m_wndSplitter.GetPane(0, 0);
CTreeCtrl *pTreeCtrl = &(pView->GetTreeCtrl());
pTreeCtrl->SetImageList(&imageList, TVSIL_NORMAL);

//Set CTreeCtrl style
long lStyle;
lStyle = ::GetWindowLong(pTreeCtrl->m_hWnd, GWL_STYLE);
lStyle |= (TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
::SetWindowLong(pTreeCtrl->m_hWnd, GWL_STYLE, lStyle);
pView->SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);

//Insert the tree root
HTREEITEM hRoot = pTreeCtrl->InsertItem("文脉统计字符", 0, 1, TVI_ROOT, TVI_ROOT);
//Insert the first branch
HTREEITEM hParent = pTreeCtrl->InsertItem("第1句", 2, 3, hRoot, TVI_LAST), hWord;

int nIndex = 0, nBranch = 2;
char word[3] = {0};
CString strTemp;

//Insert other branchs and all words
while (nIndex <= m_codeList.GetUpperBound())
{
hz = ((CCode*)m_codeList.GetAt(nIndex))->m_textCode;
if(hz != 0x0a0d)
{
// add the word to the tree
*(unsigned short*)word = hz;
hWord = pTreeCtrl->InsertItem(word, 10, 11, hParent, TVI_LAST);
pTreeCtrl->SetItemData(hWord, nIndex);
nIndex++;
}
else
{
// delete 0x0a0d
m_codeList.RemoveAt(nIndex);
//add a branch
strTemp.Format("第%d句",nBranch++);
hParent = pTreeCtrl->InsertItem(strTemp, 2, 3, hRoot, TVI_LAST);
pTreeCtrl->SetItemData(hParent, -1);
}
}
}
...全文
31 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
jw_nj 2002-03-15
  • 打赏
  • 举报
回复
谢谢各位,现这个问题已解决,原来是CImageList是在栈上的.
robothn 2002-03-15
  • 打赏
  • 举报
回复
TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE
robothn 2002-03-15
  • 打赏
  • 举报
回复
TV_INSERTSTRUCT tvInsert;
HTREEITEM hCurTreeItem;
tvInsert.hParent = TVI_ROOT; // Insert as root
tvInsert.hInsertAfter = TVI_LAST;
tvInsert.item.mask = TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE; // Set Follow Properties
tvInsert.item.pszText = "文脉"; // Caption
tvInsert.item.lParam = 0; // Param
tvInsert.item.iImage = 0; // Image of normal
tvInsert.item.iSelectedImage = 0; // Show Image when item be selected
hCurTreeItem = m_TreeCat.InsertItem(&tvInsert); // Insert item
你 ROOT 的 mask 未设
robothn 2002-03-15
  • 打赏
  • 举报
回复
htiInsert = pTree->InsertItem(sData, 1, 1, htiParentItem); // use icon 'IDI_BRANCH'
recset.GetFieldValue("cat_level", sData);
pTree->SetItemData(htiInsert, MAKELONG(m_nTotalBrowseItem,atoi(sData)));
if(strcmp(sData,"2") == 0) // If item is a leaf
pTree->SetItemImage(htiInsert, 2, 2); // modify icon
jw_nj 2002-03-15
  • 打赏
  • 举报
回复
ModifyStyle也不行
strip 2002-03-14
  • 打赏
  • 举报
回复
改变风格你用这句试试:

pTreeCtrl->ModifyStyle( 0, TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT, SWP_FRAMECHANGED );
jw_nj 2002-03-14
  • 打赏
  • 举报
回复
这个我试过了,也不行,我想问题出在风格设定.
prometheusphinx 2002-03-14
  • 打赏
  • 举报
回复
要用这个
InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam, HTREEITEM hParent, HTREEITEM hInsertAfter );
nMask中一定要有TVIF_IMAGE这一值。
jw_nj 2002-03-14
  • 打赏
  • 举报
回复
InsertItem 的第二、三个参数就是节点位图的索引,不是吗?我写了。
prometheusphinx 2002-03-14
  • 打赏
  • 举报
回复
你根本就没有指定树的节点位图的索引,它怎么会显示呢?
jw_nj 2002-03-14
  • 打赏
  • 举报
回复
没人知道吗?
jw_nj 2002-03-14
  • 打赏
  • 举报
回复
也许很简单!

1,660

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 非技术类
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧