#include "stdafx.h"
#include "NTCollectView.h"
CNTCollectView *CNTCollectView::m_pCollectView = NULL;
IMPLEMENT_DYNCREATE(CNTCollectView, CView)
CNTCollectView::CNTCollectView()
{
m_pCollectView = this;
m_globe = false;
}
CNTCollectView::~CNTCollectView()
{
}
BEGIN_MESSAGE_MAP(CNTCollectView, CView)
ON_WM_SIZE()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
void CNTCollectView::OnDraw(CDC *pDC)
{
CDocument *pDoc = GetDocument();
CRect rect;
GetClientRect(&rect);
pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &m_BgMemDC, 0, 0, SRCCOPY);
}
#ifdef _DEBUG
void CNTCollectView::AssertValid() const
{
CView::AssertValid();
}
#ifndef _WIN32_WCE
void CNTCollectView::Dump(CDumpContext &dc) const
{
CView::Dump(dc);
}
#endif
#endif
void CNTCollectView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if (cx == 0 || cy == 0) return;
InitBgMemDC();
rectShowToScreen();
Invalidate();
}
void CNTCollectView::InitBgMemDC()
{
CRect rect;
GetClientRect(rect);
if(m_BgMemDC.GetSafeHdc() != NULL)
{
m_BgMemBmp.DeleteObject();
m_BgMemDC.DeleteDC();
}
CClientDC dc(this);
m_BgMemBmp.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
m_BgMemDC.CreateCompatibleDC(&dc);
m_BgMemDC.SelectObject(&m_BgMemBmp);
SetSplitRect(rect);
CString strNo;
CFont font;
font.CreateFont(m_rectShowArray[0].Width() / 10, 0, 0, 0, FW_BOLD, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, _T("宋体"));
CFont *pOldFont;
pOldFont = (CFont *)m_BgMemDC.SelectObject(&font);
m_BgMemDC.SetBkMode(TRANSPARENT);
m_BgMemDC.SetTextColor(RGB(255, 255, 255));
for(INT_PTR i = 0, j = m_rectShowArray.GetSize(); i < j; i++)
{
if (m_globe == false)
{
m_BgMemDC.DrawEdge(m_rectShowArray[i], EDGE_ETCHED, BF_ADJUST | BF_RECT);
rect = m_rectShowArray[i];
CBrush brush(RGB(47, 79, 79));
m_BgMemDC.FillRect(rect, &brush);
brush.DeleteObject();
strNo.Format(_T("第%d区"), i + 1);
m_BgMemDC.DrawText(strNo, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
else
{
m_BgMemDC.DrawEdge(m_rectShowArray[i], EDGE_ETCHED, BF_ADJUST | BF_RECT);
rect = m_rectShowArray[i];
CBrush brush(RGB(0, 0, 0));
m_BgMemDC.FillRect(rect, &brush);
brush.DeleteObject();
strNo.Format(_T("第%d区"), i + 1);
m_BgMemDC.DrawText(strNo, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
}
m_BgMemDC.SelectObject(pOldFont);
}
void CNTCollectView::SetSplitRect(CRect rectShow)
{
int nRow, nColumn;
nColumn = 5;
nRow = 4;
double dColWidth = (double)rectShow.Width() / nColumn;
double dRowHeight = (double)rectShow.Height() / nRow;
CRect rectSplit;
m_rectShowArray.RemoveAll();
for (int i = 0; i < nRow; i++)
{
rectSplit.SetRect(rectShow.left, int(rectShow.top + i * dRowHeight), rectShow.left + int(dColWidth), int(rectShow.top + (i + 1)*dRowHeight));
for (int j = 0; j < nColumn; j++)
{
m_rectShowArray.Add(rectSplit);
rectSplit.left = rectSplit.right;
rectSplit.right = rectShow.left + int(dColWidth * (j + 2));
}
}
}
BOOL CNTCollectView::OnEraseBkgnd(CDC *pDC)
{
return TRUE;
}
void CNTCollectView::ChangeAreaStatus(const struNTCollectReply &reply)
{
m_pCollectView->RedrawArea(reply);
}
void CNTCollectView::RedrawArea(const struNTCollectReply &reply)
{
m_globe = true;
CRect rect;
GetClientRect(rect);
SendMessage(WM_SIZE, (WPARAM)SIZE_RESTORED, MAKELPARAM(rect.Width(), rect.Height()));
}