📄 timegridctrl.cpp
字号:
}
//////////////////////////////////////////////////
//
//////////////////////////////////////////////////
BOOL CTimeGridCtrl::GetCellRect(int nRow, int nCol, LPRECT pRect) const
{
pRect->left = m_nFixedCellWidth+(nCol-1)*m_nDefCellWidth;
pRect->top = m_nFixedColHeight+(nRow-1)*m_nDefCellHeight;
pRect->right = pRect->left + m_nDefCellWidth-1;
pRect->bottom = pRect->top + m_nDefCellHeight-1;
return TRUE;
}
//////////////////////////////////////////////////
//
//////////////////////////////////////////////////
CGridCell* CTimeGridCtrl::CreateCell(int nRow, int nCol)
{
CGridCell* pCell = new CGridCell;
if (!pCell)
return NULL;
return pCell;
}
///////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////
void CTimeGridCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
if(nFlags & MK_LBUTTON)
{
int nRow,nCol,nStartRow,nStartCol;
CGridCell *pStartCell=GetCellFromPt(m_nLastPoint,nStartRow,nStartCol);
CGridCell *pCell=GetCellFromPt(point,nRow,nCol);
if(pStartCell!=NULL&&pCell!=NULL)
{
for(int i=min(nStartRow,nRow);i<=max(nStartRow,nRow);i++)
{
for(int j=min(nStartCol,nCol);j<=max(nStartCol,nCol);j++)
{
pCell=GetCell(i,j);
if(pCell!=NULL)
{
if(pCell->nValid==TRUE)
{
pCell->state=GVIS_SELECTED;
RedrawCell(i,j);
}
}
}
}
}
}
if(nFlags & MK_RBUTTON)
{
int nRow,nCol,nStartRow,nStartCol;
CGridCell *pStartCell=GetCellFromPt(m_nLastPoint,nStartRow,nStartCol);
CGridCell *pCell=GetCellFromPt(point,nRow,nCol);
if(pStartCell!=NULL&&pCell!=NULL)
{
for(int i=min(nStartRow,nRow);i<=max(nStartRow,nRow);i++)
{
for(int j=min(nStartCol,nCol);j<=max(nStartCol,nCol);j++)
{
pCell=GetCell(i,j);
if(pCell!=NULL)
{
pCell->state=GVIS_NOSELECTED;
RedrawCell(i,j);
}
}
}
}
}
CWnd::OnMouseMove(nFlags, point);
}
///////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////
void CTimeGridCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
HWND hOldFocusWnd = ::GetFocus();
int nRow,nCol;
m_nLastPoint=point;
CGridCell *pCell=GetCellFromPt(point,nRow,nCol);
if(pCell!=NULL)
{
if(pCell->nValid==TRUE)
{
pCell->state = GVIS_SELECTED;
RedrawCell(nRow,nCol);
}
}
}
///////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////
void CTimeGridCtrl::OnRButtonDown(UINT nFlags, CPoint point)
{
HWND hOldFocusWnd = ::GetFocus();
int nRow,nCol;
m_nLastPoint=point;
CGridCell *pCell=GetCellFromPt(point,nRow,nCol);
if(pCell!=NULL)
{
pCell->state=GVIS_NOSELECTED;
RedrawCell(nRow,nCol);
}
CWnd::OnRButtonDown(nFlags, point);
}
///////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////
BOOL CTimeGridCtrl::DrawHourLabel(CDC* pDC, int nRow,CRect rect)
{
Draw3DRectangle(pDC,rect,0);
pDC->SetBkMode(TRANSPARENT);
CString sLabel;
sLabel.Format("%02d时",nRow-1);
pDC->DrawText(sLabel,rect, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////////////
BOOL CTimeGridCtrl::DrawMinuateLabel(CDC* pDC,int nCol, CRect rect)
{
if(((nCol-1)%5)!=0)
{
Line(rect.left,rect.top+m_nFixedColHeight/2+5,rect.left,rect.bottom,COLOR_BLUE,pDC);
}
else
{
CRect sCaptionRect=rect;
sCaptionRect.bottom=sCaptionRect.top+rect.Height()/2;
sCaptionRect.left=rect.left-10;
sCaptionRect.right=rect.left+15;
Line(rect.left,rect.top+m_nFixedColHeight/2,rect.left,rect.bottom,COLOR_RED,pDC);
CString sLabel;
sLabel.Format("%02d",nCol-1);
pDC->DrawText(sLabel,sCaptionRect, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////
void CTimeGridCtrl::DrawCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk)
{
CGridCell* pCell=GetCell(nRow,nCol);
if(pCell==NULL)
return;
if (pCell->state == GVIS_SELECTED)
{
if(pCell->nValid)
DrawRectangle(pDC,rect,1,COLOR_RED,COLOR_YELLOW);
else
DrawRectangle(pDC,rect,1,COLOR_GREEN,COLOR_BLACK);
}
else
{
if(pCell->nValid)
DrawRectangle(pDC,rect,1,COLOR_BLUE,COLOR_YELLOW);
else
DrawRectangle(pDC,rect,1,COLOR_CYAN,COLOR_BLACK);
}
return;
}
/////////////////////////////////////////////
//
/////////////////////////////////////////////
BOOL CTimeGridCtrl::SetCols()
{
m_RowData.SetSize(m_nRows);
for (int row = 0; row <m_nRows; row++)
{
m_RowData[row]=new GRID_ROW;
m_RowData[row]->SetSize(m_nCols);
for (int col =0; col <m_nCols; col++)
{
GRID_ROW* pRow = m_RowData[row];
if (pRow)
pRow->SetAt(col, CreateCell(row,col));
}
}
return TRUE;
}
////////////////////////////////////////////////
//
///////////////////////////////////////////////
int CTimeGridCtrl::GetCellStates(int nRow, int nCol)
{
CGridCell *pCell=GetCell(nRow, nCol);
if(pCell!=NULL)
return pCell->state;
return GVIS_NOSELECTED;
}
////////////////////////////////////////////
//
////////////////////////////////////////////
void CTimeGridCtrl::SetNoValid()
{
for(int i=0;i<m_nRows;i++)
{
for(int j=0;j<m_nCols;j++)
{
CGridCell *pCell=GetCell(i, j);
if(pCell!=NULL)
{
pCell->nValid=FALSE;
pCell->state=GVIS_NOSELECTED;
}
}
}
Invalidate();
}
////////////////////////////////////////////
//
////////////////////////////////////////////
void CTimeGridCtrl::SetSelectCell(int nRow,int nCol,int nSelect)
{
CGridCell *pCell=GetCell(nRow, nCol);
if(pCell!=NULL)
pCell->state=nSelect;
}
////////////////////////////////////////////
//
////////////////////////////////////////////
void CTimeGridCtrl::SetValidCell(int nRow,int nCol)
{
CGridCell *pCell=GetCell(nRow, nCol);
if(pCell!=NULL)
pCell->nValid=TRUE;
}
////////////////////////////////////////////
//
////////////////////////////////////////////
BOOL CTimeGridCtrl::GetValidCell(int nRow,int nCol)
{
CGridCell *pCell=GetCell(nRow, nCol);
if(pCell!=NULL)
return pCell->nValid;
return FALSE;
}
////////////////////////////////////////////
//
////////////////////////////////////////////
BOOL CTimeGridCtrl::PreTranslateMessage(MSG* pMsg)
{
switch(pMsg->message)
{
case WM_LBUTTONDOWN:
case WM_MOUSEMOVE:
case WM_LBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
if (m_pToolTip)
{
CPoint ptCurrentPos;
ptCurrentPos.x = LOWORD(pMsg->lParam);
ptCurrentPos.y = HIWORD(pMsg->lParam);
if (m_rectSearch.PtInRect(ptCurrentPos) == FALSE)
{
m_pToolTip->Activate(FALSE);
}
m_pToolTip->Activate(TRUE);
m_pToolTip->RelayEvent(pMsg);
}
}
return CWnd::PreTranslateMessage(pMsg);
}
////////////////////////////////////////
//
///////////////////////////////////////
BOOL CTimeGridCtrl::OnToolTipNotify(UINT id,NMHDR *pNMH, LRESULT *pResult)
{
LPTOOLTIPTEXT lpttt;
lpttt = (LPTOOLTIPTEXT)pNMH;
lpttt->szText[0] = '\0';
POINT ptCurrentPos;
GetCursorPos(&ptCurrentPos);
ScreenToClient(&ptCurrentPos);
int nRow,nCol;
GetCellFromPt(ptCurrentPos,nRow,nCol);
m_rectSearch.SetRect(ptCurrentPos.x - 3,ptCurrentPos.y - 3,ptCurrentPos.x + 3,ptCurrentPos.y + 3);
CString sTxt="";
if(nRow!=-1&&nCol!=-1)
{
sTxt.Format("%02d时%02d分",nRow-1,nCol-1);
}
strcpy(lpttt->szText,sTxt);
return FALSE;
}
BOOL CTimeGridCtrl::PreCreateWindow(CREATESTRUCT& cs)
{
return CWnd::PreCreateWindow(cs);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -