📄 superview.cpp
字号:
// SuperView.cpp : 实现文件
//
#include "stdafx.h"
#include "WspProcess.h"
#include "SuperView.h"
#include "EachItemDoc.h"
#include "CurveView.h"
// CSuperView
IMPLEMENT_DYNCREATE(CSuperView, CFormView)
CSuperView::CSuperView()
: CFormView(CSuperView::IDD)
// , ddfff(0)
{
lima.Create(IDB_ARANLIST, 16, 0, RGB(255,0,255));
limah.Create(IDB_ARANCOL, 11, 0, RGB(255,0,255));
ftTimes.CreatePointFont(90, "Times New Roman");
}
CSuperView::~CSuperView()
{
}
void CSuperView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSuperGrid1View)
DDX_Control(pDX, IDC_DATALIST, m_wndList);
//}}AFX_DATA_MAP
}
/////////////////////////////////////////////////////////////////////////////
// CSuperView printing
BOOL CSuperView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSuperView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
m_wndList.SetPrintFlag(ptUseColor|ptUseFonts|ptListName|ptPageNumbers|ptPageDate);
m_wndList.SetPrintName("here's the data name");
m_wndList.SetMargins(15,10,10,10);
m_wndList.OnBeginPrinting(pDC, pInfo);
}
void CSuperView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
m_wndList.OnEndPrinting(pDC, pInfo);
}
void CSuperView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
m_wndList.OnPrint(pDC, pInfo);
}
BEGIN_MESSAGE_MAP(CSuperView, CFormView)
//{{AFX_MSG_MAP(CSuperView)
ON_NOTIFY(LVN_GETDISPINFO, IDC_DATALIST, OnGetdispinfoList)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_DATALIST, OnItemchangedList)
ON_WM_SIZE()
ON_MESSAGE(WM_LISTEX_NOTIFY, OnListExNotify)
ON_COMMAND(ID_TESTCAT, OnTestcat)
ON_UPDATE_COMMAND_UI(ID_TESTCAT, OnUpdateTestcat)
ON_COMMAND(ID_DRAGGABLECOL, OnDraggablecol)
ON_UPDATE_COMMAND_UI(ID_DRAGGABLECOL, OnUpdateDraggablecol)
ON_COMMAND(ID_GRIDH, OnGridh)
ON_UPDATE_COMMAND_UI(ID_GRIDH, OnUpdateGridh)
ON_COMMAND(ID_GRIDV, OnGridv)
ON_UPDATE_COMMAND_UI(ID_GRIDV, OnUpdateGridv)
ON_COMMAND(ID_TESTDAO, OnTestdao)
ON_UPDATE_COMMAND_UI(ID_TESTDAO, OnUpdateTestdao)
//}}AFX_MSG_MAP
ON_WM_DESTROY()
END_MESSAGE_MAP()
// CSuperView 诊断
#ifdef _DEBUG
void CSuperView::AssertValid() const
{
CFormView::AssertValid();
}
void CSuperView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
// CSuperView 消息处理程序
void CSuperView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
CRealTime *pGraph = &(((CEachItemDoc*)GetDocument())->m_graph);
CString cs;
cs.Format("%.4f", pGraph->m_cLines[0].m_dNowValue);
m_wndList.SetItemText(0 , 5, cs);
cs.Format("%.4f", pGraph->m_cLines[0].m_dMin);
m_wndList.SetItemText(0 , 6, cs);
cs.Format("%.4f", pGraph->m_cLines[0].m_dMax);
m_wndList.SetItemText(0 , 7, cs);
m_wndList.UpdateWindow();
}
void CSuperView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
CGfxColumnManager *pManager = m_wndList.CreateColumnManager();
//定义列标题属性集
pManager->DefineColumn(0, _T(""), NULL, LVCFMT_LEFT, 0, fhNoSortArrow | fhNoResizeColumn);
pManager->DefineColumn(1, _T(""), NULL, LVCFMT_LEFT, 60, fhNoSortArrow);
pManager->DefineColumn(2, _T("Color"), NULL, LVCFMT_LEFT, 60, fhNoSortArrow);
pManager->DefineColumn(3, _T("Name"), NULL, LVCFMT_LEFT, 120, fhNoSortArrow);
pManager->DefineColumn(4, _T("Description"), NULL, LVCFMT_LEFT, 120, fhNoSortArrow);
pManager->DefineColumn(5, _T("Unit"), NULL, LVCFMT_LEFT, 120, fhNoSortArrow);
pManager->DefineColumn(6, _T("Now Value"), NULL, LVCFMT_LEFT, 120, fhEdit|fhSortAble | fhValute);
pManager->DefineColumn(7, _T("Minimum"), NULL, LVCFMT_LEFT, 120, fhNoSortArrow | fhSortAble | fhValute);
pManager->DefineColumn(8, _T("Maximum"), NULL, LVCFMT_LEFT, 120, fhNoSortArrow | fhSortAble | fhValute);
pManager->DefineColumn(9, _T("Scaled Min"), NULL, LVCFMT_LEFT, 120, fhNoSortArrow | fhValute);
pManager->DefineColumn(10, _T("Scaled Max"), NULL, LVCFMT_LEFT, 120, fhNoSortArrow | fhValute);
//按_DEFCOLS定义的各列特征,定义各列的显示顺序及其特征
int _DEFCOLS[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
pManager->DefineDefaultColumns(sizeof(_DEFCOLS)/sizeof(int), _DEFCOLS);
//读配置文件配置列标题数据集
// pManager->ReadFromProfile("WspProcessList");
//设置列表控件的图像列表
m_wndList.SetItemImageList(&lima);
//设置列表控件相关的列标题控件的图像列表
m_wndList.SetHeaderImageList(&limah);
m_wndList.OnInit();
m_wndList.ModifyFlag(0,fHighRowSelect|fVertGrid|fHorizGrid|fAutoSort,0);
m_wndList.SetupColumnData();
m_wndList.SetItemCount(20);
CRealTime *pGraph = &(((CEachItemDoc*)GetDocument())->m_graph);
int nCount = pGraph->m_cLines.GetCount();
for (int t = 0; t < nCount; t++)
m_wndList.InsertItemEx(t,t);
m_wndList.SetItemHeight(17);
m_wndList.SetCategoryCallback((void (CWnd::*)(CGfxCategoryManager* , long&))CategoryCallBack);
m_wndList.SetGetTextCallback((void (CWnd::*)(int , int, long, CString&)) GetTextCallback);
m_wndList.SetExInfoCallback((long (CWnd::*)(LXHDREX *))GetExInfoCallback);
CRect rect;
GetClientRect(rect);
int cx = rect.Width();
int cy = rect.Height();
m_wndList.SetWindowPos(0,2,2,cx-4,cy-4,SWP_NOZORDER);
}
void CSuperView::CategoryCallBack(CGfxCategoryManager *pCatMan, long &lData)
{
long value = lData;
int iCat = pCatMan->FindCategory(value);
if (iCat < 0)
{
CString cs;/*
long val1 = value / 20;
val1 *= 20;
long val2 = val1 + 20;*/
long val1 = value / 5;
val1 *= 5;
long val2 = val1 + 5;
cs.Format("%d - %d", val1, val2);
iCat = pCatMan->AddCategory(cs, val1, val2);
}
if (iCat >= 0)
{
pCatMan->AddItemToCategory(iCat, value);
}
}
void CSuperView::GetTextCallback(int iIndex, int iSubItem, long lCode, CString &cs)
{
CRealTime *pGraph = &(((CEachItemDoc*)GetDocument())->m_graph);
int rc = m_wndList.GetColumnIndex(iSubItem);
CGfxCategoryManager *pCategoryManager = m_wndList.GetCategoryManager();
if (pCategoryManager)
{
if(rc > 0)
{
long value = m_wndList.GetItemData(iIndex);
int nCat = pCategoryManager->FindCategory(value);
for(int i = 0; i < nCat; i++)
{
iIndex -= 1;
if(! pCategoryManager->pCategory[i].bExpanded)iIndex += pCategoryManager->pCategory[i].iItems;
}
iIndex -= 1;
}
}
switch(rc)
{
case 0:
cs = _T("");break;
case 1:
cs.Format("%d", iIndex);break;
case 2:
cs.Format("%d", pGraph->m_cLines[iIndex].m_nColor);break;
case 3:
cs = pGraph->m_cLines[iIndex].m_sName;break;
case 4:
cs = pGraph->m_cLines[iIndex].m_sDescription;break;
case 5:
cs = pGraph->m_cLines[iIndex].m_sUnit;break;
case 6:
cs.Format("%.2f", pGraph->m_cLines[iIndex].m_dNowValue);break;
case 7:
cs.Format("%.f", pGraph->m_cLines[iIndex].m_dMin);break;
case 8:
cs.Format("%.f", pGraph->m_cLines[iIndex].m_dMax);break;
case 9:
cs.Format("%.f", pGraph->m_cLines[iIndex].m_dScaleLow);break;
case 10:
cs.Format("%.f", pGraph->m_cLines[iIndex].m_dScaleHigh);break;
default:
break;
}
}
long CSuperView::GetExInfoCallback(LXHDREX * pLx)
{
ASSERT(pLx);
switch(pLx->iNotifyCode)
{
case NTEX_ITEMINFO:
return 1L;break;
case NTEX_SETTEXT:
{
CRealTime *pGraph = &(((CEachItemDoc*)GetDocument())->m_graph);
int iIndex = pLx->iItem;
int rc = pLx->iSubItem;
CGfxCategoryManager *pCategoryManager = m_wndList.GetCategoryManager();
if (pCategoryManager)
{
if(rc > 0)
{
long value = m_wndList.GetItemData(iIndex);
int nCat = pCategoryManager->FindCategory(value);
for(int i = 0; i < nCat; i++)
{
iIndex -= 1;
if(! pCategoryManager->pCategory[i].bExpanded)iIndex += pCategoryManager->pCategory[i].iItems;
}
iIndex -= 1;
}
}
if(rc == 6)
{
double newValue = atof(pLx->csText);
double oldValue = pGraph->m_cLines[iIndex].m_dNowValue;
if(newValue == 0 && oldValue != 0)
;
else
pGraph->m_cLines[iIndex].m_dNowValue = newValue;
}
return 1L;break;
}
default:
return 0L;
}
}
void CSuperView::OnGetdispinfoList(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
*pResult = 0;
long index = pDispInfo->item.iItem;
long subItem = pDispInfo->item.iSubItem;
long objCode = pDispInfo->item.lParam;
if(pDispInfo->item.mask & LVIF_TEXT)
{
CString cs;
GetTextCallback(index, subItem, objCode, cs);
lstrcpyn(pDispInfo->item.pszText, cs, pDispInfo->item.cchTextMax);
*pResult = 1;
}
if(pDispInfo->item.mask & LVIF_IMAGE) pDispInfo->item.iImage = 0;//set image to first in list
}
void CSuperView::OnItemchangedList(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CSuperView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
//设置列表控件位置、尺寸、Z-order
if(m_wndList.GetSafeHwnd())
m_wndList.SetWindowPos(0,2,2,cx-4,cy-4,SWP_NOZORDER);
//CWnd::GetSafeHwnd获取窗口句柄
//SWP_NOZORDER保留原有Z轴次序
//调整视图的滚动特性
SetScrollSizes(MM_TEXT, CSize(cx,cy));
}
LRESULT CSuperView::OnListExNotify(WPARAM wParam, LPARAM lParam)
{
LXHDREX * pLx = (LXHDREX *) lParam;
ASSERT(pLx);
switch(pLx->iNotifyCode)
{
case NTEX_ITEMINFO:
return 1L;break;
case NTEX_COMBOREQUEST:
return 1L;break;
case NTEX_SETTEXT:
m_wndList.SetItemText(pLx->iItem, pLx->iSubItem, pLx->csText);
return 1L;
};
return 0L;
}
void CSuperView::OnDestroy()
{
if(m_wndList.GetCategoryManager())
m_wndList.EnableCategoryView(false);
CGfxColumnManager *pManager = m_wndList.GetColumnManager();
pManager->RetrieveColumnData(&m_wndList);
// pManager->WriteToProfile("WspProcessList");
CFormView::OnDestroy();
}
void CSuperView::OnTestcat()
{
if (m_wndList.GetCategoryManager()) m_wndList.EnableCategoryView(false);
else m_wndList.EnableCategoryView(true);
}
void CSuperView::OnUpdateTestcat(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_wndList.GetCategoryManager() != NULL);
}
void CSuperView::OnDraggablecol()
{
m_wndList.EnableColumnDrag(! m_wndList.IsColumnDragEnabled());
}
void CSuperView::OnUpdateDraggablecol(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_wndList.IsColumnDragEnabled());
}
void CSuperView::OnGridh()
{
if (m_wndList.GetFlag() & fHorizGrid) m_wndList.ModifyFlag(fHorizGrid, 0, 0);
else m_wndList.ModifyFlag(0, fHorizGrid, 0);
Invalidate();
}
void CSuperView::OnUpdateGridh(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_wndList.GetFlag() & fHorizGrid ? 1 : 0);
}
void CSuperView::OnGridv()
{
if (m_wndList.GetFlag() & fVertGrid) m_wndList.ModifyFlag(fVertGrid, 0, 0);
else m_wndList.ModifyFlag(0, fVertGrid, 0);
Invalidate();
}
void CSuperView::OnUpdateGridv(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_wndList.GetFlag() & fVertGrid ? 1 : 0);
}
void CSuperView::OnTestdao()
{
}
void CSuperView::OnUpdateTestdao(CCmdUI* pCmdUI)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -