Для того, чтобы рассчитывать прямоугольники я создал класс.
Вот его описание:
#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); }
Результат тот же только без проблем с прорисовкой.