15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CTreeCtrl Image draw problem

Jeff Rucker -- jrucker@ssccorp.com
Thursday, March 06, 1997


Environment: Win95, VC++ 4.1

I've got an SDI app with a splitter window, CTreeView in the left pane.
Everything has been great until I added images for the tree items. I got
the normal images to work fine, I was trying to get the Open folder/Closed
folder type of image to work. I'm using OnItemExpanded to get the item when
it is expanded/closed and there I change it's image appropriately. What I
find is that if the item being expanded was _selected_ (single-click)
before it was expanded (double-click), the image is not redrawn, leaving
the closed folder showing. When I the select a child of the item, the item
loses focus, the whole thing is redrawn, and it looks fine.

Am I using the wrong method (OnItemExpanded) or something? I tried several
types of InvalidateRect to convince the control to redraw the selected item
with no luck.

TIA

jeff
-------------------------------------
Jeff Rucker
Software Systems Consulting
13641 Mercado Drive
Del Mar, CA 92014
(voice)619-481-3439 (fax)619-259-5554
jrucker@ssccorp.com
-------------------------------------



Mario Contestabile -- Mario_Contestabile.UOS__MTL@UOSMTL2.universal.com
Monday, March 10, 1997

[Mini-digest: 3 responses]

>I've got an SDI app with a splitter window, CTreeView in the left pane.
>Everything has been great until I added images for the tree items. I got
>the normal images to work fine, I was trying to get the Open folder/Closed
>folder type of image to work. I'm using OnItemExpanded to get the item when
>it is expanded/closed and there I change it's image appropriately. What I
>find is that if the item being expanded was _selected_ (single-click)
>before it was expanded (double-click), the image is not redrawn, leaving
>the closed folder showing. When I the select a child of the item, the item
>loses focus, the whole thing is redrawn, and it looks fine.

In your tree view's OnInitialUpdate handler, you can call
m_TreeCtrl.SetImageList(&m_ImageList, TVIS_NORMAL);
specifying that you will have an image for selected and non-selected items.
For example,
TreeCtrlItem.item.iSelectedImage = open_folder_image
TreeCtrlItem.item.iImage =  closed_folder_image

mcontest@universal.com

-----From: Robert Cobb 

You need to specify I_IMAGECALLBACK as the icon image when inserting a =
"folder" type item into the tree, implement a handler for the =
TVN_GETDISPINFO notification, and set the appropriate icon (folder open =
/ closed) in that handler.  [See help on CTreeCtrl::GetItem for =
I_IMAGECALLBACK details]

Example of TVN_GETDISPINFO handler:

void DRGTreeView::OnGetdispinfoTreeview(NMHDR* pNMHDR, LRESULT* pResult) =

{
    TV_DISPINFO* pTVDispInfo =3D (TV_DISPINFO*)pNMHDR;
    pTVDispInfo->item.iImage =3D (pTVDispInfo->item.state & =
TVIS_EXPANDED) ? IMG_FOLDER_OPEN : IMG_FOLDER_CLOSE;
    pTVDispInfo->item.iSelectedImage =3D (pTVDispInfo->item.state & =
TVIS_EXPANDED) ? IMG_FOLDER_OPEN : IMG_FOLDER_CLOSE;
=09
    *pResult =3D 0;
}

-Rob

----------
From: 	Jeff Rucker
Sent: 	 1997 Mar 06 16:26
To: 	mfc-l@netcom.com
Subject: 	CTreeCtrl Image draw problem


Environment: Win95, VC++ 4.1

I've got an SDI app with a splitter window, CTreeView in the left pane.
Everything has been great until I added images for the tree items. I got
the normal images to work fine, I was trying to get the Open =
folder/Closed
folder type of image to work. I'm using OnItemExpanded to get the item =
when
it is expanded/closed and there I change it's image appropriately. What =
I
find is that if the item being expanded was _selected_ (single-click)
before it was expanded (double-click), the image is not redrawn, leaving
the closed folder showing. When I the select a child of the item, the =
item
loses focus, the whole thing is redrawn, and it looks fine.

Am I using the wrong method (OnItemExpanded) or something? I tried =
several
types of InvalidateRect to convince the control to redraw the selected =
item
with no luck.

TIA

jeff
-------------------------------------
Jeff Rucker
Software Systems Consulting
13641 Mercado Drive
Del Mar, CA 92014
(voice)619-481-3439 (fax)619-259-5554
jrucker@ssccorp.com
-------------------------------------

-----From: Zafir Anjum 

This is what I do and it works fine. Note that each item has two images
associated with it.
The second image is used when the item is selected. Since I don't want the
images to be 
dependent on its selection state I specify the same image for selected as
well as unselected
item.

void COutline::OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;

	if( pNMTreeView->action == TVE_EXPAND ){
		SetItemImage( pNMTreeView->itemNew.hItem, OPEN_FOLDER, OPEN_FOLDER);
	}
	else if( pNMTreeView->action == TVE_COLLAPSE ){
		SetItemImage( pNMTreeView->itemNew.hItem, CLOSED_FOLDER, CLOSED_FOLDER);
	}

	*pResult = 0;
}


Hope this helps.
Zafir


At 01:26 PM 3/6/97 -0800, you wrote:
>
>Environment: Win95, VC++ 4.1
>
>I've got an SDI app with a splitter window, CTreeView in the left pane.
>Everything has been great until I added images for the tree items. I got
>the normal images to work fine, I was trying to get the Open folder/Closed
>folder type of image to work. I'm using OnItemExpanded to get the item when
>it is expanded/closed and there I change it's image appropriately. What I
>find is that if the item being expanded was _selected_ (single-click)
>before it was expanded (double-click), the image is not redrawn, leaving
>the closed folder showing. When I the select a child of the item, the item
>loses focus, the whole thing is redrawn, and it looks fine.
>
>Am I using the wrong method (OnItemExpanded) or something? I tried several
>types of InvalidateRect to convince the control to redraw the selected item
>with no luck.
>
>TIA
>
>jeff
>-------------------------------------
>Jeff Rucker
>Software Systems Consulting
>13641 Mercado Drive
>Del Mar, CA 92014
>(voice)619-481-3439 (fax)619-259-5554
>jrucker@ssccorp.com
>-------------------------------------
>





Become an MFC-L member | Вернуться в корень Архива |