📄 infoedit.cpp
字号:
// InfoEdit.cpp : implementation file
//
#include "stdafx.h"
#include "Monitor.h"
#include "InfoEdit.h"
#include "NewEditButton.h"
#include "dtpicker.h"
#include "UserEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInfoEdit
IMPLEMENT_DYNCREATE(CInfoEdit, CScrollView)
CInfoEdit::CInfoEdit()
{
}
CInfoEdit::~CInfoEdit()
{
CNewEditButton *pNewButton;
CDTPicker *pDate;
for(int i=0;i<iTypeNumber;i++)
{
pNewButton=(CNewEditButton*)TypeButtonArray.GetAt(i);
delete pNewButton;
pDate=(CDTPicker*)BeginTimeArray.GetAt(i);
delete pDate;
pDate=(CDTPicker*)EndTimeArray.GetAt(i);
delete pDate;
}
TypeButtonArray.RemoveAll();
BeginTimeArray.RemoveAll();
EndTimeArray.RemoveAll();
}
BEGIN_MESSAGE_MAP(CInfoEdit, CScrollView)
//{{AFX_MSG_MAP(CInfoEdit)
ON_WM_MOUSEACTIVATE()
ON_MESSAGE(CHOOSE_TYPE,OnChooseType)
ON_MESSAGE(SET_VALUE,OnSetValue)
ON_MESSAGE(INVERT_CONTROL,OnInvertControl)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInfoEdit drawing
void CInfoEdit::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
iTypeNumber=m_pUserValueList->GetSize();
int p=0;
CTypeInfo *pOneType;
CTypeValue *pOneValue;
CString strOneType;
CRect myRect;
sizeTotal.cx = 700;
sizeTotal.cy = iTypeNumber/3*62+11;
if(iTypeNumber-iTypeNumber/3*3) sizeTotal.cy=sizeTotal.cy+62;
SetScrollSizes(MM_TEXT, sizeTotal);
for(int i=0;i<(iTypeNumber/3)+1;i++)
{
if(p>=iTypeNumber) break;
for(int j=0;j<3;j++)
{
if(p>=iTypeNumber) break;
pOneType=(CTypeInfo*)m_pTypeList->GetAt(p);
strOneType=pOneType->sEName;
pOneValue=(CTypeValue*)m_pUserValueList->GetAt(p);
myRect=CRect(110+j*230,11+i*62,110+j*230+49,11+i*62+25);
CNewEditButton *pNewButton = new CNewEditButton;
pNewButton->Create( (LPCTSTR)strOneType,WS_VISIBLE|WS_CHILD|WS_TABSTOP
|SS_NOTIFY,myRect,this,IDC_EDIT_BUTTONES+p);
CDTPicker *pBegin=new CDTPicker;
CDTPicker *pEnd=new CDTPicker;
myRect.top+=26;
myRect.bottom+=26;
myRect.left-=80;
myRect.right=myRect.left+97;
pBegin->Create(NULL,WS_VISIBLE|WS_CHILD|WS_TABSTOP,myRect,this,
IDC_TYPE_BEGIN+p);
pBegin->SetFormat(1);
myRect.left+=97;
myRect.right=myRect.left+97;
pEnd->Create(NULL,WS_VISIBLE|WS_CHILD|WS_TABSTOP,myRect,this,
IDC_TYPE_END+p);
pEnd->SetFormat(1);
if(pOneValue->iKey>-1)
{
pNewButton->bChosen=TRUE;
VARIANT myDate;
myDate.vt=VT_DATE;
myDate.date=pOneValue->Begin;
pBegin->SetValue(myDate);
myDate.date=pOneValue->End;
pEnd->SetValue(myDate);
}
else
{
pBegin->EnableWindow(FALSE);
pEnd->EnableWindow(FALSE);
}
TypeButtonArray.SetAtGrow(p,pNewButton);
BeginTimeArray.SetAtGrow(p,pBegin);
EndTimeArray.SetAtGrow(p,pEnd);
p++;
}
}
}
void CInfoEdit::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CInfoEdit diagnostics
#ifdef _DEBUG
void CInfoEdit::AssertValid() const
{
CScrollView::AssertValid();
}
void CInfoEdit::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CInfoEdit message handlers
int CInfoEdit::OnMouseActivate(CWnd* pDesktopWnd,UINT nHitTest,UINT message)
{
int nResult = CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
SetActiveWindow();
return nResult;
}
BOOL CInfoEdit::OnChooseType(WPARAM dtpID,LPARAM action)
{
CWnd *pWnd=GetDlgItem(dtpID);
pWnd->EnableWindow(action);
return TRUE;
}
BOOL CInfoEdit::OnSetValue(WPARAM iWhichOne,LPARAM pValue)
{
VARIANT v=*(VARIANT *)pValue;
CObArray *pArray;
if(iWhichOne==1)
pArray=&BeginTimeArray;
else
pArray=&EndTimeArray;
for(int i=0;i<iTypeNumber;i++)
{
CDTPicker* p=(CDTPicker*)pArray->GetAt(i);
if(p->IsWindowEnabled())
p->SetValue(v);
}
return TRUE;
}
BOOL CInfoEdit::OnInvertControl(WPARAM NoUse,LPARAM ForFuture)
{
for(int i=0;i<iTypeNumber;i++)
{
CNewEditButton *p=(CNewEditButton*)TypeButtonArray.GetAt(i);
::SendNotifyMessage(p->m_hWnd,WM_LBUTTONUP,0,0);
}
return TRUE;
}
BOOL CInfoEdit::SetData(CObArray *UserValues,CObArray *TypeList)
{
m_pUserValueList=UserValues;
m_pTypeList=TypeList;
return TRUE;
}
BOOL CInfoEdit::SaveData()
{
CDTPicker *pBeginDate,*pEndDate;
VARIANT t;
CWnd* pFather=GetParent();
for(int i=0;i<iTypeNumber;i++)
{
CTypeValue *pOneValue=(CTypeValue*)m_pUserValueList->GetAt(i);
CNewEditButton* pButton=(CNewEditButton*)TypeButtonArray.GetAt(i);
pBeginDate=(CDTPicker*)BeginTimeArray.GetAt(i);
pEndDate=(CDTPicker*)EndTimeArray.GetAt(i);
if(pButton->bChosen)
{
if(pOneValue->iKey==-1)
{
pOneValue->iKey=i;
pOneValue->cChange='A';
t=pBeginDate->GetValue();
pOneValue->Begin=t.date;
t=pEndDate->GetValue();
pOneValue->End=t.date;
((CUserEdit*)pFather)->bTypeChanged=TRUE;
}
else
{
t=pBeginDate->GetValue();
if(t.date!=pOneValue->Begin)
{
pOneValue->Begin=t.date;
((CUserEdit*)pFather)->bTypeChanged=TRUE;
pOneValue->cChange='T';
}
t=pEndDate->GetValue();
if(t.date!=pOneValue->End)
{
pOneValue->End=t.date;
((CUserEdit*)pFather)->bTypeChanged=TRUE;
pOneValue->cChange='T';
}
}
}
else
{
if(pOneValue->iKey!=-1)
{
pOneValue->iKey=-1;
pOneValue->cChange='D';
((CUserEdit*)pFather)->bTypeChanged=TRUE;
}
}
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -