J Guy Davidson

The documentation tells me that CTreeCtrl::SetItemText can return nonzero if successful, zero otherwise. But if it is unsuccessful, is there anything I can do to find out why I'm getting crashes in my tree controls, and failed assertions on this function, so I want to see if those two facts are related.

Cheers,

Guy



Re: Visual C++ General What can I do if CTreeCtrl::SetItemText returns FALSE?

TilakGopi

Use GetLastError() function to get the actual error code.It may help u to track the reason behind the problem.

See this MSDN sample :

http://msdn.microsoft.com/library/default.asp url=/library/en-us/vcsample/html/_sample_MFC_CMNCTRL1.asp

and ofcourse google for more..

Thanx,

Ch.T.Gopi Kumar.






Re: Visual C++ General What can I do if CTreeCtrl::SetItemText returns FALSE?

J Guy Davidson

GetLastError() returns 0. [I'm pretty sure GetLastError post-dates the message handling subsystem.] Not quite sure of the relevance of the code sample either.

Thanks anyway. Any other clues Anyone

Cheers,

Guy





Re: Visual C++ General What can I do if CTreeCtrl::SetItemText returns FALSE?

TilakGopi

Hi,

Have u downloaded the sample ,at the top left corner of the page

-----------------------------------------------------------------------------

Visual C++ MFC Samples  

CMNCTRL1 Sample: Demonstrates Common Control MFC Classes, Part 1

Download Sample

The CMNCTRL1 sample illustrates how to use the following common control MFC classes: CTreeCtrl, CToolBarCtrl, CAnimateCtrl, CDateTimeCtrl, and CMonthCalCtrl. It shows how the controls are created and how to change the controls using many of

----------------------------------

Download and build , run , u'll definitely get to know good things about tree ctrl. Hope u only can solve ur problem after understanding the code in the sample.

 

Thanx,

Ch.T.Gopi Kumar.






Re: Visual C++ General What can I do if CTreeCtrl::SetItemText returns FALSE?

J Guy Davidson

I have indeed downloaded the sample, but nowhere therein does it use GetLastError to establish why a text insertion may have failed, nor does it seem to check on the success of a text insertion. Am I missing something

To reiterate, CTreeCtrl::SetItemText is returning false, and I want to find out why, as it may be the cause of a crash later on in execution.

Thanks,

Guy





Re: Visual C++ General What can I do if CTreeCtrl::SetItemText returns FALSE?

TilakGopi

Hi Guy,

I downloaded the sample ,and used the functio SetItemText() and found it's working fine.

U can also test.

1)Open treecpg.cpp file

2)Insert 'm_mytreectrl.SetItemText(m_rghItem [ 8 ],_T("J Guy Davidson "));' before return false as shown below(highlighted).

/////////////////////////////////////////////////////////////////////////////

// CTreeCtrlPage message handlers

BOOL CTreeCtrlPage::OnInitDialog()

{

CImageList *pImageList;

CBitmap bitmap;

CString strItems[12];

CCmnCtrl1App *pApp;

int iItem;

UINT nID;

TV_INSERTSTRUCT curTreeItem;

strItems[0]= _T("Dogs");

strItems[1]= _T("German Shepherd");

strItems[2]= _T("Dalmatian");

strItems[3]= _T("Great Dane");

strItems[4]= _T("Birds");

strItems[5]= _T("Hummingbird");

strItemsDevil= _T("Pigeon");

strItems[7]= _T("Eagle");

strItemsMusic= _T("Fish");

strItems[9]= _T("Snapper");

strItems[10]= _T("Sole");

strItems[11]= _T("Salmon");

pApp = (CCmnCtrl1App *)AfxGetApp();

CPropertyPage::OnInitDialog(); // let the base class do the default work

pImageList = new CImageList();

pImageList->Create(32, 16, ILC_MASK, 6, 4);

for (nID = IDB_BMTREEFIRST; nID <= IDB_BMTREELAST; nID++) // load bitmaps for dog, bird and fish

{

bitmap.LoadBitmap(nID);

pImageList->Add(&bitmap, (COLORREF)0xFFFFFF);

bitmap.DeleteObject();

}

m_mytreectrl.SetImageList(pImageList, TVSIL_NORMAL);

for (iItem = 0; iItem < CELEMS(strItems); iItem ++)

{

curTreeItem.hParent = (iItem % 4 == 0) NULL : m_rghItem[iItem / 4 * 4];

curTreeItem.hInsertAfter = TVI_SORT;

curTreeItem.item.iImage = iItem / 4 * 2;

curTreeItem.item.iSelectedImage = curTreeItem.item.iImage + 1;

curTreeItem.item.pszText = strItems[iItem].GetBuffer(strItems[iItem].GetLength());

curTreeItem.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;

m_rghItem[iItem] = m_mytreectrl.InsertItem(&curTreeItem);

}

m_mytreectrl.SetItemText(m_rghItem [ 8 ] ,_T("J Guy Davidson "));

return FALSE;

}

3)Run the application , Goto CTreeCtrl Tab View,  U can see ur name with fish icon.

So ,it might be problem with HTREEITEM u r passing for SetItemText control ,or the string.

4)Try this flow, otherwise u can post ur code,that'll help a lot in solving ur problem.

 

Thanx,

Ch.T.Gopi Kumar.






Re: Visual C++ General What can I do if CTreeCtrl::SetItemText returns FALSE?

Bite Qiu - MSFT

J Guy Davidson wrote:

To reiterate, CTreeCtrl::SetItemText is returning false, and I want to find out why, as it may be the cause of a crash later on in execution.

One main reason that Microsoft provide the source code of MFC library is that allowing developers to "find out why" by step into the MFC source code. I believe step into CTreeCtrl::SetItemText method will make things clear.