15,980
社区成员




void CLogArea::DrawTable(CAibotFrameDlg* pdialog)
{
int _1scale = CAibotFrameDlg::GetScaleFactor()->Get01WPix();
int _5scale = CAibotFrameDlg::GetScaleFactor()->Get10WPix() * 5;
int _01hscale = CAibotFrameDlg::GetScaleFactor()->Get01HPix();
int _10hscale = CAibotFrameDlg::GetScaleFactor()->Get10HPix();
int _30hscale = _10hscale * 3;
// m_AloneListRect 绘制表格的矩阵大小
m_AloneListRect.TopLeft() = CPoint(2, m_Rect.top + _30hscale);
m_AloneListRect.BottomRight() = CPoint(m_Rect.right-2, m_Rect.bottom);
//获取表格控件
CGridCtrl *pGridLog = (CGridCtrl *)pdialog->GetDlgItem(IDC_CUSTOM_TABLOG);
pGridLog->ModifyStyleEx(WS_EX_CLIENTEDGE, NULL, SWP_DRAWFRAME); //关闭下陷效果
pGridLog->SetEditable(true);
pGridLog->SetTextBkColor(RGB(248, 255, 255));
pGridLog->SetGridBkColor(RGB(0, 0, 0));
pGridLog->SetGridLineColor(RGB(0, 0, 0));
int rowhight = abs((m_lfHeight - 1) - _10hscale); // 设置行高
int rows = m_AloneListRect.Height() / rowhight; // 计算矩阵中能存放的行数
m_AloneListRect.bottom = m_AloneListRect.top + rows *rowhight; //重新设置矩阵
//将表格控件移动到指定矩阵区域
pGridLog->MoveWindow(m_AloneListRect);
CRect rect; //获取客户区大小
pGridLog->GetClientRect(rect);
int cols = IDS_STRING_LG_RMARK + 1 - IDS_STRING_LG_NO; //获取列数 12列
pGridLog->SetRowCount(rows+1); //设置行数
pGridLog->SetColumnCount(cols); //设置列数
pGridLog->SetFixedRowCount(1); //表头为第一行
//pGridLog->SetFixedColumnCount(1); //表头为一列
int width = rect.Width() / cols; //前面11列列宽
int total = 0;
pGridLog->SetRowHeight(0, rowhight); //设置标题行高
//绘制表格头
for (int icol = 0, itext = IDS_STRING_LG_NO; icol < cols; ++icol,++itext)
{
GV_ITEM Item;
Item.mask = GVIF_TEXT | GVIF_FORMAT;
Item.row = 0;
Item.col = icol;
if (icol == pGridLog->GetColumnCount() - 1)
{
int len = rect.Width() - (cols-1) * width;
pGridLog->SetColumnWidth(icol, len); //设置各列宽
total += len;
}
else
{
pGridLog->SetColumnWidth(icol, width); //设置各列宽
total += width;
}
Item.nFormat = DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
CString str;
str.LoadString(itext);
Item.strText.Format(str, icol);
pGridLog->SetItem(&Item);
}
pGridLog->ShowWindow(SW_SHOW); //显示表格
pGridLog->ShowScrollBar(SB_HORZ, FALSE);//关闭水平滚动条
}
#define GRIDCONTROL_GRIDLINEEXTENDTO_NOUSER //显示格扩展到非客户区
void CGridCtrl::OnDraw(CDC* pDC)
{
if (!m_bAllowDraw)
return;
CRect clipRect;
if (pDC->GetClipBox(&clipRect) == ERROR)
return;
EraseBkgnd(pDC); // OnEraseBkgnd does nothing, so erase bkgnd here.
// This necessary since we may be using a Memory DC.
#ifdef _DEBUG
LARGE_INTEGER iStartCount;
QueryPerformanceCounter(&iStartCount);
#endif
CRect rect;
int row, col;
CGridCellBase* pCell;
int nFixedRowHeight = GetFixedRowHeight();
int nFixedColWidth = GetFixedColumnWidth();
CCellID idTopLeft = GetTopleftNonFixedCell();
int minVisibleRow = idTopLeft.row,
minVisibleCol = idTopLeft.col;
CRect VisRect;
CCellRange VisCellRange = GetVisibleNonFixedCellRange(VisRect);
int maxVisibleRow = VisCellRange.GetMaxRow(),
maxVisibleCol = VisCellRange.GetMaxCol();
if (GetVirtualMode())
SendCacheHintToParent(VisCellRange);
#ifdef GRIDCONTROL_GRIDLINEEXTENDTO_NOUSER
do
{
int iColMax = GetColumnCount();
if(iColMax <=0 ) break;
//获取客户区大小
CRect rcClient;
GetClientRect(&rcClient);
int icxUsed = 0;
for(int iCol=0; iCol<iColMax-1; iCol++)
{
icxUsed += GetColumnWidth(iCol);
}
int iLastCX = rcClient.Width() - icxUsed;
if(GetColumnWidth(iColMax-1) != iLastCX)
{
SetColumnWidth(iColMax-1, iLastCX);
Invalidate();
}
}while(0);
#endif //GRIDCONTROL_GRIDLINEEXTENDTO_NOUSER
// draw top-left cells 0..m_nFixedRows-1, 0..m_nFixedCols-1
rect.bottom = -1;
for (row = 0; row < m_nFixedRows; row++)
{
if (GetRowHeight(row) <= 0) continue;
rect.top = rect.bottom+1;
rect.bottom = rect.top + GetRowHeight(row)-1;
rect.right = -1;
for (col = 0; col < m_nFixedCols; col++)
{
if (GetColumnWidth(col) <= 0) continue;
rect.left = rect.right+1;
rect.right = rect.left + GetColumnWidth(col)-1;
pCell = GetCell(row, col);
if (pCell)
{
pCell->SetCoords(row,col);
pCell->Draw(pDC, row, col, rect, FALSE);
}
}
}
// draw fixed column cells: m_nFixedRows..n, 0..m_nFixedCols-1
rect.bottom = nFixedRowHeight-1;
for (row = minVisibleRow; row <= maxVisibleRow; row++)
{
if (GetRowHeight(row) <= 0) continue;
rect.top = rect.bottom+1;
rect.bottom = rect.top + GetRowHeight(row)-1;
// rect.bottom = bottom pixel of previous row
if (rect.top > clipRect.bottom)
break; // Gone past cliprect
if (rect.bottom < clipRect.top)
continue; // Reached cliprect yet?
rect.right = -1;
for (col = 0; col < m_nFixedCols; col++)
{
if (GetColumnWidth(col) <= 0) continue;
rect.left = rect.right+1;
rect.right = rect.left + GetColumnWidth(col)-1;
if (rect.left > clipRect.right)
break; // gone past cliprect
if (rect.right < clipRect.left)
continue; // Reached cliprect yet?
pCell = GetCell(row, col);
if (pCell)
{
pCell->SetCoords(row,col);
pCell->Draw(pDC, row, col, rect, FALSE);
}
}
}
// draw fixed row cells 0..m_nFixedRows, m_nFixedCols..n
rect.bottom = -1;
for (row = 0; row < m_nFixedRows; row++)
{
if (GetRowHeight(row) <= 0) continue;
rect.top = rect.bottom+1;
rect.bottom = rect.top + GetRowHeight(row)-1;
// rect.bottom = bottom pixel of previous row
if (rect.top > clipRect.bottom)
break; // Gone past cliprect
if (rect.bottom < clipRect.top)
continue; // Reached cliprect yet?
rect.right = nFixedColWidth-1;
for (col = minVisibleCol; col <= maxVisibleCol; col++)
{
if (GetColumnWidth(col) <= 0) continue;
rect.left = rect.right+1;
rect.right = rect.left + GetColumnWidth(col)-1;
if (rect.left > clipRect.right)
break; // gone past cliprect
if (rect.right < clipRect.left)
continue; // Reached cliprect yet?
pCell = GetCell(row, col);
if (pCell)
{
pCell->SetCoords(row,col);
pCell->Draw(pDC, row, col, rect, FALSE);
}
}
}
// draw rest of non-fixed cells
rect.bottom = nFixedRowHeight-1;
for (row = minVisibleRow; row <= maxVisibleRow; row++)
{
if (GetRowHeight(row) <= 0) continue;
rect.top = rect.bottom+1;
rect.bottom = rect.top + GetRowHeight(row)-1;
// rect.bottom = bottom pixel of previous row
if (rect.top > clipRect.bottom)
break; // Gone past cliprect
if (rect.bottom < clipRect.top)
continue; // Reached cliprect yet?
rect.right = nFixedColWidth-1;
for (col = minVisibleCol; col <= maxVisibleCol; col++)
{
if (GetColumnWidth(col) <= 0) continue;
rect.left = rect.right+1;
rect.right = rect.left + GetColumnWidth(col)-1;
if (rect.left > clipRect.right)
break; // gone past cliprect
if (rect.right < clipRect.left)
continue; // Reached cliprect yet?
pCell = GetCell(row, col);
// TRACE(_T("Cell %d,%d type: %s\n"), row, col, pCell->GetRuntimeClass()->m_lpszClassName);
if (pCell)
{
pCell->SetCoords(row,col);
pCell->Draw(pDC, row, col, rect, FALSE);
}
}
}
CPen pen;
pen.CreatePen(PS_SOLID, 0, m_crGridLineColour);
pDC->SelectObject(&pen);
// draw vertical lines (drawn at ends of cells)
if (m_nGridLines == GVL_BOTH || m_nGridLines == GVL_VERT)
{
int x = nFixedColWidth;
for (col = minVisibleCol; col <= maxVisibleCol; col++)
{
if (GetColumnWidth(col) <= 0) continue;
x += GetColumnWidth(col);
pDC->MoveTo(x-1, nFixedRowHeight);
pDC->LineTo(x-1, VisRect.bottom);
}
}
// draw horizontal lines (drawn at bottom of each cell)
if (m_nGridLines == GVL_BOTH || m_nGridLines == GVL_HORZ)
{
int y = nFixedRowHeight;
for (row = minVisibleRow; row <= maxVisibleRow; row++)
{
if (GetRowHeight(row) <= 0) continue;
y += GetRowHeight(row);
pDC->MoveTo(nFixedColWidth, y-1);
pDC->LineTo(VisRect.right, y-1);
}
}
pDC->SelectStockObject(NULL_PEN);
// Let parent know it can discard it's data if it needs to.
if (GetVirtualMode())
SendCacheHintToParent(CCellRange(-1,-1,-1,-1));
#ifdef _DEBUG
LARGE_INTEGER iEndCount;
QueryPerformanceCounter(&iEndCount);
TRACE1("Draw counter ticks: %d\n", iEndCount.LowPart-iStartCount.LowPart);
#endif
}
#define GRIDCONTROL_GRIDLINEEXTENDTO_NOUSER //显示格扩展到非客户区
void CGridCtrl::OnDraw(CDC* pDC)
{
if (!m_bAllowDraw)
return;
CRect clipRect;
if (pDC->GetClipBox(&clipRect) == ERROR)
return;
EraseBkgnd(pDC); // OnEraseBkgnd does nothing, so erase bkgnd here.
// This necessary since we may be using a Memory DC.
#ifdef _DEBUG
LARGE_INTEGER iStartCount;
QueryPerformanceCounter(&iStartCount);
#endif
CRect rect;
int row, col;
CGridCellBase* pCell;
int nFixedRowHeight = GetFixedRowHeight();
int nFixedColWidth = GetFixedColumnWidth();
CCellID idTopLeft = GetTopleftNonFixedCell();
int minVisibleRow = idTopLeft.row,
minVisibleCol = idTopLeft.col;
CRect VisRect;
CCellRange VisCellRange = GetVisibleNonFixedCellRange(VisRect);
int maxVisibleRow = VisCellRange.GetMaxRow(),
maxVisibleCol = VisCellRange.GetMaxCol();
if (GetVirtualMode())
SendCacheHintToParent(VisCellRange);
#ifdef GRIDCONTROL_GRIDLINEEXTENDTO_NOUSER
CRect rcClient;
GetClientRect(&rcClient);
CBrush FixedRowColBack(GetDefaultCell(TRUE, TRUE)->GetBackClr());
#endif //GRIDCONTROL_GRIDLINEEXTENDTO_NOUSER
// draw top-left cells 0..m_nFixedRows-1, 0..m_nFixedCols-1
rect.bottom = -1;
for (row = 0; row < m_nFixedRows; row++)
{
if (GetRowHeight(row) <= 0) continue;
rect.top = rect.bottom+1;
rect.bottom = rect.top + GetRowHeight(row)-1;
rect.right = -1;
for (col = 0; col < m_nFixedCols; col++)
{
if (GetColumnWidth(col) <= 0) continue;
rect.left = rect.right+1;
rect.right = rect.left + GetColumnWidth(col)-1;
pCell = GetCell(row, col);
if (pCell)
{
pCell->SetCoords(row,col);
pCell->Draw(pDC, row, col, rect, FALSE);
}
}
#ifdef GRIDCONTROL_GRIDLINEEXTENDTO_NOUSER
if(rect.bottom < rcClient.bottom)
{
CRect rcFill(rect.right, rect.top, rcClient.right, rect.bottom);
pDC->FillRect(&rcFill, &FixedRowColBack);
}
#endif //GRIDCONTROL_GRIDLINEEXTENDTO_NOUSER
}
// draw fixed column cells: m_nFixedRows..n, 0..m_nFixedCols-1
rect.bottom = nFixedRowHeight-1;
for (row = minVisibleRow; row <= maxVisibleRow; row++)
{
if (GetRowHeight(row) <= 0) continue;
rect.top = rect.bottom+1;
rect.bottom = rect.top + GetRowHeight(row)-1;
// rect.bottom = bottom pixel of previous row
if (rect.top > clipRect.bottom)
break; // Gone past cliprect
if (rect.bottom < clipRect.top)
continue; // Reached cliprect yet?
rect.right = -1;
for (col = 0; col < m_nFixedCols; col++)
{
if (GetColumnWidth(col) <= 0) continue;
rect.left = rect.right+1;
rect.right = rect.left + GetColumnWidth(col)-1;
if (rect.left > clipRect.right)
break; // gone past cliprect
if (rect.right < clipRect.left)
continue; // Reached cliprect yet?
pCell = GetCell(row, col);
if (pCell)
{
pCell->SetCoords(row,col);
pCell->Draw(pDC, row, col, rect, FALSE);
}
}
}
// draw fixed row cells 0..m_nFixedRows, m_nFixedCols..n
rect.bottom = -1;
for (row = 0; row < m_nFixedRows; row++)
{
if (GetRowHeight(row) <= 0) continue;
rect.top = rect.bottom+1;
rect.bottom = rect.top + GetRowHeight(row)-1;
// rect.bottom = bottom pixel of previous row
if (rect.top > clipRect.bottom)
break; // Gone past cliprect
if (rect.bottom < clipRect.top)
continue; // Reached cliprect yet?
rect.right = nFixedColWidth-1;
for (col = minVisibleCol; col <= maxVisibleCol; col++)
{
if (GetColumnWidth(col) <= 0) continue;
rect.left = rect.right+1;
rect.right = rect.left + GetColumnWidth(col)-1;
if (rect.left > clipRect.right)
break; // gone past cliprect
if (rect.right < clipRect.left)
continue; // Reached cliprect yet?
pCell = GetCell(row, col);
if (pCell)
{
pCell->SetCoords(row,col);
pCell->Draw(pDC, row, col, rect, FALSE);
}
}
}
// draw rest of non-fixed cells
rect.bottom = nFixedRowHeight-1;
for (row = minVisibleRow; row <= maxVisibleRow; row++)
{
if (GetRowHeight(row) <= 0) continue;
rect.top = rect.bottom+1;
rect.bottom = rect.top + GetRowHeight(row)-1;
// rect.bottom = bottom pixel of previous row
if (rect.top > clipRect.bottom)
break; // Gone past cliprect
if (rect.bottom < clipRect.top)
continue; // Reached cliprect yet?
rect.right = nFixedColWidth-1;
for (col = minVisibleCol; col <= maxVisibleCol; col++)
{
if (GetColumnWidth(col) <= 0) continue;
rect.left = rect.right+1;
rect.right = rect.left + GetColumnWidth(col)-1;
if (rect.left > clipRect.right)
break; // gone past cliprect
if (rect.right < clipRect.left)
continue; // Reached cliprect yet?
pCell = GetCell(row, col);
// TRACE(_T("Cell %d,%d type: %s\n"), row, col, pCell->GetRuntimeClass()->m_lpszClassName);
if (pCell)
{
pCell->SetCoords(row,col);
pCell->Draw(pDC, row, col, rect, FALSE);
}
}
}
CPen pen;
pen.CreatePen(PS_SOLID, 0, m_crGridLineColour);
pDC->SelectObject(&pen);
#ifdef GRIDCONTROL_GRIDLINEEXTENDTO_NOUSER
VisRect.right = rcClient.right;
VisRect.bottom = rcClient.bottom;
#endif //GRIDCONTROL_GRIDLINEEXTENDTO_NOUSER
// draw vertical lines (drawn at ends of cells)
if (m_nGridLines == GVL_BOTH || m_nGridLines == GVL_VERT)
{
int x = nFixedColWidth;
for (col = minVisibleCol; col <= maxVisibleCol; col++)
{
if (GetColumnWidth(col) <= 0) continue;
x += GetColumnWidth(col);
pDC->MoveTo(x-1, nFixedRowHeight);
pDC->LineTo(x-1, VisRect.bottom);
}
}
// draw horizontal lines (drawn at bottom of each cell)
if (m_nGridLines == GVL_BOTH || m_nGridLines == GVL_HORZ)
{
int y = nFixedRowHeight;
for (row = minVisibleRow; row <= maxVisibleRow; row++)
{
if (GetRowHeight(row) <= 0) continue;
y += GetRowHeight(row);
pDC->MoveTo(nFixedColWidth, y-1);
pDC->LineTo(VisRect.right, y-1);
}
}
pDC->SelectStockObject(NULL_PEN);
// Let parent know it can discard it's data if it needs to.
if (GetVirtualMode())
SendCacheHintToParent(CCellRange(-1,-1,-1,-1));
#ifdef _DEBUG
LARGE_INTEGER iEndCount;
QueryPerformanceCounter(&iEndCount);
TRACE1("Draw counter ticks: %d\n", iEndCount.LowPart-iStartCount.LowPart);
#endif
}
pGridLog->MoveWindow(m_AloneListRect);
pGridLog->AutoSize(GVS_BOTH);
//后面的行列调整的可以都不要