?? rtreview.cpp
字號:
// this function implements that type of comparison. Users who
// need a different comparison should derive a class and override
// this function.
//
int CRTreView::SortCompare(LPARAM item1LParam, LPARAM item2LParam)
{
ASSERT(item1LParam && item2LParam);
ASSERT(GetItemHandle(item1LParam) && GetItemHandle(item2LParam));
return GetTreeCtrl().GetItemText(GetItemHandle(item1LParam) )
.Compare(
GetTreeCtrl().GetItemText(GetItemHandle(item2LParam) ));
}
//////////
// OnInitialUpdate() function of MFC Doc/View Architecture.
//
void CRTreView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
// TODO: You may populate your TreeView with items by directly accessing
// its tree control through a call to GetTreeCtrl().
}
//////////
// OnUpdate() function of MFC Doc/View Architecture.
//
void CRTreView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
switch(lHint)
{
case CRTreHint::documentIsOpen:
{
GetTreeCtrl().DeleteAllItems();
Populate_(GetDocument()->m_pRootItem, TVI_ROOT);
TV_SORTCB sortCB;
sortCB.hParent = GetTreeCtrl().GetRootItem();
sortCB.lpfnCompare = CRTreViewCompare;
sortCB.lParam = reinterpret_cast<LPARAM>(this);
GetTreeCtrl().SortChildrenCB(&sortCB);
break;
}
default:
break;
}
}
//////////
// Populate_() function called from OnUpdate()
//
void CRTreView::Populate_(CTreeItem* item, HTREEITEM parent)
{
TV_INSERTSTRUCT insert;
::ZeroMemory(&insert, sizeof insert);
insert.hParent = parent;
insert.hInsertAfter = TVI_LAST;
insert.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
insert.item.pszText = const_cast<TCHAR*>((LPCTSTR)(item->m_szName));
insert.item.lParam = reinterpret_cast<LPARAM>(item);
insert.item.cChildren = item->m_childrenItems.GetSize();
insert.item.iSelectedImage = insert.item.iImage = item->m_nType; //image idx by type
/*
if (item->m_szType == "www")
insert.item.iSelectedImage = insert.item.iImage = IMAGELIST_WWW;
else
if (item->m_szType == "host")
insert.item.iSelectedImage = insert.item.iImage = IMAGELIST_HOST;
else
if (item->m_szType == "document")
insert.item.iSelectedImage = insert.item.iImage = IMAGELIST_DOCUMENT;
else
ASSERT(0);
*/
insert.hParent = GetTreeCtrl().InsertItem(&insert);
ASSERT(insert.hParent);
for (int index = 0; index < insert.item.cChildren; index++)
{
CTreeItem* child = item->m_childrenItems.GetAt(index);
Populate_(child, insert.hParent);
}
GetTreeCtrl().Expand(insert.hParent, TVE_EXPAND);
}
//////////
// OnShowHandlesAndLParams() function handles the command to
// show all the HTREEITEM handles and the TVI_ITEM.lParam values
// for the items in the TreeView control.
//
/*TPMTPMTPM
void CRTreView::OnShowHandlesAndLParams()
{
m_bShowHandlesAndLParams = ! m_bShowHandlesAndLParams;
ApplyIfTrue_ ( CRTreView::TruePredicate_,
CRTreView::ShowHandleAndLParam_,
m_bShowHandlesAndLParams,
TVI_ROOT );
}
//////////
// OnUpdateShowHandlesAndLParams() function enables the menu.
//
void CRTreView::OnUpdateShowHandlesAndLParams(CCmdUI* pCmdUI)
{
pCmdUI->Enable(TRUE);
pCmdUI->SetCheck(m_bShowHandlesAndLParams);
}
*/
//////////
// OnViewGetItemHandleDialog() function invokes a dialog allowing
// the user to pick a single LPARAM from a list of LPARAM values
// in the TreeView. Then it locates the user's choice in the TreeView
// and selects that choice.
//
/*
void CRTreView::OnViewGetItemHandleDialog()
{
CChooseLPARAMDialog dlog;
CDWordArray arrayOfTreeViewLParams;
ApplyIfTrue_ ( CRTreView::TruePredicate_,
CRTreView::SaveItemsLParams_,
reinterpret_cast<DWORD>(& arrayOfTreeViewLParams),
TVI_ROOT );
dlog.m_pArrayOfTreeViewLParams = & arrayOfTreeViewLParams;
if (dlog.DoModal() == IDOK)
{
GetTreeCtrl().GetFocus();
if (dlog.m_selectedTreeViewLParam)
{
HTREEITEM candidate = GetItemHandle(dlog.m_selectedTreeViewLParam);
if (candidate)
{
VERIFY(GetTreeCtrl().SelectItem(candidate));
VERIFY(GetTreeCtrl().SetItemState(candidate,
TVIS_SELECTED, TVIS_SELECTED));
}
}
}
}
TPMTPMTPM*/
//////////
//
//
/*
void CRTreView::OnUpdateViewGetItemHandleDialog(CCmdUI* pCmdUI)
{
pCmdUI->Enable();
}
TPMTPMTPM*/
//////////
//
//
BOOL CRTreView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= TVS_HASBUTTONS | TVS_HASLINES;
return CTreeView::PreCreateWindow(cs);
}
//////////
//
//
void CRTreView::OnDraw(CDC* pDC)
{
CRTreDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
}
//////////
//
//
int CRTreView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CTreeView::OnCreate(lpCreateStruct) == -1)
return -1;
//VERIFY(m_imageList.Create(IDB_USB_DEVS,16,1,RGB(255,255,255)));
VERIFY(m_imageList.Create(IDB_USB_ICO,16,1,RGB(255,255,255)));
GetTreeCtrl().SetImageList(&m_imageList, TVSIL_NORMAL);
return 0;
}
//////////
// CRTreView diagnostics
//
#ifdef _DEBUG
void CRTreView::AssertValid() const
{
CTreeView::AssertValid();
}
void CRTreView::Dump(CDumpContext& dc) const
{
CTreeView::Dump(dc);
}
CRTreDoc* CRTreView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRTreDoc)));
return (CRTreDoc*)m_pDocument;
}
#endif //_DEBUG
void CRTreView::OnRButtonDown(UINT nFlags, CPoint point)
{
UINT uFlags;
HTREEITEM htItem = GetTreeCtrl().HitTest(point, &uFlags);
if((htItem!= NULL) && (uFlags& TVHT_ONITEM))
{
m_pOldSel = GetTreeCtrl().GetSelectedItem();
GetTreeCtrl().Select(htItem, TVGN_DROPHILITE);
}
CTreeView::OnRButtonDown(nFlags, point);
}
void CRTreView::OnRButtonUp(UINT nFlags, CPoint point)
{
UINT uFlags;
HTREEITEM htItem = GetTreeCtrl().HitTest(point, &uFlags);
if((htItem!= NULL) && (uFlags& TVHT_ONITEM))
GetTreeCtrl().Select(htItem, TVGN_DROPHILITE);
CTreeView::OnRButtonUp(nFlags, point);
}
void CRTreView::OnLButtonDown(UINT nFlags, CPoint point)
{
UINT uFlags;
HTREEITEM htItem = GetTreeCtrl().HitTest(point, &uFlags);
if((htItem!= NULL) && (uFlags& TVHT_ONITEM))
GetTreeCtrl().Select(htItem, TVGN_DROPHILITE);
CTreeView::OnLButtonDown(nFlags, point);
}
void CRTreView::OnContextMenu(CWnd* pWnd, CPoint point)
{
UINT uFlags;
CTreeCtrl& treeCtrl = GetTreeCtrl();
CPoint ptTree = point;
treeCtrl.ScreenToClient(&ptTree);
HTREEITEM htItem = treeCtrl.HitTest(ptTree, &uFlags);
if ((htItem != NULL) && (uFlags & TVHT_ONITEM))
{
ShowPopupMenu( point );
treeCtrl.SetItemState(htItem, 0, TVIS_DROPHILITED);
}
else
CTreeView::OnContextMenu(pWnd, point);
if (m_pOldSel != NULL)
{
treeCtrl.Select(m_pOldSel, TVGN_DROPHILITE);
m_pOldSel = NULL;
}
}
void CRTreView::ShowPopupMenu( CPoint& point )
{
if (point.x == -1 && point.y == -1)
{ //keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
point = rect.TopLeft();
point.Offset(5, 5);
}
CMenu menu;
VERIFY(menu.LoadMenu(IDR_EZMRTYPE));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -