Шаг 72 - Класс для расчета областей рисования

Для того, чтобы рассчитывать прямоугольники я создал класс.

72_1.gif (2515 b)

Вот его описание:

#define ADD_CONSTANT_CAPTION 3

class CCalcWindowNonClient  
{
public:
	void Calc(CWnd* cWin);
	CCalcWindowNonClient();
	virtual ~CCalcWindowNonClient();
	CRect crCaptionRect;
	CRect crLeft;
	CRect crRight;
	CRect crTop;
	CRect crWindowsRect;
	CRect crClienRect;
};

А вот реализация.

////////////////////////////
// Construction/Destruction
////////////////////////////

CCalcWindowNonClient::CCalcWindowNonClient()
{

}

CCalcWindowNonClient::~CCalcWindowNonClient()
{

}

void CCalcWindowNonClient::Calc(CWnd *cWin)
{
	cWin->GetWindowRect(&crWindowsRect);
	cWin->GetClientRect(&crClienRect);
	int inFrameWidht=(crWindowsRect.Width() - crClienRect.Width()) / 2;
	// CALC CAPTION
	crCaptionRect.top =0;
	crCaptionRect.left = 0;
	crCaptionRect.bottom = crWindowsRect.Height() -
		crClienRect.Height()  - ADD_CONSTANT_CAPTION;
	crCaptionRect.right = crWindowsRect.Width();

	// CALC LEFT
	crLeft.top = crCaptionRect.bottom;
	crLeft.bottom = crWindowsRect.Height();
	crLeft.left = 0;
	crLeft.right =  inFrameWidht;

	// CALC RIGHT
	crRight.top = crCaptionRect.bottom;
	crRight.bottom = crWindowsRect.Height();
	crRight.left = crWindowsRect.Width() - inFrameWidht; 
	crRight.right = crWindowsRect.Width(); 

	// CALC TOP
	crTop.left = crLeft.right;
	crTop.right = crRight.left;
	crTop.bottom =  crWindowsRect.Height();
	crTop.top =  crWindowsRect.Height() - inFrameWidht;
}

Со всеми расчетами. Теперь мы применим этот класс для закрашивания. Включаем его описание.

/////////////////////////
// CTestPaintDlg dialog
#include "CalcWindowNonClient.h"

class CTestPaintDlg : public Cdialog
......

И используем:

void CTestPaintDlg::DrawWindowArea( BOOL b)
{
	CDC* cdWinDC= GetWindowDC();
	CCalcWindowNonClient ccWin;
	ccWin.Calc(this); 
	CBrush tempBrush1;
	tempBrush1.CreateSolidBrush(RGB(255,0,0));
	cdWinDC->FillRect(&ccWin.crCaptionRect,&tempBrush1);
	cdWinDC->FillRect(&ccWin.crLeft,&tempBrush1);
	cdWinDC->FillRect(&ccWin.crRight,&tempBrush1);
	cdWinDC->FillRect(&ccWin.crTop ,&tempBrush1);
	ReleaseDC(cdWinDC);
}

Результат тот же только без проблем с прорисовкой.

72_2.gif (2310 b)


Предыдущий Шаг | Следующий Шаг | Оглавление
Автор Каев Артем - 05.07.2002