From: Isliguezze on
In my dialog class SmthDlg I have CTreeCtrl Tree; Also I have an
instance of my own class FileSystemParser fps. I want this:
ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE, fps::OnItemexpandingTree)

So, I want that message to be processed by my class's method. How do I
make that possible?
From: David Lowndes on
>In my dialog class SmthDlg I have CTreeCtrl Tree; Also I have an
>instance of my own class FileSystemParser fps. I want this:
>ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE, fps::OnItemexpandingTree)
>
>So, I want that message to be processed by my class's method. How do I
>make that possible?

The notification message is handled by the parent window of the
control - which is your SmthDlg dialog class, so you either need your
method to be in your SmthDlg class to be the dialog, or just call your
class method from a handler of your dialog.

Dave
From: Isliguezze on
Thank you, Dave. I knew this approach, but when I did this:

void CtreeDlg::OnItemexpandingTree(NMHDR* pNMHDR, LRESULT* pResult)
{
fsp.OnItemexpandingTree(pNMHDR, pResult);
}

runtime error occured in this line (which is outside of
FileSystemParser::OnItemexpandingTree method -- in )

NETRESOURCE *const pNetResource = (NETRESOURCE *)(Tree-
>GetItemData( hItem ) );

it says: "Unhandled exception at 0x78a74dee (mfc90ud.dll) in tree.exe:
0xC0000005: Access violation reading location 0x00000020."


HERE:

// winctrl2.cpp
DWORD_PTR CTreeCtrl::GetItemData(HTREEITEM hItem) const
{
ENSURE(::IsWindow(m_hWnd)); // <---- here error happens
// ......... other code
}









If you need the code:

void FileSystemParser::OnItemexpandingTree(NMHDR* pNMHDR, LRESULT*
pResult)
{
TRACE( _T("CDlgGetPath::OnItemexpandingTree(%p)\n"), pNMHDR );
CWaitCursor CursorWaiting; //Show the wait cursor while
expanding
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
ASSERT( pNMTreeView );
ASSERT( pResult );
//Only action 2 notifications
if( pNMTreeView->action == 2 )
{
//Update location display
CString sPath = GetItemPath( pNMTreeView->itemNew.hItem );
//Refresh children
if( !Tree->GetChildItem( pNMTreeView->itemNew.hItem ) )
{
PopulateTree(pNMTreeView->itemNew.hItem );
if(Tree->GetSelectedItem( ) != pNMTreeView->itemNew.hItem )
Tree->SelectItem( pNMTreeView->itemNew.hItem );
}
}
*pResult = 0;
}




CString FileSystemParser::GetItemPath( HTREEITEM hItem )
{
TRACE( _T("CtreeDlg::GetItemPath(%p)\n"), hItem );
CString sRet;
do
{
//End with a share name.
NETRESOURCE *const pNetResource = (NETRESOURCE *)(Tree-
>GetItemData( hItem ) );
if( pNetResource )
{
sRet = CString(pNetResource->lpRemoteName) + _T('\\')+ sRet;
break;
}
//Add the directory name to the path.
sRet = Tree->GetItemText( hItem ) + _T('\\')+ sRet;
hItem = Tree->GetParentItem( hItem );
} while( hItem );
return sRet;
}
From: David Lowndes on
>NETRESOURCE *const pNetResource = (NETRESOURCE *)(Tree-
>>GetItemData( hItem ) );
>
>it says: "Unhandled exception at 0x78a74dee (mfc90ud.dll) in tree.exe:
>0xC0000005: Access violation reading location 0x00000020."

Looks like you've got a NULL pointer somewhere - possibly your "Tree"
variable.

Dave