少了硬編碼 代碼確實(shí)好看了很多...
上個例子... 滾動視圖部分的
修改前的代碼
void CTransportWnd::OnPaint()
{
CPaintDC dc(this);
m_tooltip.RemoveAllTools(); //清空所有標(biāo)記
CRect rect;
GetClientRect(rect);
DocToClient(rect);
HDC dcMem;
HBITMAP bm;
bm = CreateCompatibleBitmap(dc.m_hDC, rect.Width(), rect.Height());
dcMem = CreateCompatibleDC(dc);
SelectObject(dcMem, bm);
//////////////////////////
Graphics graphics(dcMem);
graphics.SetSmoothingMode(SmoothingModeHighQuality);
// background
graphics.FillRectangle(&SolidBrush(Color(255, 255, 255, 255)), rect.left, rect.top, rect.Width(), rect.Height());
// concrete flow
DrawAllPlaces(graphics, rect);
BitBlt(dc, 0, 0, rect.Width(), rect.Height(), dcMem, 0, 0, SRCCOPY);
DeleteObject(bm);
DeleteDC(dcMem);
//更改滾動條
GetClientRect(&rect);
int iCount = m_vecPlaces.size();
int iTotalHeight = (iCount / 2) * (FLOW_HEIGHT+10);
SetScrollSizes( MM_LOENGLISH, CSize(rect.Width() - 20, iTotalHeight) );
}
修改過后的代碼
void CWorksiteWnd::OnDraw(CDC* pDC)
{
// TODO: 在此處為本機(jī)數(shù)據(jù)添加繪制代碼
m_tooTip.RemoveAllTools(); //清空所有標(biāo)記
CRect rect;
GetClientRect(rect);
//繪圖
Graphics graphics( pDC->m_hDC );
DrawAllPlaces(graphics, rect);
//更新滾動條
GetClientRect(&rect);
int iCount = m_vecPlaces.size();
int iTotalHeight = iCount * (FLOW_HEIGHT+10) + 20;
SetScrollSizes( MM_TEXT, CSize(rect.Width() - 20, iTotalHeight) );
}
單單拋開雙緩沖不說 那個DocToClient這個函數(shù)簡直是丑陋無比 而且是設(shè)備相關(guān)的(換了分辨率就變樣了...)
void CTransportWnd::DocToClient(CRect& rect)
{
CClientDC dc(this);
OnPrepareDC(&dc, NULL);
dc.LPtoDP(rect);
rect.NormalizeRect();
//rect.bottom += 5000;
//rect.top -= 198;
}
代碼的丑陋可能現(xiàn)在還看不出來...在上一段小小的代碼 后面畫圖部分的
void CTransportWnd::DrawAllPlaces(Graphics& graphics, CRect rect)
{
//rect.top += 188;
CRect rectTemp;
GetClientRect(&rectTemp);
rect.top += rectTemp.bottom;
//rect.top = 0;
vector<PLACE_STATION*>::iterator it = m_vecPlaces.begin();
簡直就是war3里面的憎惡... 用肉縫起來的代碼 后面還有大量的
CPoint pointScorll = GetScrollPosition();
rectTemp.bottom += pointScorll.y;
rectTemp.top += pointScorll.y;
哎 今天花了一早上更改代碼 現(xiàn)在的代碼看著要舒服多了 還是聽感謝侯捷的<深入淺出MFC> 昨晚無意間翻到的CScorllView這一節(jié) 一下就看明白代碼的設(shè)備相關(guān)性的問題出在哪了... 看來還是要時不時翻翻書
posted on 2009-11-09 14:42
李佳 閱讀(475)
評論(0) 編輯 收藏 引用 所屬分類:
WIN32 應(yīng)用開發(fā)