Проанализировав код написанный ранее можно сделать вывод, что нам нужен только указатель на CWind* и все. Остальное можно скрыть от программиста, получения контекста для рисования, расчет областей. Создадим новый класс:
В этом новом классе объявим четыре виртуальные функции.
сlass CCustomDrawDialog { public: virtual void DrawBottom(CRect cr,CDC *dc); virtual void DrawLight(CRect cr,CDC *dc); virtual void DrawLeft(CRect cr,CDC *dc); virtual void DrawCaption(CRect cr,CDC *dc); void Draw(CWnd* cWin); CCustomDrawDialog(); virtual ~CCustomDrawDialog(); private: CCalcWindowNonClient cCalc; CDC *cdWinDC; };
При вызове Draw будет производить все необходимые расчеты и вызывать эти функции с параметрами.
#include "stdafx.h" #include "TestPaint.h" #include "CustomDrawDialog.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ///////////////////////////// // Construction/Destruction ///////////////////////////// CCustomDrawDialog::CCustomDrawDialog() {} CCustomDrawDialog::~CCustomDrawDialog() {} void CCustomDrawDialog::Draw(CWnd* cWin) { cCalc.Calc(cWin); CDC* cdWinDC= cWin->GetWindowDC(); DrawCaption(cCalc.crCaptionRect,cdWinDC); DrawLeft(cCalc.crLeft,cdWinDC); DrawLight(cCalc.crRight,cdWinDC); DrawBottom(cCalc.crTop,cdWinDC); cWin->ReleaseDC(cdWinDC); } void CCustomDrawDialog::DrawCaption(CRect cr,CDC *dc) {} void CCustomDrawDialog::DrawLeft(CRect cr,CDC *dc) {} void CCustomDrawDialog::DrawLight(CRect cr,CDC *dc) {} void CCustomDrawDialog::DrawBottom(CRect cr,CDC *dc) {}
Вот и все базовый класс готов.