?? leftview.cpp
字號:
/////////////////////////////////////////////////////////////////
// //
// LeftView.cpp //
//-------------------------------------------------------------//
// By Eugene Khodakovsky //
// April,2002 //
// Eugene@cpplab.com //
// Last Update: April, 2002 //
/////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Query.h"
#include "QueryDoc.h"
#include "LeftView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLeftView
IMPLEMENT_DYNCREATE(CLeftView, CFormView)
CLeftView::CLeftView()
: CFormView(CLeftView::IDD)
{
//{{AFX_DATA_INIT(CLeftView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CLeftView::~CLeftView()
{
}
void CLeftView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLeftView)
DDX_Control(pDX, IDC_TREE_CTRL, m_treeCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLeftView, CFormView)
//{{AFX_MSG_MAP(CLeftView)
ON_WM_SIZE()
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_CTRL, OnSelchangedTreeCtrl)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLeftView diagnostics
#ifdef _DEBUG
void CLeftView::AssertValid() const
{
CFormView::AssertValid();
}
void CLeftView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
CQueryDoc* CLeftView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CQueryDoc)));
return (CQueryDoc*)m_pDocument;
}
/////////////////////////////////////////////////////////////////////////////
// CLeftView message handlers
void CLeftView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
m_imageList.Create(IDB_IMAGELIST, 16, 0, RGB(255,0,255));
m_imageList.SetBkColor(GetSysColor(COLOR_WINDOW));
m_treeCtrl.SetImageList(&m_imageList,TVSIL_NORMAL);
PopulateTree();
SetSize();
}
void CLeftView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
SetSize();
}
void CLeftView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
switch (lHint)
{
default:
break;
case HINT_UPDATE_WINDOW: // redraw entire window
Invalidate(FALSE);
break;
case HINT_ON_QUERY_RESULT_READY:
{
UpdateData(FALSE);
}
break;
}
}
void CLeftView::SetSize()
{
if(!::IsWindow(m_treeCtrl.GetSafeHwnd()))
return;
const d = 5;
CRect rcClient,rcTree;
GetClientRect(rcClient);
rcTree = rcClient;
rcTree.DeflateRect(d,d);
m_treeCtrl.MoveWindow(rcTree);
}
void CLeftView::PopulateTree()
{
CConnectionProps& prop = ((CQueryApp*)AfxGetApp())->m_props;
m_treeCtrl.DeleteAllItems();
CTables tableSet;
HTREEITEM hDatabase =
m_treeCtrl.InsertItem(prop.m_strDatabaseName,IID_DATABASE,IID_DATABASES);
m_treeCtrl.SetItemData(hDatabase,TreeNode_RootDatabase);
HTREEITEM hTables =
m_treeCtrl.InsertItem(_T("Tables"),IID_TABLE,IID_TABLES,hDatabase);
m_treeCtrl.SetItemData(hTables,TreeNode_RootTables);
CString strType("TABLE");
if (tableSet.Open(*GetSession(), NULL, NULL, NULL, strType) != S_OK)
return;
while(tableSet.MoveNext() == S_OK)
{
HTREEITEM hItem = NULL;
if (_tcscmp(tableSet.m_szType, _T("VIEW")) == 0)
hItem = m_treeCtrl.InsertItem(tableSet.m_szName,IID_VIEW,IID_VIEWS,hTables);
else
hItem = m_treeCtrl.InsertItem(tableSet.m_szName,IID_TABLE,IID_TABLES,hTables);
m_treeCtrl.SetItemData(hItem,TreeNode_TableName);
}
UpdateWindow();
}
void CLeftView::OnSelchangedTreeCtrl(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
HTREEITEM hItem = pNMTreeView->itemNew.hItem;
TreeNodeType nodeType = TreeNode_None;
CString strText;
if(hItem != NULL)
{
nodeType = (TreeNodeType)m_treeCtrl.GetItemData(hItem);
strText = m_treeCtrl.GetItemText(hItem);
}
GetDocument()->OnSelectTreeNode(nodeType,strText);
*pResult = 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -