www.gusucode.com > VC++编写的SQL服务端和客户端源码程序 > VC++编写的SQL服务端和客户端源码程序\code\Server\FileTree.cpp
// FileTree.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "miniSQL.h" #include "FileTree.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CFileTree CFileTree::CFileTree() { } CFileTree::~CFileTree() { } BEGIN_MESSAGE_MAP(CFileTree, CTreeCtrl) //{{AFX_MSG_MAP(CFileTree) ON_WM_RBUTTONDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFileTree message handlers void CFileTree::SetMenuID(UINT nID1, UINT nID2) { m_menuID1 = nID1; m_menuID2 = nID2; } UINT CFileTree::GetMenuID(int num) { if( num == 1 ) return m_menuID1; if( num == 2 ) return m_menuID2; return 0; } void CFileTree::OnRButtonDown(UINT nFlags, CPoint point) { CTreeCtrl::OnRButtonUp(nFlags, point); HTREEITEM hItem = HitTest(point, &nFlags); CTreeCtrl::Select( hItem, TVGN_CARET ); CRect Rect; GetItemRect(hItem, Rect, TRUE); if( point.x>=Rect.left && point.x<=Rect.right ) { GetClientRect(Rect); ClientToScreen(Rect); point.Offset(Rect.TopLeft()); CMenu menu; if( !GetParentItem( hItem ) ) //VERIFY(menu.LoadMenu(m_menuID1)); return ; else if( !GetParentItem( GetParentItem( hItem ) ) ) VERIFY(menu.LoadMenu(m_menuID2)); else return; 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); } }