www.pudn.com > ODBCApi.rar > TableEditTreeCtrl.cpp


// TableEditTreeCtrl.cpp : 实现文件 
// 
 
#include "stdafx.h" 
#include "DataManager.h" 
#include "TableEditTreeCtrl.h" 
#include ".\tableedittreectrl.h" 
#include "MainFrm.h" 
#include "DataManagerView.h" 
 
#define ID_TABLE_MODIFY 1001 
#define ID_TABLE_ADD 1002 
#define ID_TABLE_DELETE 1003 
#define ID_TABLE_QUERY 1004 
#define ID_ICON_MAX 1005 
#define ID_ICON_MIN 1006 
 
// CTableEditTreeCtrl 
IMPLEMENT_DYNAMIC(CTableEditListCtrl, CListCtrl) 
CTableEditListCtrl::CTableEditListCtrl() 
{ 
	m_menuItem.m_hMenu = NULL; 
	m_menuMain.m_hMenu = NULL; 
} 
 
CTableEditListCtrl::~CTableEditListCtrl() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CTableEditListCtrl, CListCtrl) 
	ON_WM_CREATE() 
	ON_NOTIFY_REFLECT(NM_RCLICK, OnNMRclick) 
	ON_BN_CLICKED(ID_TABLE_MODIFY, OnTableModify) 
	ON_BN_CLICKED(ID_TABLE_QUERY, OnTableQuery) 
	ON_BN_CLICKED(ID_TABLE_ADD, OnTableAdd) 
	ON_BN_CLICKED(ID_TABLE_DELETE, OnTableDelete) 
	ON_BN_CLICKED(ID_ICON_MAX, OnIconMax) 
	ON_BN_CLICKED(ID_ICON_MIN, OnIconMin) 
END_MESSAGE_MAP() 
 
void CTableEditListCtrl::OnTableModify() 
{ 
	MessageBox("OnTableModify"); 
} 
 
void CTableEditListCtrl::OnTableQuery() 
{ 
	MessageBox("OnTableQuery"); 
} 
 
// CTableEditTreeCtrl 消息处理程序 
 
 
int CTableEditListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{ 
	if (CListCtrl::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	if(m_menuItem.m_hMenu == NULL) 
	{ 
		m_menuItem.CreatePopupMenu(); 
		m_menuItem.AddSideBar(new CMenuXPSideBar(24, "表格")); 
		m_menuItem.AppendXPMenu(0, new CMenuXPText(ID_TABLE_MODIFY, "&设计表", AfxGetApp()->LoadIcon(IDI_ICON1))); 
		m_menuItem.AppendXPMenu(0, new CMenuXPText(ID_TABLE_QUERY, "&打开表", AfxGetApp()->LoadIcon(IDI_ICON2))); 
		m_menuItem.AppendXPMenu(0, new CMenuXPText(ID_TABLE_ADD, "&新建表", AfxGetApp()->LoadIcon(IDI_ICON1))); 
		m_menuItem.AppendXPMenu(0, new CMenuXPText(ID_TABLE_DELETE, "&删除表", AfxGetApp()->LoadIcon(IDI_ICON2))); 
		SetMenu(&m_menuItem); 
	} 
	if(m_menuMain.m_hMenu == NULL) 
	{ 
		m_menuMain.CreatePopupMenu(); 
		m_menuMain.AddSideBar(new CMenuXPSideBar(24, "操作")); 
		m_menuMain.AppendXPMenu(0, new CMenuXPText(ID_TABLE_ADD, "&新建表", AfxGetApp()->LoadIcon(IDI_ICON1))); 
		m_menuMain.AppendXPMenu(0,new CMenuXPSeparator()); 
		m_menuMain.AppendXPMenu(0, new CMenuXPText(ID_ICON_MAX, "&大图标", AfxGetApp()->LoadIcon(IDI_ICON3))); 
		m_menuMain.AppendXPMenu(0, new CMenuXPText(ID_ICON_MIN, "&小图标", AfxGetApp()->LoadIcon(IDI_ICON4))); 
		SetMenu(&m_menuMain); 
	} 
 
	return 0; 
} 
 
void CTableEditListCtrl::OnNMRclick(NMHDR *pNMHDR, LRESULT *pResult) 
{	 
	LPNMLISTVIEW lpListView = (LPNMLISTVIEW)pNMHDR; 
	CPoint pt; 
	GetCursorPos(&pt); 
	if(lpListView->iItem!=-1) 
	{ 
		if(m_menuItem.m_hMenu != NULL) 
		{ 
			m_menuItem.TrackPopupMenu(TPM_RIGHTBUTTON,pt.x,pt.y,this,0); 
		} 
	} 
	else 
	{ 
		if(m_menuMain.m_hMenu != NULL) 
		{ 
			m_menuMain.TrackPopupMenu(TPM_RIGHTBUTTON,pt.x,pt.y,this,0); 
		} 
	} 
} 
void CTableEditListCtrl::OnIconMax() 
{ 
	if(m_hWnd) 
	{ 
		ModifyStyle(LVS_SMALLICON, LVS_ICON|LVS_ALIGNLEFT); 
	} 
} 
void CTableEditListCtrl::OnIconMin() 
{ 
	if(m_hWnd) 
	{ 
		ModifyStyle(LVS_ICON, LVS_SMALLICON|LVS_ALIGNLEFT); 
	} 
} 
 
void CTableEditListCtrl::OnTableAdd() 
{ 
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd(); 
	if(pMainWnd==NULL) 
	{ 
		MessageBox("OnTableAdd errors!"); 
		return ; 
	} 
	CDataManagerView* pDataManagerView = (CDataManagerView*)pMainWnd->GetActiveView(); 
	if(pDataManagerView==NULL) 
	{ 
		MessageBox("OnTableAdd errors!"); 
		return ; 
	} 
	CRect rcClient; 
	if(m_tableAddDlg.m_hWnd==NULL) 
	{ 
		m_tableAddDlg.Create(IDD_DLG_TABLEADD, pDataManagerView); 
		pDataManagerView->GetClientRect(rcClient); 
		m_tableAddDlg.MoveWindow(0, 0, rcClient.Width()+200, rcClient.Height()+100); 
	} 
	if(m_tableAddDlg.m_hWnd!=NULL) 
	{	 
		m_tableAddDlg.ShowWindow(true); 
	} 
} 
 
void CTableEditListCtrl::OnTableDelete() 
{ 
}