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

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


tree ctrl item highlighting during context menu

Keith Morgan -- keith@stellus.com
Wednesday, January 08, 1997

Environment: VC++ 4.2b, Win NT 4.0

I am trying to get right-click context menuing on an item-by-item basis for
a tree control but I can't seem to get the item highlighted while the menu
is displayed. I'm after the kind of behavior that Windows Explorer
exhibits: the rclicked item is highlighted while the menu is up and the
currently selected item temporarily loses its highlighting, but the context
menu operation does not change the selected item of the tree.

I am handling  WM_CONTEXTMENU (OnContextMenu) in a window with an
embedded tree control. I use CTreeCtrl::HitTest to get the current item and
CMenu::TrackPopupMenu to display the menu. Tree label editing is not
enabled. Everything seems to be working OK except the highlighting.

Things I have tried to get highlighting to work:
1) Run SelectItem(item) before the call to CMenu::TrackPopupMenu and
SelectItem(selItem) afterward. This results in an objectionable flashing of
the currently selected item when the right button goes up. Replacing
SelectItem(item) with SetItemState(item, TVIS_SELECTED, TVIS_SELECTED), etc
seems to produce the same results.

2) Similar to (1) but try to manually blt the items into submission. I get
the rects of the selected and rclick item labels, and run:

dc.PatBlt(rectSel.left, rectSel.top, rectSel.Width(), rectSel.Height(),
PATINVERT);
dc.PatBlt(rectItem.left, rectItem.top, rectItem.Width(), rectItem.Height(),
PATINVERT);

before and after the call to CMenu::TrackPopupMenu. This changes the right
regions of the window but the colors are wrong.

3) I have looked a bit at CTreeCtrl::GetEditCtrl() but it seems only to
apply to labels being edited and label editing is not enabled in my tree.

Any help appreciated.

Keith Morgan
Stellus Development Co.




K. V. Rammohan Rao -- kvrmrao@SierraOpt.com
Friday, January 10, 1997

[Mini-digest: 2 responses]

On 09 January 1997 04:32 Keith Morgan wrote,

>Environment: VC++ 4.2b, Win NT 4.0
>
>
>Things I have tried to get highlighting to work:
>1) Run SelectItem(item) before the call to CMenu::TrackPopupMenu and
>SelectItem(selItem) afterward. This results in an objectionable
>flashing of
>the currently selected item when the right button goes up. Replacing
>SelectItem(item) with SetItemState(item, TVIS_SELECTED, TVIS_SELECTED),
>etc
>seems to produce the same results.

Proably you are not updating your window within the RButtonDown()
handler. In that case shifting highlight to current item and again back
to selected item will occur when you come out of RButtonDown() hadler
resulting in flicker. To force it to paint immediately do the following

SelectItem(hItem);
CRect rect;
GetItemRect(hItem, &rect, TRUE);
InvalidateRect(&rect);
GetItemRect(hSelItem, &rect, TRUE);
InvalidateRect(&rect);
UpdateWindow();
//show PopUp menu etc.,
-----From: Masanori Iwasa 

>Environment: VC++ 4.2b, Win NT 4.0

I usually just do this in my constructor.

    //- Don't allow auto menu, because we'll be using our own.
    m_bAutoMenuEnable = FALSE;

Masa
>

>I am trying to get right-click context menuing on an item-by-item basis
>for
>a tree control but I can't seem to get the item highlighted while the
>menu
>is displayed. I'm after the kind of behavior that Windows Explorer
>exhibits: the rclicked item is highlighted while the menu is up and the
>currently selected item temporarily loses its highlighting, but the
>context
>menu operation does not change the selected item of the tree.
>
>I am handling  WM_CONTEXTMENU (OnContextMenu) in a window with an
>embedded tree control. I use CTreeCtrl::HitTest to get the current item
>and
>CMenu::TrackPopupMenu to display the menu. Tree label editing is not
>enabled. Everything seems to be working OK except the highlighting.
>
>Things I have tried to get highlighting to work:
>1) Run SelectItem(item) before the call to CMenu::TrackPopupMenu and
>SelectItem(selItem) afterward. This results in an objectionable
>flashing of
>the currently selected item when the right button goes up. Replacing
>SelectItem(item) with SetItemState(item, TVIS_SELECTED, TVIS_SELECTED),
>etc
>seems to produce the same results.
>
>2) Similar to (1) but try to manually blt the items into submission. I
>get
>the rects of the selected and rclick item labels, and run:
>
>dc.PatBlt(rectSel.left, rectSel.top, rectSel.Width(), rectSel.Height(),
>PATINVERT);
>dc.PatBlt(rectItem.left, rectItem.top, rectItem.Width(),
>rectItem.Height(),
>PATINVERT);
>
>before and after the call to CMenu::TrackPopupMenu. This changes the
>right
>regions of the window but the colors are wrong.
>
>3) I have looked a bit at CTreeCtrl::GetEditCtrl() but it seems only to
>apply to labels being edited and label editing is not enabled in my
>tree.
>
>Any help appreciated.
>
>Keith Morgan
>Stellus Development Co.
>
>



Dong Chen -- d_chen@ix.netcom.com
Saturday, January 11, 1997


Is this a feature given for free by MFC's CListView? Or I might
misunderstand your question. Anyway, here is what works for me.

in declaration:
void OnRightClick(NMHDR *pNotifyStruct,LRESULT *result);

in message map:
ON_NOTIFY_REFLECT(NM_RCLICK,OnRightClick)

and defined as:
void CMyTreeView::OnRightClick(NMHDR *pNotifyStruct,LRESULT *result)
{
	CPoint curPoint;
	GetCursorPos(&curPoint);
	ScreenToClient(&curPoint);
	CMenu popMenu;
	CPoint posMouse;

	popMenu.LoadMenu(IDR_MENU1);
	GetCursorPos(&posMouse);
                popMenu.GetSubMenu(0) ->TrackPopupMenu(
0,posMouse.x,posMouse.y,this);

	*result = 0;
}

Oh, just noticed you are running under NT4.0 while I am at Windows 95.
Good luck.
--
Dong
d_chen@ix.netcom.com





| Вернуться в корень Архива |