读程序的高手请进
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);
}
}
}