📄 tablelist.cpp
字号:
// TableList.cpp : implementation file
//
#include "stdafx.h"
#include "VDB.h"
#include "TableList.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTableList
IMPLEMENT_DYNCREATE(CTableList, CListView)
CTableList::CTableList()
{
}
CTableList::~CTableList()
{
}
BEGIN_MESSAGE_MAP(CTableList, CListView)
//{{AFX_MSG_MAP(CTableList)
ON_WM_LBUTTONDBLCLK()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTableList drawing
void CTableList::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CTableList diagnostics
#ifdef _DEBUG
void CTableList::AssertValid() const
{
CListView::AssertValid();
}
void CTableList::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTableList message handlers
BOOL CTableList::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
cs.style |= WS_HSCROLL | WS_VSCROLL | LVS_SHAREIMAGELISTS;
return CListView::PreCreateWindow(cs);
}
void CTableList::OnInitialUpdate()
{
CListView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CListCtrl& ListCtrl = GetListCtrl();
if (!(list.Create(IDB_BIG_DB, 32, 1, RGB(0, 255, 0))))
AfxMessageBox("图像列表创建出错!");
ListCtrl.SetImageList(&list, TVSIL_NORMAL);
ListCtrl.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
}
void CTableList::ViewStringList(CStringList *pSL)
{
CListCtrl& ListCtrl = GetListCtrl();
ListCtrl.LockWindowUpdate();
ListCtrl.DeleteAllItems();
POSITION pos;
int iIndex;
if (pSL->GetCount() < 2) return;
while(ListCtrl.DeleteColumn(0));
CString sStr, sSet;
// 设置列头文字
pos = pSL->GetHeadPosition();
sStr = pSL->GetAt(pos) + ',';
int iA, iB, iColWidth, iCol, iItem, iIcon;
iIndex = 0;
iA = iB = 0;
iA = sStr.Find(',', 0);
while(iA != -1)
{
sSet = sStr.Mid(iB, iA - iB);
ListCtrl.InsertColumn(iIndex, sSet, LVCFMT_LEFT);
iB = iA + 1;
iA = sStr.Find(',', iA + 1);
iIndex ++;
};
// 设置列宽
pSL->GetNext(pos);
sStr = pSL->GetNext(pos) + ',';
iIndex = 0;
iA = iB = 0;
iA = sStr.Find(',', 0);
while(iA != -1)
{
sSet = sStr.Mid(iB, iA - iB);
sscanf(sSet, "%d", &iColWidth);
ListCtrl.SetColumnWidth(iIndex, iColWidth);
iB = iA + 1;
iA = sStr.Find(',', iA + 1);
iIndex ++;
};
// 填充内容
for (; pos != NULL; )
{
sStr = pSL->GetNext(pos) + ',';
iA = iB = 0;
iA = sStr.Find(',', 0);
if (iA != -1)
{
sSet = sStr.Mid(iB, iA - iB);
sscanf(sSet, "%d", &iIcon);
iB = iA + 1;
iA = sStr.Find(',', iA + 1);
}
if (iA != -1)
{
sSet = sStr.Mid(iB, iA - iB);
iItem = ListCtrl.InsertItem(iIndex, sSet, iIcon);
iB = iA + 1;
iA = sStr.Find(',', iA + 1);
}
iCol = 1;
while(iA != -1)
{
sSet = sStr.Mid(iB, iA - iB);
ListCtrl.SetItemText(iItem, iCol, sSet);
iB = iA + 1;
iA = sStr.Find(',', iA + 1);
iCol ++;
};
iIndex ++;
}
ListCtrl.UnlockWindowUpdate();
}
void CTableList::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMainFrame* pMain = (CMainFrame *) AfxGetMainWnd();
CTreeCtrl& TreeCtrl = ((CTreeView *)pMain->m_wndSplitter.GetPane(0, 0))->GetTreeCtrl();
CListCtrl& ListCtrl = GetListCtrl();
int nSel = ListCtrl.HitTest(point);
if (nSel == -1)
return;
HTREEITEM hItem;
hItem = TreeCtrl.GetChildItem(TreeCtrl.GetSelectedItem());
for (int i = 0; i < nSel; i ++)
{
hItem = TreeCtrl.GetNextItem(hItem, TVGN_NEXT);
}
TreeCtrl.SelectItem(hItem);
TreeCtrl.Expand(hItem, TVE_EXPAND);
CListView::OnLButtonDblClk(nFlags, point);
}
void CTableList::OnSize(UINT nType, int cx, int cy)
{
CListView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CListCtrl& ListCtrl = GetListCtrl();
ListCtrl.Arrange(LVA_DEFAULT);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -